Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] ds1307(RTC) in assembly

Status
Not open for further replies.

toruk.makto

Newbie level 1
Joined
Feb 10, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
22
i want drive a ds1307 with ATmega32 in assembly

(ATmega32 works in 8 MHZ internal oscillator mode)

i use this simple program for drive ds1307 and its not working ...
leds randomly turn on and off

the purpose of this program is first send primary Values to ds1307
(second/minute/hour/day/month/year)
and then reading second and send it to porta.(to show on leds)

would you please correct this program or write another simple program like this one

(i am beginner in assembly and i searched internet and found nothing )

attention: this mode i used in my program called hardware i2c mode which is used pc0 and pc1 as scl and sda.

the program:

Code ASM - [expand]
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



schematic:
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top