Dear Friends, What I'm trying to do is creating 1s interrupt on the background with=20 Timer0, I have set Timer0 to B2 and I need a counter for it. It's state machine turn on and turn off LED in one second, but the "one=20 second" comes from Timer0 interrupt, Do you get what I mean ? Let me make it simple: ;********************************************************************* ; 1 ms timer function calls ;********************************************************************* bcf STATUS, RP0 ;Select Bank 0 bcf STATUS, RP1 ;....... 1ms timer counter here..... clrf TMR0 ;Clear TMR0 and prescaler banksel TMR0 movlw 0xB2 ;Count=3DB2 movwf TMR0 *How can I make the 1ms counter here ?* ;.................................... ;.................................... incf COUNT, f movlw .10 ;Compare count to 10 decimal subwf COUNT, W ;Store the result back in btfss STATUS, C ;Is the result 0, skip if no goto exittimer clrf COUNT ;Clear count register ;********************************************************************** ; 10ms timer function calls ;********************************************************************** ;....... 10ms timer counter here..... *How can I make the 10ms counter here ?* ;.................................... incf COUNT1, f movlw .10 ;Compare count to 100 decimal subwf COUNT1, W ;Store the result back in btfss STATUS, C ;Is the result 0, skip if no goto exittimer clrf COUNT1 ;********************************************************************** ; 100ms timer function calls ;********************************************************************** ;....... 100ms timer counter here..... *How can I make the 100ms counter here ? The interrupt will trigger state 1, which is turning on LED=20 from here, how can I do that ?* ;.................................... any ideas or clues will be appreciated Thanks for replying... On 1/07/2013 12:24 PM, Byron Jeff wrote: > OK. I'm going to critque the code now. > > On Mon, Jul 01, 2013 at 07:09:02AM +0800, Electronic Consultation wrote: >> Yes this the first time I used assembly for PIC, most of the time I used= C. >> if I want 1 ms on 20 Mhz processor with 1:64 prescaler ? > It cannot be done. A 1:64 prescale on a 5 Mhz instruction clock will give > you a 12.8 uS tick rate. There is no integer number of counts of 12.8 uS > that will give you 1 mS. > >> Something like this ? >> *on init :* >> clrf TMR0 ;Set timer 0 to 0 - may not be needed >> >> clrwdt ;Clear watchdog timer >> >> >> bsf STATUS, RP0 ;SELECT BANK 1 >> >> ; Set up timer interrupt >> movlw b'10010110' ;weak portb pullups disabled - >> 1ms interrupt >> movwf OPTION_REG ;select tmr0, 64d prescal, clock s= ource >> >> bcf STATUS, RP0 ;Select bank 0 >> >> bcf INTCON,RBIE ; port B interrupt on change di= sable >> >> ;movlw b'1010000' ;enable global/timer0 interrupt >> movlw b'10100000' ;enable global/timer0 interrupt >> movwf INTCON ; > Where exactly does the interrupt go? > >> *for 1ms:* >> LedTimer EQU 0x0A > Is LedTimer an address or a count. If it's an address then I don't think > 0x0A is a General Purpose register on the 16F648A. Also take a read of my > discussion earlier about the use of CBLOCK instead of equates. > >> clrf TMR0 ;Clear TMR0 and prescaler >> banksel TMR0 >> movlw 0xB2 ;Count=3DB2 >> movwf TMR0 >> >> timer1ms >> movf LedTimer,f >> btfsc STATUS,Z >> decf LedTimer,Z >> return > Tthe timer1ms code makes little sense. First off it doesn't use Timer 0 i= n > any way. If it's an interrupt service routine, it needs a retfie. If not, > then is doesn't have a loop. If only decrements the LedTimer, which again > is not a proper address, when it is already zero. You never assigned a > value to LedTimer, so it's unclear if the decrement will ever execute. > > I really think you need to take a step back, stop trying to write code, a= nd > just explain what it is that you are trying to do. Right now the code is = so > confusing, that no one can really help you. > > As I always tell my students, programming isn't about writing code, it is > about solving problems. Please explain the problem that you are trying to > solve. > > Hope this helps, > > BAJ > >> --=20 >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .