AT90S2313-Digital-Clock
This project shows the application of AVR AT90S2313 as DIGITAL CLOCK. It is being
designed to work as a watch that will count at a maximum of 60 for minute hand
and 60 for the second hand.
This circuit uses one AT90S2313 Microcontroller, a four digit 7-segment display &
a driver for this 7-segment display. This digital clock stops after 60 mts.
The program is as shown:
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.text
.global main
.type main, @function
main:
ldi r18,0xff
out 0X17,r18 ;Enabling the ‘DDRD’ and ‘DDRB’ Registers in Output Mode
out 0X11,r18
com r18
mov r30,r18
ext_cmp:
ldi r16,0x00
out 0x2C,R16 ; Initializing the Timer/Counter1 Registers
out 0X2D,r16
out 0X2A,r16 ; Initializing Output Compare Register
out 0X2B,r16
OUT 0X3A,r16
out 0x38,r16
; Change the value of R16 according to the Application
ldi r16,0x3B
;ldi r16,0x02
out 0X2A,r16 ; Loading the Compare Match Value at Output Compare Register
ldi r23,0b01000000
out 0X39,r23 ; Enabling the OCIE1A bit of ‘TIMSK’ Register
sei ; Setting the Global Interrupt Enable Bit = 1
clc
ldi r17,0x00 ;Enabling the Timer/Counter1 Control Register with Clk=
Clk/64
out 0X2E,r17
/* ROUTINE FOR CONVERTING HEX – DECIMAL
; Decimal Adjusting
loop1:
in r28,0X2C
; Conversion from Hex- Dec from 0 - 19
cpi r28,0x0A
brcs output
adiw r28,0x06
; Conversion from Hex- Dec from 19 -29
cpi r28,0x1A
brcs output
adiw r28,0x06
; Conversion from Hex- Dec from 29 -39
cpi r28,0x2A
brcs output
adiw r28,0x06
; Conversion from Hex- Dec from 39 -49
cpi r28,0x3A
brcs output
adiw r28,0x06
; Conversion from Hex- Dec from 49 -59
cpi r28,0x4A
brcs output
adiw r28,0x06
; Extended Value for Upgradation or for special other Timer Application
; Conversion from Hex- Dec from 59 -69
cpi r28,0x5A
brcs output
adiw r28,0x06
; Routine for displaying the minute value through Port B
output:
out 0X18,r28
clc
rjmp loop1
/* TIMER16 - COMPARE ROUTINE
----------------------------*/
.size main, .-main
.global __vector_4
.type __vector_4, @function
__vector_4:
ldi r16,0x00
clc
out 0X18,r16 ; Clearing The Port B , ‘TCCR1B’ & ‘TCNT1L’ Registers
out 0X2E,r16
out 0X2C,r16
adiw r30,0x01 ; Incrementing the Register R30 which stores the Hour value
of the Clock
; Change the value according to the Application
cpi r30,0x5a ; Checking whether Hour Hand has reached 24 hrs
breq output2
; Routine for Hex- Dec Conversion for Hour Hand in Clock
*/
cpi r30,0x0A
brne output1
adiw r30,0x06
output1:
cpi r30,0x1A
brne output3
adiw r30,0x06
output3:
cpi r30,0x2A
brne output4
adiw r30,0x06
output4:
cpi r30,0x3A
brne output5
adiw r30,0x06
output5:
cpi r30,0x4A
brne output6
adiw r30,0x06
output6:
cpi r30,0x5A
brne l1 ;output7
adiw r30,0x06
;output7:
;cpi r30,0x6A
;brne l1
;adiw r30,0x06
; Routine for outputting the Hour Value of the Clock
l1:
out 0X12,r30
rjmp ext_cmp
; Routine for Resetting the Clock after Completing 24 Hrs
*/
output2:
ldi r30,0x00
out 0X12,r30
reti