Pin Configuration of PIC16F877A
Pin Configuration of PIC16F877A
INDF Register
PCLATH Register
We use the MPLAB IDE Software for designing, editing & compiling codes. Look out for the MPLAB Tutorial
for details, on how to begin with a new project & end up with a .hex file of the required code (after simulator
testing.)
Read the PICPgm Tutorial to know, how to feed the code ( .hex file) into the microcontroller.
Feed the Test File into the MicroController to understand the process.
Pin Diagram of PIC16F877A
PART B) To Light up an LED
Problem Statement:
Connect an LED to the RB0 of PORTB (Pin No. 33 of the IC), and write a code that will light up the given LED.
Compile the code, test it using the MPLAB Simulator, and feed the .hex file into the IC.
Procedure:
Connect 8 LEDs to the port pins of PORTB through current limiting resistors (220 Ohm each). Write a delay routine
to generate approximately 0.5 s delay. Define an 8-bit variable ‘Counter’. Initialize ‘Counter’ to FFH. Use the
instruction ‘decf Counter, W’ to decrement the counter. Output the content of W to PORTB. Introduce a delay of 0.5
s and repeat in an infinite loop.
Circuit Diagram of the Microcontroller Circuit for LED Lighting
Blinking of LED with a Delay
MAIN_PROG CODE
start
Loop
bsf PORTB, 0
movlw 0xFF
movwf count
Delay1
nop
decfsz count
goto Delay1
bcf PORTB, 0
movlw 0xFF
movwf count
Delay2
nop
decfsz count
goto Delay2
goto Loop
MAIN_PROG CODE
start
Loop
bsf PORTB, 0
movlw 0xFF
movwf count2
Delay11 movlw 0xFF
movwf count1
Delay12
nop
decfsz count1
goto Delay12
decfsz count2
goto Delay11
bcf PORTB, 0
movlw 0xFF
movwf count2
Delay21 movlw 0xFF
movwf count1
Delay22
nop
decfsz count1
goto Delay22
decfsz count2
goto Delay21
goto Loop