AT90S2313-10-hrs-Clock
This project shows the application of AVR AT90S2313 as a 10-Hour digital clock used for monitoring a system for ten hours. It is being designed to work as a watch, showing hours, minutes and seconds and it will count at a maximum of 10 for hour hand, 60 for minute hand and 60 for the second hand.
This circuit uses two AT90S2313 Microcontroller, a Six digit 7-segment display & a driver for this 7-segment display.
The program is as shown:
Code 1
__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 Routine--------------------------
main:
ldi r16,0xff
out 0X17,r16 ;enabling the DDRD and DDRB registers in OUTPUT MODE
out 0X11,r16
com r16
mov r30,r16
out 0x2C,r16 ; initializing the TIMER/COUNTER1 registers
out 0X2D,r16
out 0X2A,r16 ; initializing OUTPUT COMPARE REGISTER
out 0X2B,r16
ext_cmp:
out 0x38,r16 ; change the value of R16 according to the application
ldi r16,0x3C
;ldi r16,0x02
out 0X2A,r16 ; loading the compare match value at OUTPUT COMPARE REGITER
ldi r23,0b01000000
out 0X39,r23 ; enabling the OCIE1A bit of TIMSK register
sei
clc
ldi r17,0x03 ;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 PORTB
output:
out 0X18,r28
clc
rjmp loop1
/* timer16 - compare routine*/
.size main, .-main
.global __vector_4
.type __vector_4, @function
__vector_4:
ldi r31,0xDF
out __SP_L__,r31
ldi r16,0x00
clc
out 0X18,r16 ; Clearing the PORTB , TCCR1B & TCNT1L Registers
out 0X2E,r16
out 0X2C,r16
adiw r30,0x00 ; 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 10 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 10 hrs */
output2:
ldi r30,0x00
out 0X12,r30
rjmp main
CODE 2
__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:
; prologue: frame size=0
; ldi r28,lo8(__stack - 0)
; ldi r29,hi8(__stack - 0)
; out __SP_H__,r29
; out __SP_L__,r28
/* prologue end (size=4) */
ldi r31,0x01 ; Incrementing the R31 by 1
ldi r20,0x00 ; Setting up the DDRB register as input mode
out 0x17,r20
com r20
andi r20,0b1111000 ; Setting the higher nibble of PORTD as output mode
out 0x11,r20
loop1:
in r22 ,0x16 ; Inputting R22 with 0x16 & checking whether it has reached zero
cpi r22,0x00 ; Checking whether R22 has reached zero if equal jump to loop2
breq loop2
rjmp loop1
loop2:
out 0x12,r25 ; outputting R25 through PORTD
inc r24 ; Incrementing R24
cpi r24,0x0b ; comparing R24 with 0x0b
breq clear ; if z =1 jumps to label 'clear'
;cpi r24,0x0a
;breq convert
mov r25,r24 ; moving value at R24 to R25
clc
rol r25 ; rotating R25 3 times left
rol r25
rol r25
ldi r28,0x4 ; setting up the INT0 bit of GIMSK register
out 0x3B,r28
ldi r29,0x30 ; setting the SE bit of MCUCR
out 0x35,r29
sei ; enabling the "global interrupt enable" bit of SREG
sleep
;convert:
;adiw r24,0x06
;ret
clear:
ldi r24,0x00 ; resetting R24 & R25 & back to main
ldi r25,0x00
ret
.size main, .-main
.global __vector_1
.type __vector_1, @function
__vector_1:
; prologue: frame size=0
; prologue end (size=0)
ldi r28,0xDF
out __SP_L__,r28
reti
;rjmp main