bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
Guys,
How can I check if my counter is already zero on ledmgr.asm ?
Please see the code
thanks
timer.asm
and check the counter here :
ledmgr.asm
How can I check if my counter is already zero on ledmgr.asm ?
Please see the code
thanks
timer.asm
Code:
;
;
; File: timer.ASM
;
list p=16f628A
#include p16f628A.inc
#include globals.inc
extern counter
;extern counter1
;extern sectimer
;------------------------------------------------------------------------------
BANK0 UDATA
;------------------------------------------------------------------------------
COUNT RES 1 ;COUNT OF INTERRUPTS
COUNT1 RES 1 ;COUNT FOR 1 SECOND TIMER
COUNT2 RES 1
COUNT3 RES 1
;------------------------------------------------------------------------------
PROG0 CODE ; program code section
;------------------------------------------------------------------------------
TimerInt ; Interrupt routine
global TimerInt ; Define as global
intsOff bcf INTCON, T0IE ;Disable timer interrupts
bcf INTCON, T0IF ;clear interrupt flag
bsf INTCON, GIE ;Enable global interrupt
;-------------- Insert no new code above here ---------------------------------
;*********************************************************************
; 1 ms timer function calls
;*********************************************************************
bcf STATUS, RP0 ;Select Bank 0
bcf STATUS, RP1
;....... 1ms timer counter here.....
;call sectimer
;call counter
;test toggle LED here...
;bcf PORTB, POWERLED ;Turn off LED
;....................................
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.....
;call counter
;
;test toggle LED off here...
;bcf PORTB, POWERLED ;Turn off LED
;....................................
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.....
;
;call counter
;test toggle LED on here...
;bsf PORTB, POWERLED ;Turn on LED
;....................................
incf COUNT2, f
movlw .10 ;Compare count to 100 decimal
subwf COUNT2, W ;Store the result back in
btfss STATUS, C ;Is the result 0, skip if no
goto exittimer
clrf COUNT2
;**********************************************************************
; 1000ms timer function calls
;**********************************************************************
;....... 1000ms timer counter here.....
;call counter
incf COUNT3, f
movlw .30 ;Compare count to 100 decimal
subwf COUNT3, W ;Store the result back in
btfss STATUS, C ;Is the result 0, skip if no
goto exittimer
clrf COUNT3
;**********************************************************************
; 30000ms timer function calls
;**********************************************************************
;....... 30000ms timer counter here.....
call counter
exittimer
movlw .217 ;count 14
clrf TMR0 ;Clear TMR0 and prescaler
banksel TMR0
movwf TMR0
;-------------- Insert no new code below here ---------------------------------
bcf INTCON, T0IF ;Clear timer overflow flag
bsf INTCON, T0IE ;Enable interrupts again
return
;----------------------------------------------------------------------------------
;**********************************************************************************
initTimer
Global initTimer
GLOBAL COUNT
clrf COUNT
return
end
and check the counter here :
ledmgr.asm
Code:
LIST P=16F628A
#include p16f628A.inc
#include globals.inc
;-------------------------------------------------------------------------------
extern COUNT
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
BANK0 UDATA
;-------------------------------------------------------------------------------
;..... your variables here ....
LedState RES 1
LedTimer RES 1
timersec RES 1
Global LedTimer,LedState,timersec,counter
;-------------------------------------------------------------------------------
JUMPTAB0 CODE
;-------------------------------------------------------------------------------
LEDManager
GLOBAL LEDManager
movlw .10
;movlw .1
BANKSEL LedTimer ;Loading timer value
movwf LedTimer ;to 30sec
movlw high LEDManager
movwf PCLATH
;btfss INTCON,T0IF
;goto exit
movf LedState,w
addwf PCL,f
goto led_state_1
goto led_state_2
;-------------------------------------------------------------------------------
PROG0 CODE
;-------------------------------------------------------------------------------
;...... your state machine here ......
;led_state_1 begin
led_state_1
;call counter
bsf PORTB, POWERLED ;Turn on LED
;wait if there's interrupt
;btfss STATUS,Z
incf LedState,1 ;increase the state, for the next state
return
;led_state_1 end
;-------------------------------------------------------------------------------
;led_state_2 begin
led_state_2
bcf PORTB, POWERLED ;Turn off LED
;btfss STATUS,Z
;goto exit
;how can I check if my counter already zero here ?
;jump to previous state if there's interrupt
decf LedState,1 ;increase the state, for the next state
return
;led_state_2 end
;-------------------------------------------------------------------------------
;--------------- Called in Initialisation ----------------------
initState
Global initState
movlw 0x00
BANKSEL LedState ;Initialising
movwf LedState ;State Value to '0'
movlw .10
;movlw .1 ;test for 1s
BANKSEL LedTimer ;Loading seconds timer
movwf LedTimer ;to 10
return
;--------------------------------------------------------
;---------------------- Called in States ------------------
;counter
; Global counter
; BANKSEL LedTimer
; movf LedTimer,w ;Checking timervalue
; btfsc STATUS,Z ;reaches 0 or not?
; return ;Yes-Return
; decf LedTimer,f ;No-decrement value
; return ;and return
;------------------Call in Timer Module --------------------
counter
Global counter ;Decrementing Sec's
BANKSEL LedTimer ;timer value
movf LedTimer,w ;for every 10 counts
btfss STATUS,Z
decf LedTimer,f
return
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;test
;------------------Call in Timer Module --------------------
;counter
; Global counter ;Decrementing Sec's
; BANKSEL LedTimer ;timer value
; movlw .10 ;for every 10 counts
; movwf LedTimer
;check decfsz LedTimer
; goto check
; return
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
return ;LEDManager
END