Until now any timing I've done I've managed to get by with just using a simple loop, looking at the datasheets and setting registers that I do not understand scares me.
What's happening currently is my program has branches withing the timing loop and these stuff up my timing depending on the situation, so I'm gonna bite the bullet and learn how to use the onboard timers. I'm currently uding a 16f676 and was wanting to use timer0 just to increment a time, i qrote a simple bit of code to see if I'd grasped the concept - obviously not!!!
I set the prescaler to 256 and was going to toggle a red led everytime it interupted so I can see it working
here's what I've got so far - would greatly appreciate any suggestions - thanks - also how do i get the code in that lil code box displayed on here?
[code:]
@ DEVICE PIC16F676, XT_OSC, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF
DEFINE OSC 4
TRISA = %000000
TRISC = %101100
ANSEL = %10000000 'enable ch7 analog
CMCON = 7 'Disable comparitor
OPTION_REG = %00010111 'set prescaler to 256
INTCON.2 = 0 ' Clear Timer0 int flag
INTCON.5 = 1 ' Enable Timer0 int
TMR0 = 0 ' Set TMR0 to 0.
ON INTERRUPT GOTO int
red var PortA.2
clear
PortA = 0
PortC = 0
Start: 'stay in loop
goto start
int: 'toggle led on interupt
TMR0 = 0
toggle red
resume
Bookmarks