1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
| /*
* ds1307.asm
*
* Created: 1/17/2014 5:13:16 PM
* Author: Home
*/
.include "m32def.inc"
.org 00
;---------------------------Initialized stack pointer
ldi r16,high(ramend)
out sph,r16
ldi r16,low(ramend)
out spl,r16
;----------------------make porta output
ldi r16,0xff
out ddra,r16
;--------------------------start i2c connection and put zero in 07H of ds1307 (primary setting)
call i2c_init
call i2c_start
ldi r16,208
call i2c_send
ldi r16,0x07
call i2c_send
ldi r16,0x00
call i2c_send
call i2c_stop
;----------------- send primary values to set (hour/minute/second) in ds1307
call delay
call i2c_start
ldi r16,208
call i2c_send
ldi r16,0x00
call i2c_send
ldi r16,0x55
call i2c_send
ldi r16,0x58
call i2c_send
ldi r16,0b00010110
call i2c_send
call i2cstop
;-------------------reading second from ds1307 and send to porta
call delay
main: call i2c_init
call i2c_start
ldi r16,208
call i2c_send
call i2c_start
ldi r16,209
call i2c_send
ldi r16,0x00
call i2c_send
in r18,twdr
out porta,r18
call i2c_stop
call delay_1sec
rjmp main
;-----------------------------------Subprograms
delay_1sec:
ldi r19,250
l3: ldi r20,200
l2: ldi r21,40
l1: nop
dec r21
brne l1
dec r20
brne l2
dec r19
brne l3
ret
delay:
ldi r17,0xff
a1: dec r17
nop
brne a1
ret
i2c_init:
ldi r16,1
out twsr,r16
ldi r16,123
out twbr,r16
ldi r16,(1<<twen)
out twcr,r16
ret
i2c_start:
ldi r16,(1<<twint)|(1<<twsta)|(1<<twen)
out twcr,r16
wait1:
in r16,twcr
sbrs r16,twint
rjmp wait1
ret
i2c_send:
out twdr,r16
ldi r16,(1<<twen)|(1<<twint)
out twcr,r16
q1: in r16,twcr
sbrs r16,twint
rjmp q1
ret
i2c_stop:
ldi r16,(1<<twint)|(1<<twsto)|(1<<twen)
out twcr,r16
ret |