1. Arm yourself with the PICs Datasheet.
' Done
2. Have a look at Section 5 - Timer1 Module
' Yep
3. Have a look at section 5-1 T1CON... see if you can figure why I would set it to...
T1CON=%00000001
' You enable Timer 1, allow it work
4. Find TMR1H, TMR1L anf PIR1... see why I would load them thus...
TMR1H=$E0
TMR1L=$00
PIR1.0=0
' You preload the timer with the hex value of E000
' You reset the Timer Overflow flag
5. Read section 5.6 it might interest you...
' Very interesting that I can run the clok with the device in sleep
' mode, thus even less consumption
6. Have a look at Bit 0 of PIR1 (Datasheet 2-5) what would this piece of code do?...
While PIR.0=0:Wend
' It will will wait until PIR bit 0 = 1, or when the timer roll's over
Answers to these questions will qualify you as a Timer1 expert, and gain you the appropriate shoulder badge...
' OK, so I will try the code....
Very brief example (assuming your 32kHz clock)...
code:--------------------------------------------------------------------------------
LED var GPIO.0 ' Assign Led name to GPIO port 0
TRISIO=%00000000 ' Set all ports as outputs
' Question..... does this affect the xtal ports 4,5 ?
T1CON=%00000001 ' Set bit 0 High in T1Con
Loop:
TMR1H=$E0 ' Preload the High Byte with E0
TMR1L=$00 ' Preload the Low Byte with 00
PIR1.0=0 ' Reset the interupt flag
Toggle LED ' Change the LED status, ie from on
' to off or off to on
While PIR1.0=0:Wend ' wait for the roll over
Goto Loop redo the whole process
End
--------------------------------------------------------------------------------
*smiles*
' No smiles I' afraid
' I believe there are a few more things to do
' Some more registers to set
' I'll keep digging, and reading
' However, the above may help other persons as well
Next step will be the Interrupt Navigators badge.... however, I think I've mentioned before that interrupts on a 12 series PIC are a bit limited...
' Woooha, interupts! Lots to learn, nice to get help!
' Will keep on
' Thanks, Peter
Bookmarks