Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;******************************************************************************
- ;PICMicro3
- ;By Daniel 2017
- ;8-Bit stopwatch BCD Display with start stop and up down buttons
- ;******************************************************************************
- ;MPASM Assembler Init
- list p=16f84a
- #include <p16f84a.inc>
- errorlevel -302
- __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
- ;******************************************************************************
- ;Custom Port names
- #define b1 PORTB,7
- #define b2 PORTB,4
- ;******************************************************************************
- ;Variables
- cblock 0x20
- Cntd1
- CntByt1
- CntByt2
- LoByt1
- HiByt1
- endc
- ;Starting Vector
- org 0x0000
- goto Init
- ;******************************************************************************
- ;Delay Block
- Delay1 ;1ms
- movlw D'247'
- VarDel1
- movwf Cntd1
- Loopd1
- nop
- decfsz Cntd1,f
- goto Loopd1
- return
- ;******************************************************************************
- LpCnt1 ;200ms
- movlw D'200'
- VarCnt1
- movwf CntByt1
- LoopBlk1
- call Delay1
- decfsz CntByt1,f
- goto LoopBlk1
- return
- ;******************************************************************************
- LpCnt2 ;500ms
- movlw D'2'
- VarCnt2
- movwf CntByt2
- LoopBlk2
- call LpCnt1
- decfsz CntByt2,f
- goto LoopBlk2
- return
- ;******************************************************************************
- ;Increment 2Bytes Block
- Inc2By
- incf LoByt1,f
- movlw d'10' ;Lower byte upper limit +1
- xorwf LoByt1,w ;XOR into w to test if equal
- btfss STATUS,Z ;Skip if not equal (Z=0)
- goto Disp2Byt
- movlw b'00000000'
- movwf LoByt1
- incf HiByt1,f
- movlw d'10'
- xorwf HiByt1,w
- btfss STATUS,Z
- goto Disp2Byt
- movlw b'00000000'
- movwf HiByt1
- goto Disp2Byt
- ;Decrement 2Bytes Block
- Dec2By
- decf LoByt1,f
- movlw b'11111111'
- xorwf LoByt1,W
- btfss STATUS,Z
- goto Disp2Byt
- movlw b'00001001'
- movwf LoByt1
- decf HiByt1,f
- movlw b'11111111'
- xorwf HiByt1,W
- btfss STATUS,Z
- goto Disp2Byt
- movlw b'00001001'
- movwf HiByt1
- ;Display Block
- Disp2Byt
- movf LoByt1,W ;Load byte in w
- movwf PORTA ;Upper nibble is ignored
- movf HiByt1,W ;Swap upper and lower nibble
- movwf PORTB ;Load upper nibble into B
- return
- ;******************************************************************************
- ;Stop/Start button block
- Stopb1
- movlw d'50'
- call VarCnt1
- btfss b1
- goto Startb1
- Startb1
- movlw d'50'
- call VarCnt1
- btfsc b1
- goto Stopb1
- Runb1
- movlw d'50'
- call VarCnt1
- btfss b1
- goto Runb1
- return
- ;******************************************************************************
- ;Init Block
- Init
- bsf STATUS,RP0 ;Select Bank1
- clrf TRISA ;Write 0 to TRISA to set as outputs
- movlw b'11110000' ;4 inputs and 4 outputs
- movwf TRISB ;Make the upper nibble inputs
- movlw b'00001000' ;Move 1 into OPTION register
- movwf OPTION_REG
- bcf STATUS,RP0 ;Select Bank0
- movlw b'00000000' ;Default state for PORTA
- movwf PORTA
- movlw b'10010000' ;Default state for PORTB
- movwf PORTB
- movlw b'00000000'
- movwf LoByt1 ;Resets Counter
- movwf HiByt1
- goto Start
- ;******************************************************************************
- ;Main Program
- Start
- call LpCnt1 ;Wait 200ms
- btfss b1 ;Test if B1 is pressed
- call Stopb1 ;Goto Idle button routine
- btfss b2 ;Test if B2 is pressed
- call Dec2By ;Decrement count if b2 is held down
- btfss b2
- goto Start
- call Inc2By ;Else increment count
- goto Start
- end
- ;******************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement