Digital clock


digital clock schematic based on PCF8563

Pcf8563 clock schematic...

digital clock with 7 segment led display and pic16f628 microcontroller

powered by a mobile phone charger

Pic16f628A can be replaced with a Pic16f627.

For memory back up I use a battery lithium coin ( button cell ) 3v 20mm type CR2032 which can be found at electronic shops.

The source code for this clock it is available for download
;================Ceas Version 1.0==================16/04/09==
;	internal clock
; http://www.module.ro
;------------------------------------------------------------
;------------------------------------------------------------
;------------------------------------------------------------
     LIST P=16F628A;f=inhx8m
    ; LIST P=16F627A;f=inhx8m
        #include "P16F628A.INC"  ; Include header file
       ; #include "P16F628A.INC"  ; Include header file
	__CONFIG	_PWRTE_ON  & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _LVP_OFF & _CP_OFF & _MCLRE_OFF
	errorlevel	-302	
;------------------------------------------------------------
	cblock 0x20	; Beginn General Purpose-Registerstatus	
	transo
	count1	
	count2	
	count3
	count4
	hh
	hl
	mh
	ml
	minl
	minh
	hourl
	hourh
	endc
;------------------------------------------------------------

#DEFINE dig1	PORTA,7
#DEFINE dig2	PORTA,0
#DEFINE dig3	PORTA,1
#DEFINE dig4	PORTA,6
#DEFINE sclk	PORTA,2
#DEFINE sdta	PORTA,3
#DEFINE buton	PORTA,5
;-------------------------------------------------------------
	org	0x00
	goto	init
	org	0x04
decode
	addwf	PCL,F
	retlw	0x77	;0
	retlw	0x21	;1
	retlw	0xD5	;2
	retlw	0xB5	;3
	retlw	0xA3	;4
	retlw	0xB6	;5
	retlw	0xF6	;6
	retlw	0x25	;7
	retlw	0xF7	;8
	retlw	0xB7	;9
	retlw	0x77	;0
	retlw	0x77	;0
	retlw	0x77	;0
	retlw	0x77	;0
	retlw	0x77	;0
	retlw	0x77	;0
;;------------------------------------------------------------
init	
	call	haltc
	clrf	PORTA
	clrf	PORTB
	movlw	0x07		; Turn comparators OFF and enable pins for I/O 
	movwf	CMCON
	bcf	STATUS,RP1
	bsf	STATUS,RP0  ;switch to bank 1
	clrf	TRISA
	clrf	TRISB
	bcf	STATUS,RP0  ;switch back to bank 0

	call	iict
	movlw	0xA2
	call	act
	movlw	0x0D
	call	act
	movlw	0x83
	call	act
	call	iicp


tim1	call	time_rd
	btfss	buton
	goto	set_ini
	call	tabel

	clrf	 count4
nou	movf	ml,W
	movwf	PORTB
	bsf	dig1
	call	halta
	bcf	dig1
	movf	mh,W
	movwf	PORTB
	bsf	dig2
	call	halta
	bcf	dig2
	movf	hl,W
	movwf	PORTB
	bsf	dig3
	call	halta
	bcf	dig3
	movf	hh,W
	movwf	PORTB
	sublw	0x77
	btfss	STATUS,Z ;test zero bit
	bsf	dig4
	call	halta
	bcf	dig4
	incf	count4,F
	btfss	STATUS,Z
	goto	nou
	goto	tim1

set_ini
	call	clone
setare
	movlw	0xC0
	call	afisare	
	btfsc	buton
	goto	time_wr
	movlw	0xE0
	call	afisare
	movlw	0x0A
	movwf	count3
rep1	btfsc	buton
	goto	setare
	call	timeup
	movlw	0xD9
	call	afisare
	decfsz	count3,F
	goto	rep1
rep2	btfsc	buton
	goto	setare
	call	timeup
	movlw	0xFD
	call	afisare
	goto	rep2
time_wr
	swapf	minh,W
	addwf	minl
	swapf	hourh,W
	addwf	hourl
	call	iict
	movlw	0xA2
	call	act
	movlw	0x02
	call	act
	movlw	0x00
	call	act
	movf	minl,W
	call	act
	movf	hourl,W
	call	act
	call	iicp
	goto	tim1
;**********************************************************************
afisare
	movwf	 count4
	movf	minl,W
	call	decode
	movwf	ml
	movf	minh,W
	call	decode
	movwf	mh
	movf	hourl,W
	call	decode
	movwf	hl
	movf	hourh,W
	call	decode
	movwf	hh
rep5	movf	ml,W
	movwf	PORTB
	bsf	dig1
	call	halta
	bcf	dig1
	movf	mh,W
	movwf	PORTB
	bsf	dig2
	call	halta
	bcf	dig2
	movf	hl,W
	movwf	PORTB
	bsf	dig3
	call	halta
	bcf	dig3
	movf	hh,W
	movwf	PORTB
	bsf	dig4
	call	halta
	bcf	dig4
	incf	count4,F ; incfsz
	btfss	STATUS,Z
	goto	rep5
	return
;**********************************************************************
timeup
	incf	minl,F
	movlw	0x0A
	subwf	minl,W
	btfss	STATUS,Z ;test zero bit
	goto	gatas
	clrf	minl

	incf	minh,F
	movlw	0x06
	subwf	minh,W
	btfss	STATUS,Z ;test zero bit
	goto	gatas
	clrf	minh

	incf	hourl,F
	movlw	0x02
	subwf	hourh,W
	btfss	STATUS,Z ;test zero bit
	goto	twoh
	movlw	0x04
	subwf	hourl,W
	btfss	STATUS,Z ;test zero bit
	goto	gatas
	clrf	hourl
	clrf	hourh
	goto	gatas
twoh
	movlw	0x0A
	subwf	hourl,W
	btfss	STATUS,Z ;test zero bit
	goto	gatas
	clrf	hourl
	incf	hourh,F
gatas	return
;**********************************************************************
time_rd	
	call	iict
	movlw	0xA2
	call	act
	movlw	0x03
	call	act
	call	iict
	movlw	0xA3
	call	act
	call	rx_iic
	movf	transo,W
	movwf	mh
	movwf	ml
	swapf	mh,F
	movlw	0x0F
	andwf	mh,F
	andwf	ml,F
	call	ackm
	call	rx_iic
	movf	transo,W
	movwf	hh
	movwf	hl
	swapf	hh,F
	movlw	0x03
	andwf	hh,F
	movlw	0x0F
	andwf	hl,F
	call	ackp
	call	iicp
	return
;**********************************************************************
clone
	movf	ml,W
	movwf	minl
	movf	mh,W
	movwf	minh
	movf	hl,W
	movwf	hourl
	movf	hh,W
	movwf	hourh
	return
;**********************************************************************
tabel
	movf	ml,W
	call	decode
	movwf	ml
	movf	mh,W
	call	decode
	movwf	mh
	movf	hl,W
	call	decode
	movwf	hl
	movf	hh,W
	call	decode
	movwf	hh
	return
;**********************************************************************
rx_iic
	movlw 0x08
	movwf count3
sbit	bcf	sclk
	call	ser_in
	call	haltb
	bcf	STATUS,C
	bsf	sclk
	call	haltb
	btfsc sdta
	bsf	STATUS,C	
	rlf	transo,F
	decfsz count3,F
	goto	sbit
	bcf	sclk
	call	ser_out
	return
;***************************************************
act	movwf transo	; iic data transmission 
	movlw 0x08
	movwf count3
vbit	bcf	sclk
	call	haltb
	btfsc transo,7	
	bsf	sdta
	btfss transo,7
	bcf	sdta
	call	haltb
	bsf	sclk
	call	haltb
	bcf	sclk
	call	haltb
	rlf	transo,F
	decfsz	count3,F
	goto	vbit
	call	ackp
	return
;***************************************************
iicp	bcf	sdta	; stop condition module
	call	haltb
	bsf	sclk
	call	haltb
	bsf	sdta	; stop command
	call	haltb
	bcf	sclk
	call	haltb
	return
;***************************************************	
iict	bsf	sdta	; start condition module 
	bsf	sclk
	call	haltb
	bcf	sdta	; start command
	call	haltb
	bcf	sclk
	call	haltb
	return
;***************************************************
ackp	call	ser_in
	bsf	sclk	; one clock step for acknowledge (not read)
	call	haltb
	bcf	sclk
	call	ser_out
	return
;***************************************************
ackm	bcf	sdta
	call	haltb
	bsf	sclk	; one clock step for acknowledge (not read)
	call	haltb
	bcf	sclk
	nop
	bcf	sdta
	return
;************************************************************************
;	Subrutine de intarziere				 		*
;************************************************************************
halta	
	movlw	0x02	;2ms
	movwf	count2
m1	movlw	0xFA	
	movwf	count1
m0	nop
	decfsz	count1,F	
	goto 	m0
	decfsz	count2,F	
	goto 	m1
 	retlw	0x00
;______________________________________________________________________

haltb
	nop
	nop
 	return
;________________________________________________________________________
haltc	
	movlw	0x96	;150ms
	movwf	count2
n1	movlw	0xFA	
	movwf	count1
n0	nop
	decfsz	count1,F	
	goto 	n0
	decfsz	count2,F	
	goto 	n1
 	return

;************************************************************************
ser_in
	bsf	STATUS,RP0	; Bank 1
	movlw	0x28	; input
	movwf	TRISA
	bcf	STATUS,RP0	; Bank 0
	return
;************************************************************************
ser_out
	bsf	STATUS,RP0	; Bank 1
	movlw	0x20	; output
	movwf	TRISA
	bcf	STATUS,RP0	; Bank 0
	return
;------------------------------------------------------------
	end
;============================================================

PCB sandwich



Back to my home page

Last updated January 2010

© Copyright 2010 Bergthaller Iulian-Alexandru