http://www.piclist.com/postbot.asp?id=3Dpiclist\2002\06\07\153942a Thanks for the reply and yes I hadn't assigned the Prescaler in that = example,BUT this is not the real problem. I have written other code to select the prescaler for the TMR0 but is = not that the PIC isn't counting/timing at the correct rate it's more = drastic....=20 *** the TMR0 register is just RANDOMLY changing ****=20 I can see no sequence in the numbers at all. They appear to just change = at will on every instruction. When I run this in the simulator all is well and I get the TMR0 register = changing as expected.=20 So why NOT on the real hardware??? I have now written it in assembler and still I must be missing something = obvious... ; Use PIC16F84 and set radix system to decimal LIST P=3D16F877, R=3DDEC ;************************************************************************= ****** ; Include header file ;************************************************************************= ****** #include "p16f877.inc" #define TIMER_PRESET 180 ;************************************************************************= ****** ; equates ;************************************************************************= ****** ; WORDS status_temp equ 0x0c w_temp equ 0x0d ;************************************************************************= ****** ; START of CODE ;************************************************************************= ****** org 0x0 ; reset vector goto init ; jump over subroutines org 0x4 ; Interrupts goto isr ; Goto this service routine ;************************************************************************= ****** ; initalisation ;************************************************************************= ****** init clrf PORTC ; set =3D 0 bsf STATUS,RP0 ; BANK1 movlw 0x00 movwf TRISC movlw b'11011111' ; movwf OPTION_REG ; Set Timer ON and use prescaler = of 256 bcf STATUS,RP0 ; Retrun to BANK0 movlw TIMER_PRESET movwf TMR0 ; Reset Timer0 bsf INTCON,T0IE ; Turn Timer Interrupt On bsf INTCON,INTE ; Turn RB0 Change Interrupt On bsf INTCON,GIE ; Turn Global Interrupts On ;************************************************************************= ****** ; main program ;************************************************************************= ****** main background_loop goto background_loop = ;************************************************************************= ****** ; Interrupt Service Routines ;************************************************************************= ****** isr ; --------------------------- save context = ------------------------------------ context_save movwf w_temp ; save off W and STATUS = registers swapf STATUS, w movwf status_temp clrf STATUS ; select Bank0 ; ************************* TIMER TMR0 Interrupt = ****************************** tmr0_int ; ----------------------- Clear Interrupt Condition = -------------------------- bcf INTCON,T0IF ; Clear pending interrupt flag ; ------------- Reset TMR0 Timer State for next timed interrupt = -------------- movlw TIMER_PRESET movwf TMR0 ; Reset Timer0 tmr0_int_end ; ******************** restore context saved on entry to ISR = ******************* isr_end context_restore swapf status_temp, w ; restore all registers movwf STATUS swapf w_temp, f swapf w_temp, w ; -------------------- END of interrupt service routine = ----------------------- retfie ; Return from interrupt service = routine ;************************************************************************= ****** ;************************************************************************= ****** ;************************************************************************= ****** end ; ------------------------------ END OF FILE = ---------------------------------- --- Peter R Betts http://www.piclist.com/member/PRB-TRL-AA7 PIC/PICList FAQ: http://www.piclist.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu