hi hello i have just started progrmming in assembly of pic . i wrote a simple program for pic16f84a running at 4mhz . it has got a timer routine which runs for 0.1 sec and sec1 routine which calls timer routine 10 times..to waste 1 sec.....main program toggles led once a second using sec1 routine... i m unable to pinpoint the mistake in my program as it is compiling successfully... here goes the code ======================= list pf84a include "p16f84a.inc" cblock 0ch tenthsec,sec,tensec,min,mark250,mark200,mark2,ten endc #define led portb,0 org 00h goto main init bsf status,rp0 movlw 00 movwf trisb movlw 7 movwf option_reg clrf tenthsec clrf sec clrf tensec clrf min movlw 250 movwf mark250 movlw 200 movwf mark200 movlw 2 movwf mark2 return ; for 0.1 sec at 4mhz pic should run 100,000 which ; is 250*200*2 timer bcf status,rp0 movf mark250,w subwf TMR0,w btfss STATUS,Z goto timer movlw 250 addwf mark250 decf mark200,f btfss STATUS,Z goto timer movlw 200 movwf mark200 decf mark2,f btfss STATUS,Z goto timer movlw 2 movwf mark2 return sec1 movlw 10 movwf ten loop call timer decf ten,f btfss status,z goto loop return main call init bcf status,z bsf led call sec1 bcf led call sec1 goto main end ======================== in MPLAB IDE 6.3 i m unable to simulate timer0...its not incrementing at all...is that a limitation of MPLAB IDE ? i m unable to point out the mistake in last 2 days... please find the clock.asm file attached please help me out... thanks in advance nisheeth |
|
timer0 in pic16f84a
Started by ●August 1, 2003
Reply by ●August 8, 20032003-08-08
Have you solved your problem yet? I may have some time this weekend. Chad --- Nisheeth Gupta <> wrote: > hi > hello > i have just started progrmming in assembly of pic . i > wrote a simple program for pic16f84a running at 4mhz . it has got a > timer routine which runs for 0.1 sec and sec1 routine which calls > timer routine 10 times..to waste 1 sec.....main program toggles led > once a second using sec1 routine... > i m unable to pinpoint the mistake in my program as it is compiling > successfully... > here goes the code > ======================= > list pf84a > include "p16f84a.inc" > cblock 0ch > tenthsec,sec,tensec,min,mark250,mark200,mark2,ten > endc > #define led portb,0 > org 00h > goto main > > init > bsf status,rp0 > movlw 00 > movwf trisb > movlw 7 > movwf option_reg > clrf tenthsec > clrf sec > clrf tensec > clrf min > movlw 250 > movwf mark250 > movlw 200 > movwf mark200 > movlw 2 > movwf mark2 > return > > ; for 0.1 sec at 4mhz pic should run 100,000 which > ; is 250*200*2 > timer > bcf status,rp0 > movf mark250,w > subwf TMR0,w > btfss STATUS,Z > goto timer > movlw 250 > addwf mark250 > > decf mark200,f > btfss STATUS,Z > goto timer > movlw 200 > movwf mark200 > > decf mark2,f > btfss STATUS,Z > goto timer > movlw 2 > movwf mark2 > return > > sec1 > movlw 10 > movwf ten > loop call timer > decf ten,f > btfss status,z > goto loop > return > main > call init > bcf status,z > bsf led > call sec1 > bcf led > call sec1 > goto main > end > ======================== > in MPLAB IDE 6.3 i m unable to simulate timer0...its not incrementing > > at all...is that a limitation of MPLAB IDE ? > i m unable to point out the mistake in last 2 days... > please find the clock.asm file attached > please help me out... > > thanks in advance > nisheeth __________________________________ |
Reply by ●August 9, 20032003-08-09
TMR0 works for me, but you do have other problems. I would reset to bank 0 immediately after OPTION although I don't believe it affects your program here. Chad --- In , "Nisheeth Gupta" <nisheeth_007@y...> wrote: > hi > hello > i have just started progrmming in assembly of pic . i > wrote a simple program for pic16f84a running at 4mhz . it has got a > timer routine which runs for 0.1 sec and sec1 routine which calls > timer routine 10 times..to waste 1 sec.....main program toggles led > once a second using sec1 routine... > i m unable to pinpoint the mistake in my program as it is compiling > successfully... > here goes the code > ======================= > list pf84a > include "p16f84a.inc" > cblock 0ch > tenthsec,sec,tensec,min,mark250,mark200,mark2,ten > endc > #define led portb,0 > org 00h > goto main > > init > bsf status,rp0 > movlw 00 > movwf trisb > movlw 7 > movwf option_reg > clrf tenthsec > clrf sec > clrf tensec > clrf min > movlw 250 > movwf mark250 > movlw 200 > movwf mark200 > movlw 2 > movwf mark2 > return > > ; for 0.1 sec at 4mhz pic should run 100,000 which > ; is 250*200*2 > timer > bcf status,rp0 > movf mark250,w > subwf TMR0,w > btfss STATUS,Z > goto timer > movlw 250 > addwf mark250 > > decf mark200,f > btfss STATUS,Z > goto timer > movlw 200 > movwf mark200 > > decf mark2,f > btfss STATUS,Z > goto timer > movlw 2 > movwf mark2 > return > > sec1 > movlw 10 > movwf ten > loop call timer > decf ten,f > btfss status,z > goto loop > return > main > call init > bcf status,z > bsf led > call sec1 > bcf led > call sec1 > goto main > end > ======================== > in MPLAB IDE 6.3 i m unable to simulate timer0...its not incrementing > at all...is that a limitation of MPLAB IDE ? > i m unable to point out the mistake in last 2 days... > please find the clock.asm file attached > please help me out... > > thanks in advance > nisheeth |
|
Reply by ●August 10, 20032003-08-10
I've noticed too that timer0 does NOT advance in MPSIM if the prescaler is bypassed (1:1). But if the prescaler is assigned to TMR0 (i.e. at least 1:2 or higher), then TMR0 increments. I'm not sure why though. You may want to use the prescaler of 1:2 or higher. --- In , "Chad Russel" <chadrussel@y...> wrote: > TMR0 works for me, but you do have other problems. I would reset to > bank 0 immediately after OPTION although I don't believe it affects > your program here. > > Chad > --- In , "Nisheeth Gupta" <nisheeth_007@y...> > wrote: > > hi > > hello > > i have just started progrmming in assembly of pic . i > > wrote a simple program for pic16f84a running at 4mhz . it has got a > > timer routine which runs for 0.1 sec and sec1 routine which calls > > timer routine 10 times..to waste 1 sec.....main program toggles led > > once a second using sec1 routine... > > i m unable to pinpoint the mistake in my program as it is compiling > > successfully... > > here goes the code > > ======================= > > list pf84a > > include "p16f84a.inc" > > cblock 0ch > > tenthsec,sec,tensec,min,mark250,mark200,mark2,ten > > endc > > #define led portb,0 > > org 00h > > goto main > > > > init > > bsf status,rp0 > > movlw 00 > > movwf trisb > > movlw 7 > > movwf option_reg > > clrf tenthsec > > clrf sec > > clrf tensec > > clrf min > > movlw 250 > > movwf mark250 > > movlw 200 > > movwf mark200 > > movlw 2 > > movwf mark2 > > return > > > > ; for 0.1 sec at 4mhz pic should run 100,000 which > > ; is 250*200*2 > > timer > > bcf status,rp0 > > movf mark250,w > > subwf TMR0,w > > btfss STATUS,Z > > goto timer > > movlw 250 > > addwf mark250 > > > > decf mark200,f > > btfss STATUS,Z > > goto timer > > movlw 200 > > movwf mark200 > > > > decf mark2,f > > btfss STATUS,Z > > goto timer > > movlw 2 > > movwf mark2 > > return > > > > sec1 > > movlw 10 > > movwf ten > > loop call timer > > decf ten,f > > btfss status,z > > goto loop > > return > > > > > > main > > call init > > bcf status,z > > bsf led > > call sec1 > > bcf led > > call sec1 > > goto main > > end > > ======================== > > in MPLAB IDE 6.3 i m unable to simulate timer0...its not incrementing > > at all...is that a limitation of MPLAB IDE ? > > i m unable to point out the mistake in last 2 days... > > please find the clock.asm file attached > > please help me out... > > > > thanks in advance > > nisheeth |