ex 38514e

2
EEE 447 MICROPROCESSOR LABORATORY EXPERIMENTAL WORK 3 PIC I/O PORT PROGRAMMING Objective: In this experiment, I/O Port programming of PIC18F25K22 is represented.Setting the ports of PIC18F25K22 as input and output is emphasized. Ex.1: Write the following Assembly Language Program, compile and download the resulted “HEX” file to PIC18F25K22. Observe PORTB, PORTC and PORTD individually. LIST P=18f45k22 INCLUDE "P18f45k22.INC" MYREG EQU 0X09 R1 EQU 0X07 R2 EQU 0X08 ORG 0 ; Starting point MOVLW 0X00 MOVWF TRISB ;PORTB is output MOVWF TRISC ;PORTC is output MOVWF TRISD ;PORTD is output L1 MOVLW 0X55 MOVWF PORTB ;PORTB =0x55 CALL DELAY MOVLW 0X50 MOVWF PORTC ;PORTC =0x50 CALL DELAY MOVLW 0X45 MOVWF PORTD ;PORTD =0x45 ; Delay Routine, 0.25s Delay ORG 200H ; Starting point of delay routine DELAY MOVLW D'200' MOVWF R1 D1 MOVLW D'250' MOVWF R2 D2 NOP NOP DECF R2,F BNZ D2 DECF R1,F BNZ D1 RETURN END Ex.2: Write the following Assembly Language Program, compile and download the resulted “HEX” file to PIC18F25K22. Observe PORTB, PORTC and PORTD pins individually. LIST P=18f45k22 INCLUDE "P18f45k22.INC" R1 EQU 0X07 R2 EQU 0X08 ORG 0 ; Starting point CLRF TRISB ;PORTB is output BSF PORTD,5 GOTO FINISH ; Delay Routine, 0.25s Delay ORG 200H ; Starting point of delay routine DELAY MOVLW D'200'

Upload: zuebuek-zade

Post on 27-Jan-2016

213 views

Category:

Documents


0 download

DESCRIPTION

ggh

TRANSCRIPT

Page 1: Ex 38514e

EEE 447 MICROPROCESSOR LABORATORY

EXPERIMENTAL WORK 3

PIC I/O PORT PROGRAMMING

Objective: In this experiment, I/O Port programming of PIC18F25K22 is represented.Setting the ports of PIC18F25K22 as input and output is emphasized.

Ex.1: Write the following Assembly Language Program, compile and download the resulted “HEX” file to PIC18F25K22. Observe PORTB, PORTC and PORTD individually.

LIST P=18f45k22INCLUDE "P18f45k22.INC"

MYREG EQU 0X09R1 EQU 0X07R2 EQU 0X08

ORG 0 ; Starting pointMOVLW 0X00MOVWF TRISB ;PORTB is outputMOVWF TRISC ;PORTC is outputMOVWF TRISD ;PORTD is output

L1 MOVLW 0X55MOVWF PORTB ;PORTB =0x55CALL DELAYMOVLW 0X50MOVWF PORTC ;PORTC =0x50CALL DELAYMOVLW 0X45MOVWF PORTD ;PORTD =0x45

; Delay Routine, 0.25s DelayORG 200H ; Starting point

of delay routineDELAY MOVLW D'200'

MOVWF R1D1 MOVLW D'250'

MOVWF R2D2 NOP

NOPDECF R2,FBNZ D2DECF R1,FBNZ D1RETURNEND

Ex.2: Write the following Assembly Language Program, compile and download the resulted “HEX” file to PIC18F25K22. Observe PORTB, PORTC and PORTD pins individually.

LIST P=18f45k22INCLUDE "P18f45k22.INC"R1 EQU 0X07R2 EQU 0X08

ORG 0 ; Starting pointCLRF TRISB ;PORTB is outputCLRF TRISC ;PORTC is outputCLRF TRISD ;PORTD is output

BSF PORTB,0CALL DELAYBSF PORTC,1CALL DELAYBSF PORTD,2CALL DELAYBSF PORTB,3CALL DELAYBSF PORTC,4CALL DELAY

BSF PORTD,5GOTO FINISH

; Delay Routine, 0.25s DelayORG 200H ; Starting point

of delay routineDELAY MOVLW D'200'

MOVWF R1D1 MOVLW D'250'

MOVWF R2D2 NOP

NOPDECF R2,FBNZ D2DECF R1,FBNZ D1RETURN

FINISH NOPEND

Page 2: Ex 38514e

Ex.3: Repeat the procedures in the previous Assembly Language program for the following one. The program:

Checks the state of RC3 pin

If it is 0, does nothing

If it is 1, sends 63H to PORTB and sets RD3 0.25s later.

LIST P=18f45k22INCLUDE "P18f45k22.INC"R1 EQU 0X07R2 EQU 0X08

BSF TRISC,3 ;RC3 is inputCLRF TRISB ;PORTB is outputBCF TRISD,4 ;RD4 is output

MOVLW 0X63REPEAT BTFSS PORTC,3

BRA REPEATCALL DELAYMOVWF PORTBBSF PORTD,3GOTO FINISH

; Delay RoutineDELAY MOVLW D'200'

MOVWF R1D1 MOVLW D'250'

MOVWF R2D2 NOP

NOPDECF R2,FBNZ D2DECF R1,FBNZ D1RETURN

FINISH NOPEND