Got it working, and I only found one problem.
The 194 would be for timer 0. Where it counts from that number until it overflows at 256, which takes 62 counts.
Timer 2 works a little different.
It counts from 0 up to the number in PR2, then resets to 0 again.
So 62 is the number for PR2 @ ~1ms. It's actually 62.5, so we may need to drop the prescaler to 4 and use 250 for PR2 if you want more accuracy.
I do not see any problems with the interrupt portions, and it all works fine here. Here's the breadboard I just put together.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1902&stc=1&d=118607629 9">
And here's the program I'm using ...
Code:
<font color="#0000FF"><b><i>; http://www.picbasic.co.uk/forum/showthread.php?t=6818
</i></b></font><font color="#000080">@ ERRORLEVEL -306 </font><font color="#0000FF"><b><i>; turn off crossing page boundary message
</i></b></font><font color="#000080">@ __CONFIG _CONFIG1, _CP_OFF & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
</font><font color="#008000"><b>DEFINE </b></font><b>LCD_DREG PORTB </b><font color="#0000FF"><b><i>' LCD data port
</i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_DBIT </b><font color="#800000"><b>0 </b></font><font color="#0000FF"><b><i>' LCD data starting bit 0 or 4
</i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_RSREG PORTB </b><font color="#0000FF"><b><i>' LCD register select port
</i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_RSBIT </b><font color="#800000"><b>4 </b></font><font color="#0000FF"><b><i>' LCD register select bit
</i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_EREG PORTB </b><font color="#0000FF"><b><i>' LCD enable port
</i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_EBIT </b><font color="#800000"><b>5 </b></font><font color="#0000FF"><b><i>' LCD enable bit
</i></b></font><font color="#008000"><b>PAUSE </b></font><font color="#800000"><b>500 </b></font>: <font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>1 </b></font>: <font color="#008000"><b>PAUSE </b></font><font color="#800000"><b>250 </b></font><font color="#0000FF"><b><i>; Initialize LCD
</i></b></font><b>LED </b><font color="#008000"><b>VAR </b></font><b>PORTA</b>.<font color="#800000"><b>4
</b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">"DT_INTS-14.bas" </font><font color="#0000FF"><b><i>' Base Interrupt System
</i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">"ReEnterPBP.bas" </font><font color="#0000FF"><b><i>' Include if using PBP interrupts
</i></b></font><font color="#008000"><b>ASM
</b></font><font color="#0000FF"><b><i>;T0IF = TMR0IF
;T0IE = TMR0IE
</i></b></font><font color="#000080">INT_LIST macro </font><font color="#0000FF"><b><i>; IntSource, Label, Type, ResetFlag?
</i></b></font><font color="#000080">INT_Handler TMR2_INT, _tick, PBP, yes
endm
INT_CREATE </font><font color="#0000FF"><b><i>; Creates the interrupt processor
</i></b></font><font color="#008000"><b>ENDASM
</b></font><font color="#000080">@ INT_ENABLE TMR2_INT </font><font color="#0000FF"><b><i>; Enable Timer 1 Interrupts
'------- initial --------------------
</i></b></font><b>TMR2_clock </b><font color="#008000"><b>VAR WORD
</b></font><b>OPTION_REG </b>= <font color="#800000"><b>%00000000
</b></font><b>TRISB </b>= <font color="#800000"><b>%00000000 </b></font><font color="#0000FF"><b><i>' portb all output
</i></b></font><b>TRISA </b>= <font color="#800000"><b>%00111111 </b></font><font color="#0000FF"><b><i>' some analog inputs
</i></b></font><b>ANSEL </b>= <font color="#800000"><b>%00001111 </b></font><font color="#0000FF"><b><i>' some analog inputs
</i></b></font><b>CMCON </b>= <font color="#800000"><b>%00000111 </b></font><font color="#0000FF"><b><i>' turn of comparators
</i></b></font><b>ADCON1 </b>= <font color="#800000"><b>%10000000</b></font><font color="#0000FF"><b><i>' right justified
</i></b></font><b>T2CON </b>= <font color="#800000"><b>%00000011 </b></font><font color="#0000FF"><b><i>' TMR2 prescale 1:16
'---------------------------------------------------
</i></b></font><b>TMR2_clock </b>= <font color="#800000"><b>0
</b></font><font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>' clear screen
</i></b></font><b>PR2 </b>= <font color="#800000"><b>62 </b></font><font color="#0000FF"><b><i>' load tmr2 PR2 to reset every 1ms
</i></b></font><b>T2CON</b>.<font color="#800000"><b>2 </b></font>= <font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>' turn TMR2 on
</i></b></font><b>MAIN</b>:
<font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>$80</b></font>, <font color="#008000"><b>DEC </b></font><b>TMR2_clock</b>,<font color="#FF0000">" " </font><font color="#0000FF"><b><i>;---> CHANGED
</i></b></font><font color="#008000"><b>GOTO </b></font><b>MAIN
tick</b>:
<b>TMR2_clock </b>= <b>TMR2_clock </b>+ <font color="#800000"><b>1
</b></font><font color="#008000"><b>IF </b></font><b>TMR2_clock </b>= <font color="#800000"><b>500 </b></font><font color="#008000"><b>THEN
</b></font><b>TMR2_clock </b>= <font color="#800000"><b>0
</b></font><font color="#008000"><b>TOGGLE </b></font><b>LED
</b><font color="#0000FF"><b><i>' Set some flag..
</i></b></font><font color="#008000"><b>ENDIF
</b></font><font color="#000080">@ INT_RETURN
</font>
The LED flashes at almost 1 hz, and the numbers on the LCD are counting away.
I say "almost" due to the Timer 2 prescaler. For better accuracy, use ...
Code:
T2CON = %00000001 ' TMR2 prescale 1:4
PR2 = 250 ' load tmr2 PR2 to reset every 1ms
Bookmarks