Getting Started with PICs
Here is a very simple test circuit:
According to the 16F84 data sheet, reset pin 4 can be tied to Vcc. However, I didn't find this particularly reliable if using a solderless breadboard, so I added the RC combination, ensuring the 16F84 gets a proper reset when powered up. It should work OK if a PCB is used.
I've used the RC oscillator option, with the on-chip capacitor, to keep things simple. The oscillator isn't particularly stable, but it doesn't really matter in this case.
This is the circuit built on a solderless breadboard. It requires about 5V: I used four NiMH AA cells.
Here is a simple test program that flashes the LED:
;*******************************************************************
; test2.asm
;
; test program to flash an LED connected to RB3 (pin 9)
;
;*******************************************************************
#include "P16F84.INC"
count1 equ 0C ;GP registers
count2 equ 0D
count3 equ 0E
org 0 ; origin
bsf STATUS,RP0 ;select bank 1
bcf TRISB, 3 ;RB3 output
bcf STATUS,RP0 ;select bank 0
main:
call flash ;flash LED briefly
call long_dly ;wait
goto main ;do it again, and again, ...
;subroutine to flash the LED once, briefly
flash:
bsf PORTB, 3 ;LED on
call dly ;short delay
bcf PORTB, 3 ;LED off
return
;long delay loop subroutine that calls short delay subroutine
long_dly:
movlw 0x03F ;initialise delay counter
movwf count3
long1:
call dly ;short delay
decfsz count3, 1 ;decrement counter, if counter is not zero
goto long1 ;go round again
return ;else return
;short delay subroutine with two nested loops
dly:
movlw 0xFF ;initialise outer loop counter
movwf count1
dly1:
movlw 0x0F ;initialise inner loop counter
movwf count2
dly2:
decfsz count2, 1 ;decrement inner loop counter, if counter is not zero
goto dly2 ;go round again
decfsz count1, 1 ;else decrement outer loop counter, if counter is not zero
goto dly1 ;go round again
return ;else return
END