How about this?
It won't produce exactly the same frequency as your example but it's 12% smaller (37 words). I suppose there's also the odd chance/risk of the TMR0 interrupt bit being set in between checking it and clearing it. You COULD also do away with the n=0 at the start with the drawback of the FIRST iteration taking longer depending on the start value of n. AND, possibly, get rid of the GOTO Main and let the PC freerun and start over from the top.Code:Main: n = n + INTCON.2 INTCON.2 = 0 IF n.3 THEN LATA = LATA ^ %000011 n=0 ENDIF goto Main
Adding DEFINE NO_CLRWDT 1 saves one or two words depending on which version.
Using TMR1, which is 16 bits with its 8:1 prescaler instead of counting overflows should achieve similar results
Combining these I got it down to 34 words but have not checked if it actually works.Code:T1CON = %00110001 Main: IF PIR1.0 THEN PIR1.0 = 0 LATA = LATA ^ %000011 ENDIF Goto Main
/Henrik.




Bookmarks