;Binary Clock 2009 LIST p=16F628A ;tell assembler what chip we are using include "P16F628A.inc" ;include the defaults for the chip __config 0x3D18 ;sets the configuration settings ;(oscillator type etc internal.) Ticks EQU 20h Seconds EQU 21h Minutes EQU 22h Hours EQU 23h Delay EQU 24h Delay1 EQU 25h BCD EQU 26h BCDCount EQU 27h BCDSeconds EQU 28h BCDMinutes EQU 29h BCDHours EQU 30h Count EQU 31h abuff EQU 32h bbuff EQU 33h TenSeconds EQU 34h TenMinutes EQU 35h TenHours EQU 36h push_w EQU 37h push_status EQU 38h org 0x0000 ;org sets the origin, 0x0000 for the 16F628, ;this is where the program starts running goto start ; ***************************************** ; Interrupt Service Routine ; ***************************************** org 0x004 _intserv ; Save W and Status movwf push_w swapf STATUS,W bcf STATUS,RP0 ; Sel bank 0 movwf push_status incf Ticks ; Increment the tick bcf INTCON,1 ;Clear flag bsf PORTA,4 swapf push_status,W movwf STATUS swapf push_w,F swapf push_w,W retfie ; This instruction sets the GIE bit ; in INTCON register and returns from ; interupt start bsf INTCON,7 ;GIE – Global interrupt enable (1=enable) bsf INTCON,4 ;INTE - RB0 interrupt enable (1=enable) bcf INTCON,1 ;Clear flag movlw 0x07 movwf CMCON ;turn comparators off (make it like a 16F84) bsf STATUS, RP0 ;select bank 1 Movlw b'11000000' movwf OPTION_REG movlw b'00000001' ;set PortB to outputs interrupt to input movwf TRISB movlw b'00011000' movwf TRISA ;set PortA all outputs bcf STATUS, RP0 ;select bank movlw 0 movwf Ticks movwf Seconds movwf Minutes movwf Hours movwf TenSeconds movwf TenMinutes movwf TenHours movwf BCDSeconds movwf BCDMinutes movwf BCDHours Loop Display btfss PORTA,3 Call Settime bcf PORTA,4 movlw b'11111110' movwf PORTA ;set all bits on Movlw b'11111111' xorwf BCDHours,0 movwf PORTB Movlw b'11111111' movwf PORTB movlw b'11111101' movwf PORTA ;set all bits on Movlw b'11111111' xorwf BCDMinutes,0 movwf PORTB Movlw b'11111111' movwf PORTB movlw b'11111011' movwf PORTA ;set all bits on Movlw b'11111111' xorwf BCDSeconds,0 movwf PORTB Movlw b'11111111' movwf PORTB nop ;the nop's make up the time taken by the goto nop ;giving a square wave output Movlw .100 ;Change this to 120 if building in the USA XORWF Ticks,0 BTFSS STATUS,Z Goto Loop clrf Ticks Incf Seconds,1 movf Seconds,0 Addlw .6 ;Test to see if between A-F BTFSC STATUS,DC ;Did it cause a carry ? Call Incrementtenseconds Movf Seconds,0 Call Spin ;Move seconds to MSB Movwf BCDSeconds ; Move seconds to BCB Seconds bcf BCDSeconds,3 bcf BCDSeconds,2 bcf BCDSeconds,1 btfsc TenSeconds,0 bsf BCDSeconds,3 btfsc TenSeconds,1 bsf BCDSeconds,2 btfsc TenSeconds,2 bsf BCDSeconds,1 Movlw .6 XORWF TenSeconds,0 BTFSS STATUS,Z Goto Loop Clrf Seconds Clrf TenSeconds Clrf BCDSeconds Incf Minutes,1 movf Minutes,0 Addlw .6 ;Test to see if between A-F BTFSC STATUS,DC ;Did it cause a carry ? Call IncrementtenMinutes Movf Minutes,0 Call Spin ;Move seconds to MSB Movwf BCDMinutes ; Move seconds to BCB Seconds bcf BCDMinutes,3 bcf BCDMinutes,2 bcf BCDMinutes,1 btfsc TenMinutes,0 bsf BCDMinutes,3 btfsc TenMinutes,1 bsf BCDMinutes,2 btfsc TenMinutes,2 bsf BCDMinutes,1 Movlw .6 XORWF TenMinutes,0 BTFSS STATUS,Z Goto Loop Clrf Minutes Clrf TenMinutes Clrf BCDMinutes Incf Hours,1 movf Hours,0 Addlw .6 ;Test to see if between A-F BTFSC STATUS,DC ;Did it cause a carry ? Call IncrementtenHours Movf Hours,0 Call Spin ;Move seconds to MSB Movwf BCDHours ; Move seconds to BCB Seconds bcf BCDHours,3 bcf BCDHours,2 bcf BCDHours,1 btfsc TenHours,0 bsf BCDHours,3 btfsc TenHours,1 bsf BCDHours,2 Movlw .2 XORWF TenHours,0 BTFSS STATUS,Z Goto Loop Movlw .4 XORWF Hours,0 BTFSS STATUS,Z Goto Loop Clrf Hours Clrf TenHours Goto Loop Movlw .60 XORWF Minutes,0 BTFSS STATUS,Z Goto Loop Movlw 0 Movwf Minutes Incf Hours,1 Movlw .24 XORWF Hours,0 BTFSS STATUS,Z Goto Loop Movlw 0 Movwf Hours goto Loop ;go back and do it again BinBCD clrf BCD clrf BCDCount Movwf BCD again movlw .10 subwf BCD,F btfss STATUS,C Return Incf BCDCount goto again Spin ;Reverse bit order code here movwf abuff bsf Count,3 ;count = 8 bitcount rrf abuff rlf bbuff decfsz Count goto bitcount movf bbuff,0 Return bcf bbuff,3 bcf bbuff,2 bcf bbuff,1 btfsc BCDCount,0 bsf bbuff,3 btfsc BCDCount,1 bsf bbuff,2 btfsc BCDCount,2 bsf bbuff,1 movf bbuff,0 return Incrementtenseconds incf TenSeconds clrf Seconds Return IncrementtenMinutes incf TenMinutes clrf Minutes Return IncrementtenHours incf TenHours clrf Hours Return Settime incf Ticks Movlw .100 Movwf Delay Loop1 Decfsz Delay,1 Goto Loop1 Return end