> these 3 things are exactly what i want to understand. this is what im > having problems with to visualise and that is why i thought of turning > to code directly. Here's some absolute code that will help you understand TMR0. If you use a 4MHz crystal and have an LED on PortB,1 you should see it flash at 1s on, 1s off (I hope - not used an F84 for a looong time and this code was just put together in Notepad, and I'm tired) E&OE (errors and omissions excepted, ie cross fingers, touch wood) ;4MHz crystal = 1MHz instruction cycle ; ;TMR0 generates an interrupt passing through 0xff -> 0x00 ; ;One second takes 1,000,000 increments of TMR0 ; ;1,000,000/256 = 3906 times TMR0 passes through 0xff -> 0x00 ; ;ticks_hi:ticks_lo are used to count from -3906 (0x0f42) up to 0 ; ;1,000,000/256 is actually 3906.25. 3906 * 256 = 999.936s list P=16F84 #include "p16f84.inc" __config _XT_OSC & _WDT_OFF & _PWRTE_ON ;============================ cblock 0x0c ticks_lo ;TMR0 interrupt counter ticks_hi s_temp ;status store in ISR w_temp ;W store in ISR endc ;============================ #define led portb,1 ;LED flash output irq_count = - d3906 ;count up to 0 ;============================ org 0x00 goto init org 0x04 goto tmr0_isr ;================================================ ; Main program ;================================================ init banksel trisa movlw b'00000000' ;all output movwf trisa movlw b'00000000' ;all output ; 0 LED (don't forget a resistor, a few hundred ohms) movwf trisb banksel porta clrf porta clrf portb movlw high(irq_count) ;set counter to - d3906 movwf ticks_hi ;ticks high set to 0x0f movlw low(irq_count) movwf ticks_lo ;ticks_lo set to 0x42 clrf intcon ;clear all IRQ flags, generally ;specifically bcf intcon,t0if ;clear IF before GIE set bsf intcon,t0ie ;enable TMR0 interrupts clrf tmr0 ;reset TMR0 bsf intcon,gie ;enable all interrupts wait nop ;loop here forever goto wait ;================================================ ; Process TMR0 interrupt ;================================================ tmr0_isr movwf w_temp ;store W and Status swapf status,w movwf s_temp bcf intcon,t0if ;must clear IF before retfie incfsz ticks_lo ;increment ticks until = 0x0000 goto isr_exit ;low byte <> 0 incfsz ticks_hi goto isr_exit ;high byte <> 0 ;count = 0x0000 movlw high(irq_count) ;reload counter with - 3906 movwf ticks_hi movlw low(irq_count) movwf ticks_lo movfw portb ;read port xorlw b'00000010' ;toggle b0 (LED flash) movwf portb ;write back to port isr_exit swapf s_temp,w ;restore status, W, exit movwf status swapf w_temp swapf w_temp,w retfie -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist