Beruflich Dokumente
Kultur Dokumente
Engineering Faculty
Department of Computer Engineering
ECOM 3022: Embedded Systems Discussion
Chapter 4
PIC I/O PORT PROGRAMMING
PIC 18F458 has 40-pin chip, 33 pins are set aside for the five ports PORTA, PORTB,
PORTC, PORTD, and PORTE.
Each port has some other functions, such as timer, ADC, interrupts and serial
communication.
Port A has 7 pins; Ports B, C, and D each have 8 pins; and Port E has only 3 pins.
Each port can be configured as input or output.
PROBLEMS
11. Write a program to get 8-bit data from PORTC and send it to ports PORTB and PORTD.
SETF TRISC
; Define PORTC as input
CLRF TRISB
; Define PORTB as output
CLRF TRISD
; Define PORTD as output
MOVF PORTC, W
NOP
MOVWF PORTB
MOVWF PORTD
15. Write a program to toggle all the bits of PORTB and PORTC continuously
(a) using AAH and 55H (b) using the COMF instruction.
(a)
CLRF TRISB
CLRF TRISC
BACK MOVLW 55H
MOVWF PORTB
MOVWF PORTC
CALL DELAY
MOVLW AAH
MOVWF PORTB
MOVWF PORTC
CALL DELAY
GOTO BACK
(b)
CLRF TRISB
CLRF TRISC
MOVLW 55H
MOVWF PORTB
MOVWF PORTC
BACK CALL DELAY
COMF PORTB
COMF PORTC
BRA BACK
20. Write a program to toggle RB2 and RB5 continuously without disturbing the rest of the bits.
BCF TRISB,
BCF TRISB,
BACK BTG PORTB,
BTG PORTB,
CALL DELAY
BRA BACK
2
5
2
5
22. Write a program to monitor bit RC3. When it is HIGH, send 55H to PORTD.
BSF TRISC, 3
; Define PC3 as input
CLRF TRISD
; Define PD as output
BACK BTFSS PORTC, 3
BRA BACK
MOVLW 0x55
MOVWF PORTD
26. Write a program to get the status of RC3 and put it on RC4.
BSF TRISC, 3
BCF TRISC, 4
AGAIN BTFSS PORTC, 3
GOTO OVER
BSF PORTC, 4
GOTO AGAIN
OVER BCF PORTC, 4
GOTO AGAIN
Best Wishes