Deagol_the_Dead
New Member
I was working through this tutorial at **broken link removed** when I noticed that the counter to delay the turning on/off of the LED is too long. I am using the specified resistor and capacitor, but I am using a PIC16F84A-20. I looked in the datasheet for RC, but all it shows is how to connect the RC to pin 16 and "5k Ohm <= R <= 100k Ohm, C > 20pF".
The original code had the delay decrementing 255, 255 times. This made the LED stay on/off for a little over a minute and a half. I changed it to decrement 255 only 5 times and this makes the LED stay on/off for ~1 sec.
Questions:
How would you calculate which size capacitor and resistor for a 20 MHz 16F84A?
How does the RC time constant get worked into the equation?
The original code had the delay decrementing 255, 255 times. This made the LED stay on/off for a little over a minute and a half. I changed it to decrement 255 only 5 times and this makes the LED stay on/off for ~1 sec.
Questions:
How would you calculate which size capacitor and resistor for a 20 MHz 16F84A?
How does the RC time constant get worked into the equation?
Code:
LIST P=PIC16F84A
INCLUDE "P16F84A.INC"
__CONFIG _RC_OSC & _PWRTE_ON & _CP_OFF & _WDT_OFF
COUNT1 equ 08h
COUNT2 equ 09h
bsf STATUS,5 ;switch to Bank 1
movlw 00h ;set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;switch back to Bank 0
Start movlw 02h ;turn the LED on by first putting
movwf PORTA ;it into the w register and then on the port
call setCount2
call delay
movlw 00h ;turn the LED off by first putting
movwf PORTA ;into the w register and then on the port
call setCount2
call delay
goto Start
delay
Loop1 decfsz COUNT1,1 ;subtract 1 from 255
goto Loop1 ;if COUNT is zero, carry on.
decfsz COUNT2,1 ;subtract 1 from 5
goto Loop1 ;go back to the start of our loop
return
setCount2
movlw 05h ;put the value of 05h in the W register
movwf COUNT2 ;now move it to our COUNT2 register
return
end