;********************************************************************** ; * ; Filename: StopWatch.asm * ; Date: 2008.May.25 * ; File Version: * ; * ; Author: JR7DUT * ; Company: DUT Brewery * ; * ; * ;********************************************************************** ; * ; Files required: * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ; * ; * ; * ; * ;********************************************************************** list p=16f648A ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _HS_OSC ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS w_temp EQU 0x7D ; variable used for context saving status_temp EQU 0x7E ; variable used for context saving pclath_temp EQU 0x7F ; variable used for context saving Sec_H EQU 0x20 Sec_L EQU 0x21 Dev_H EQU 0x22 Dev_L EQU 0x23 Base EQU 0x24 SSW EQU 0x25 Puls EQU 0x26 fLAP EQU 1 D_L EQU 5 D_H EQU 6 S_L EQU 1 S_H EQU 2 test1 EQU 0x30 test2 EQU 0x31 ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere********************** btfss PIR1,TMR2IF ;TMR2orRB0 INT goto RB0int ;test============================================================= ; movlw 0ffh ; movwf test1 ;tlp1 movlw 0ffh ; movwf test2 ;tlp2 decfsz test2,F ; goto tlp2 ; decfsz test1,F ; goto tlp1 ;test end====================================================== decfsz Base,F ;Base=Base-1 goto XtT2int bsf Puls,1 ;Set 0.01sec puls XtT2int bcf PIR1,TMR2IF goto XtINT RB0int btfsc SSW,fLAP goto ReDisp bsf SSW,fLAP ;if SSW,fLAP is clear, Set fLAP for Disp Halt goto XtRBint ReDisp bcf SSW,fLAP ;if SSW,fLAP is set, Clear fLAP for Disp Renewal XtRBint bcf INTCON,INTF goto XtINT ;***************************************************************************************** XtINT movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt ;============================================================ main clrf PORTB movlw b'00001100' ;Disp DCBA=1100=disp data<_> movwf PORTA ;Initialize PORTA by setting output data latches movlw 0x07 ;Turn comparators off and movwf CMCON ;enable pins for I/O functions bcf STATUS, RP1 bsf STATUS, RP0 ;Select Bank1 movlw b'00100000' ;Value used to initialize data direction movwf TRISA ;Set RA pins ;TRISA<0,4> as outputs ;TRISA<5> always read as e1f. ;TRISA<7:6> depend on oscillator mode bcf OPTION_REG,7 ;PORTB weak pull-up bcf OPTION_REG,6 ;RB0/INT Falling edge movlw b'10000001' ;TRISB<7>input(Start/Stop),<6,1>output,<0>input(Lap IOC) movwf TRISB ;RB<1,4> turns output. Still Disp '_ _._ _', no LE(Light Enable) sig.. ;TMR2 INT condition bsf PIE1,TMR2IE ;TMR2 INT Enable movlw d'200' ; movwf PR2 ;TMR2,PR2 Set 200 bcf STATUS, RP0 ;Select Bank0 ;Initial condition clrf Sec_H clrf Sec_L clrf Dev_H clrf Dev_L movlw d'5' movwf Base ;Initial set of Base = 5 ;6MHzOSC,1.5MHzInstruction cyc.,PR2_200(7500Hz),postscalor15(500Hz) ;500/5=100Hz i.e. 0.01sec clrf SSW clrf Puls clrf INTCON bsf INTCON,GIE ;Global INT Enable bsf INTCON,PEIE ;Periphral INT Enable bsf INTCON,INTE ;RB IINT Enable movlw b'01110000' movwf T2CON ;bit<7> vac ;bit<6,3> postscalor 1;15 ;bit<2> TMR2 off ;bit<1,0> prescalor 1:1 bcf PIR1,TMR2IF ;=========================================================================================== ;Poling START Sig Start btfsc PORTB,7 ;Polling START/STOP SW(SW on, PORTB,7 clear) goto Start bsf T2CON,TMR2ON ;TMR2 start ;Display start from '00.00' clrf PORTA bcf PORTB,D_L ;'_ _._0' bsf PORTB,D_L bcf PORTB,D_H ;'_ _.00' bsf PORTB,D_H bcf PORTB,S_L ;'_ 0.00' bsf PORTB,S_L bcf PORTB,S_H ;'00.00' bsf PORTB,S_H ;Wait START Button open, Base puls W1 btfsc Puls,1 call IncRes btfss PORTB,7 ;PORTB,7 set, if START Button open goto W1 goto W2 ;Now START Button open. Wait STOP sig, Base,puls W2 btfsc Puls,1 call IncRes btfsc PORTB,7 ;check if STOP button on goto W2 ENDsq bcf T2CON,TMR2ON ;Stop TMR2. goto ENDsq ;Infinite Loop. Wait reset. ;;;;;Subruotine;;;;; ;Increment Display Resisters ;Reset Base & Clear Puls IncRes movlw d'5' movwf Base ;Initial set of Base = 5 clrf Puls ;Dev_L incf Dev_L,F movf Dev_L,W ; bcf STATUS,Z sublw d'10' ;check if Dev_L up to 10 btfss STATUS,Z goto Disp ;if not 10, Inc Res finished clrf Dev_L ;if 10, Dev_L disp '0', carry to Dev_H ;Dev_H incf Dev_H,F movf Dev_H,W ; bcf STATUS,Z sublw d'10' ;check if Dev_H up to 10 btfss STATUS,Z goto Disp ;if not 10, Inc Res finished clrf Dev_H ;if 10, Dev_H disp '0', carry to Sec_L ;Sec__L incf Sec_L,F movf Sec_L,W ; bcf STATUS,Z sublw d'10' ;check if Sec_L up to 10 btfss STATUS,Z goto Disp ;if not 10, Inc Res finished clrf Sec_L ;if 10, Sec_L disp '0', carry to Sec_H ;Sec__H incf Sec_H,F movf Sec_H,W ; bcf STATUS,Z sublw d'10' ;check if Sec_L up to 10 btfss STATUS,Z goto Disp ;if not 10, Inc Res finished clrf Sec_H ;if 10, Sec_L disp '0', carry to Dev_L goto IncRes ;Return to 00.01. csuses 0.01sec mismatch Disp btfsc SSW,fLAP ;check if in Lap Display goto LAP ;Display routine movf Dev_L,W movwf PORTA bcf PORTB,D_L bsf PORTB,D_L movf Dev_H,W movwf PORTA bcf PORTB,D_H bsf PORTB,D_H movf Sec_L,W movwf PORTA bcf PORTB,S_L bsf PORTB,S_L movf Sec_H,W movwf PORTA bcf PORTB,S_H bsf PORTB,S_H LAP bsf PORTB,D_L bsf PORTB,D_H bsf PORTB,S_L bsf PORTB,S_L return ;;;;;End of Subroutine;;;;; END ; directive 'end of program'