added timer interrupt and a function whic returns if a button(defines: butt1, butt2, butt3) has been clicked

This commit is contained in:
Dorian Zedler 2018-08-05 16:33:41 +02:00
parent 16d1f07226
commit a3dcc424d1
9 changed files with 426 additions and 234 deletions

Binary file not shown.

Binary file not shown.

View file

@ -1,9 +1,9 @@
:1000000014C02CC02BC02AC029C028C027C026C0BD
:1000000014C02CC02BC02AC029C0A7C027C026C03E
:1000100025C024C023C022C021C020C01FC01EC0D4
:100020001DC01CC01BC01AC019C011241FBECFEDBB
:10003000CDBF10E0A0E6B0E0EEE3F2E002C0059034
:10003000CDBF10E0A0E6B0E0E6EFF2E002C0059030
:100040000D92A237B107D9F720E0A2E7B0E001C0D6
:100050001D92A837B207E1F7AED0EFC0D1CFCF9352
:100050001D92A837B207E1F7F4D04BC1D1CFCF93AF
:10006000C2E362D0C150E9F7CF910895CF93C62F74
:10007000843038F4823048F4882371F0813049F0BC
:100080000CC0843051F4939808C04F73833009F446
@ -19,21 +19,33 @@
:1001200082E0DEDF9CDF0895CF93DF931F92CDB78F
:10013000DD2784E4898389819FEF980F9983882341
:1001400041F08981898189819FEF980F998381117D
:10015000F8CF0F90DF91CF910895EF92FF920F9318
:100160001F93CF937C01892B29F081E0E816F104DD
:1001700031F00AC06894EE24E1F8F12C05C00F2E8E
:10018000F3E0EF2EF12CF02DFA0160816F3569F06C
:100190008A010F5F1F4FC0E04C2F8E2D67DFF801E3
:1001A00061918F01CF5F6F35B9F7CF911F910F919B
:1001B000FF90EF90089511BAC2E7D0E080917400EB
:1001C000882319F0813051F0FBCF109275008DDF3C
:1001D00081E086DF81E080937400F0CF81E080933E
:1001E000750040E650E060E070E080E090E0B5DF50
:1001F00090B380917700937021E0933009F020E074
:10020000982F91702917A1F090B39370933069F4EF
:1002100081608093770080917200909173000196C5
:10022000909373008093720003C08E7F8093770059
:0E0230008881805D80936000C1CFF894FFCF7D
:10023E002048616C6C6F5F5F5F5F5F5F5F5F5F5FEA
:02024E005F004F
:10015000F8CF0F90DF91CF9108951F920F920FB6B5
:100160000F9211248F939F9386EE99EF9DBD8CBDC6
:100170009F918F910F900FBE0F901F901895EF9247
:10018000FF920F931F93CF937C01892B29F081E07D
:10019000E816F10431F00AC06894EE24E1F8F12C7D
:1001A00005C00F2EF3E0EF2EF12CF02D042F152FAC
:1001B000C0E0F80161918F016F3519F04C2F8E2D41
:1001C00055DFCF5FC031A9F7CF911F910F91FF90FD
:1001D000EF90089520B3BC016F5F7F4F409177008F
:1001E000E1E0F0E0DF0102C0AA0FBB1F8A95E2F751
:1001F000CD01237030E051E02617370709F050E0B9
:10020000242F30E028233923E1E0121613060CF0E6
:10021000E0E05E1799F020B3237030E062177307B7
:1002200031F4842B8093770081E090E008958095ED
:1002300048234093770080E090E0089580E090E0CC
:10024000089511BA86EE99EF9DBD8CBD1FBC85E067
:100250008EBD80E889BF7894C2E7D0E080917400B9
:10026000882319F0813051F0FBCF109275003DDFEB
:1002700081E036DF81E080937400F0CF81E08093ED
:10028000750040E650E060E070E080E090E077DFED
:1002900080E090E09FDF892B51F080917200909177
:1002A0007300019690937300809372001DC081E0EB
:1002B00090E090DF892B51F0809172009091730053
:1002C000029690937300809372000EC082E090E0DB
:1002D00081DF892B49F08091720090917300039621
:1002E00090937300809372008881805D809360009A
:0602F000B5CFF894FFCF2A
:1002F6002048616C6C6F5F5F5F5F5F5F5F5F5F5F32
:020306005F0096
:00000001FF

View file

@ -3,31 +3,31 @@ AtTiny_alarm_clock.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000023e 00000000 00000000 00000094 2**1
0 .text 000002f6 00000000 00000000 00000094 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000012 00800060 0000023e 000002d2 2**0
1 .data 00000012 00800060 000002f6 0000038a 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000006 00800072 00800072 000002e4 2**0
2 .bss 00000006 00800072 00800072 0000039c 2**0
ALLOC
3 .comment 00000030 00000000 00000000 000002e4 2**0
3 .comment 00000030 00000000 00000000 0000039c 2**0
CONTENTS, READONLY
4 .note.gnu.avr.deviceinfo 00000040 00000000 00000000 00000314 2**2
4 .note.gnu.avr.deviceinfo 00000040 00000000 00000000 000003cc 2**2
CONTENTS, READONLY
5 .debug_aranges 00000090 00000000 00000000 00000354 2**0
5 .debug_aranges 000000a0 00000000 00000000 0000040c 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_info 00000a9b 00000000 00000000 000003e4 2**0
6 .debug_info 00000b59 00000000 00000000 000004ac 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_abbrev 000006f0 00000000 00000000 00000e7f 2**0
7 .debug_abbrev 00000738 00000000 00000000 00001005 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_line 0000059a 00000000 00000000 0000156f 2**0
8 .debug_line 0000061f 00000000 00000000 0000173d 2**0
CONTENTS, READONLY, DEBUGGING
9 .debug_frame 00000120 00000000 00000000 00001b0c 2**2
9 .debug_frame 00000154 00000000 00000000 00001d5c 2**2
CONTENTS, READONLY, DEBUGGING
10 .debug_str 00000446 00000000 00000000 00001c2c 2**0
10 .debug_str 00000470 00000000 00000000 00001eb0 2**0
CONTENTS, READONLY, DEBUGGING
11 .debug_loc 000003bb 00000000 00000000 00002072 2**0
11 .debug_loc 00000428 00000000 00000000 00002320 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_ranges 00000078 00000000 00000000 0000242d 2**0
12 .debug_ranges 00000088 00000000 00000000 00002748 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
@ -38,7 +38,7 @@ Disassembly of section .text:
4: 2b c0 rjmp .+86 ; 0x5c <__bad_interrupt>
6: 2a c0 rjmp .+84 ; 0x5c <__bad_interrupt>
8: 29 c0 rjmp .+82 ; 0x5c <__bad_interrupt>
a: 28 c0 rjmp .+80 ; 0x5c <__bad_interrupt>
a: a7 c0 rjmp .+334 ; 0x15a <__vector_5>
c: 27 c0 rjmp .+78 ; 0x5c <__bad_interrupt>
e: 26 c0 rjmp .+76 ; 0x5c <__bad_interrupt>
10: 25 c0 rjmp .+74 ; 0x5c <__bad_interrupt>
@ -65,7 +65,7 @@ Disassembly of section .text:
32: 10 e0 ldi r17, 0x00 ; 0
34: a0 e6 ldi r26, 0x60 ; 96
36: b0 e0 ldi r27, 0x00 ; 0
38: ee e3 ldi r30, 0x3E ; 62
38: e6 ef ldi r30, 0xF6 ; 246
3a: f2 e0 ldi r31, 0x02 ; 2
3c: 02 c0 rjmp .+4 ; 0x42 <__SREG__+0x3>
3e: 05 90 lpm r0, Z+
@ -87,8 +87,8 @@ Disassembly of section .text:
52: a8 37 cpi r26, 0x78 ; 120
54: b2 07 cpc r27, r18
56: e1 f7 brne .-8 ; 0x50 <.do_clear_bss_loop>
58: ae d0 rcall .+348 ; 0x1b6 <main>
5a: ef c0 rjmp .+478 ; 0x23a <_exit>
58: f4 d0 rcall .+488 ; 0x242 <main>
5a: 4b c1 rjmp .+662 ; 0x2f2 <_exit>
0000005c <__bad_interrupt>:
5c: d1 cf rjmp .-94 ; 0x0 <__vectors>
@ -327,188 +327,314 @@ void wait_100us(void){
156: cf 91 pop r28
158: 08 95 ret
0000015a <lcd_write_text>:
0000015a <__vector_5>:
int counter = 0;
uint8_t flags;
ISR (TIMER1_OVF_vect) // Timer1 ISR
{
15a: 1f 92 push r1
15c: 0f 92 push r0
15e: 0f b6 in r0, 0x3f ; 63
160: 0f 92 push r0
162: 11 24 eor r1, r1
164: 8f 93 push r24
166: 9f 93 push r25
//counter++;
TCNT1 = 63974;
168: 86 ee ldi r24, 0xE6 ; 230
16a: 99 ef ldi r25, 0xF9 ; 249
16c: 9d bd out 0x2d, r25 ; 45
16e: 8c bd out 0x2c, r24 ; 44
}
170: 9f 91 pop r25
172: 8f 91 pop r24
174: 0f 90 pop r0
176: 0f be out 0x3f, r0 ; 63
178: 0f 90 pop r0
17a: 1f 90 pop r1
17c: 18 95 reti
0000017e <lcd_write_text>:
}
}
}
void lcd_write_text(int row, int col, uint8_t text[16])
{
15a: ef 92 push r14
15c: ff 92 push r15
15e: 0f 93 push r16
160: 1f 93 push r17
162: cf 93 push r28
164: 7c 01 movw r14, r24
17e: ef 92 push r14
180: ff 92 push r15
182: 0f 93 push r16
184: 1f 93 push r17
186: cf 93 push r28
188: 7c 01 movw r14, r24
switch(row){
166: 89 2b or r24, r25
168: 29 f0 breq .+10 ; 0x174 <lcd_write_text+0x1a>
16a: 81 e0 ldi r24, 0x01 ; 1
16c: e8 16 cp r14, r24
16e: f1 04 cpc r15, r1
170: 31 f0 breq .+12 ; 0x17e <lcd_write_text+0x24>
172: 0a c0 rjmp .+20 ; 0x188 <lcd_write_text+0x2e>
18a: 89 2b or r24, r25
18c: 29 f0 breq .+10 ; 0x198 <lcd_write_text+0x1a>
18e: 81 e0 ldi r24, 0x01 ; 1
190: e8 16 cp r14, r24
192: f1 04 cpc r15, r1
194: 31 f0 breq .+12 ; 0x1a2 <lcd_write_text+0x24>
196: 0a c0 rjmp .+20 ; 0x1ac <lcd_write_text+0x2e>
case 0:
row = line1;
174: 68 94 set
176: ee 24 eor r14, r14
178: e1 f8 bld r14, 1
17a: f1 2c mov r15, r1
17c: 05 c0 rjmp .+10 ; 0x188 <lcd_write_text+0x2e>
198: 68 94 set
19a: ee 24 eor r14, r14
19c: e1 f8 bld r14, 1
19e: f1 2c mov r15, r1
1a0: 05 c0 rjmp .+10 ; 0x1ac <lcd_write_text+0x2e>
break;
case 1:
row = line2;
17e: 0f 2e mov r0, r31
180: f3 e0 ldi r31, 0x03 ; 3
182: ef 2e mov r14, r31
184: f1 2c mov r15, r1
186: f0 2d mov r31, r0
1a2: 0f 2e mov r0, r31
1a4: f3 e0 ldi r31, 0x03 ; 3
1a6: ef 2e mov r14, r31
1a8: f1 2c mov r15, r1
1aa: f0 2d mov r31, r0
1ac: 04 2f mov r16, r20
1ae: 15 2f mov r17, r21
1b0: c0 e0 ldi r28, 0x00 ; 0
break;
}
int i=0;
while(text[i] != 0x5F){
188: fa 01 movw r30, r20
18a: 60 81 ld r22, Z
18c: 6f 35 cpi r22, 0x5F ; 95
18e: 69 f0 breq .+26 ; 0x1aa <lcd_write_text+0x50>
190: 8a 01 movw r16, r20
192: 0f 5f subi r16, 0xFF ; 255
194: 1f 4f sbci r17, 0xFF ; 255
196: c0 e0 ldi r28, 0x00 ; 0
for(int i=0;i<=15;i++){
if(text[i] != 0x5F){
1b2: f8 01 movw r30, r16
1b4: 61 91 ld r22, Z+
1b6: 8f 01 movw r16, r30
1b8: 6f 35 cpi r22, 0x5F ; 95
1ba: 19 f0 breq .+6 ; 0x1c2 <lcd_write_text+0x44>
lcd_write(row, text[i], 0+i);
198: 4c 2f mov r20, r28
19a: 8e 2d mov r24, r14
19c: 67 df rcall .-306 ; 0x6c <lcd_write>
1bc: 4c 2f mov r20, r28
1be: 8e 2d mov r24, r14
1c0: 55 df rcall .-342 ; 0x6c <lcd_write>
1c2: cf 5f subi r28, 0xFF ; 255
break;
case 1:
row = line2;
break;
}
int i=0;
while(text[i] != 0x5F){
19e: f8 01 movw r30, r16
1a0: 61 91 ld r22, Z+
1a2: 8f 01 movw r16, r30
1a4: cf 5f subi r28, 0xFF ; 255
1a6: 6f 35 cpi r22, 0x5F ; 95
1a8: b9 f7 brne .-18 ; 0x198 <lcd_write_text+0x3e>
for(int i=0;i<=15;i++){
1c4: c0 31 cpi r28, 0x10 ; 16
1c6: a9 f7 brne .-22 ; 0x1b2 <lcd_write_text+0x34>
if(text[i] != 0x5F){
lcd_write(row, text[i], 0+i);
i++;
}
}
}
1aa: cf 91 pop r28
1ac: 1f 91 pop r17
1ae: 0f 91 pop r16
1b0: ff 90 pop r15
1b2: ef 90 pop r14
1b4: 08 95 ret
1c8: cf 91 pop r28
1ca: 1f 91 pop r17
1cc: 0f 91 pop r16
1ce: ff 90 pop r15
1d0: ef 90 pop r14
1d2: 08 95 ret
000001b6 <main>:
000001d4 <button_clicked>:
uint8_t flags;
int button_clicked(int button)
{
if(((PIND & 0x03) == button+1) != ((flags & (1<<button))>0)){
1d4: 20 b3 in r18, 0x10 ; 16
1d6: bc 01 movw r22, r24
1d8: 6f 5f subi r22, 0xFF ; 255
1da: 7f 4f sbci r23, 0xFF ; 255
1dc: 40 91 77 00 lds r20, 0x0077 ; 0x800077 <flags>
1e0: e1 e0 ldi r30, 0x01 ; 1
1e2: f0 e0 ldi r31, 0x00 ; 0
1e4: df 01 movw r26, r30
1e6: 02 c0 rjmp .+4 ; 0x1ec <button_clicked+0x18>
1e8: aa 0f add r26, r26
1ea: bb 1f adc r27, r27
1ec: 8a 95 dec r24
1ee: e2 f7 brpl .-8 ; 0x1e8 <button_clicked+0x14>
1f0: cd 01 movw r24, r26
1f2: 23 70 andi r18, 0x03 ; 3
1f4: 30 e0 ldi r19, 0x00 ; 0
1f6: 51 e0 ldi r21, 0x01 ; 1
1f8: 26 17 cp r18, r22
1fa: 37 07 cpc r19, r23
1fc: 09 f0 breq .+2 ; 0x200 <button_clicked+0x2c>
1fe: 50 e0 ldi r21, 0x00 ; 0
200: 24 2f mov r18, r20
202: 30 e0 ldi r19, 0x00 ; 0
204: 28 23 and r18, r24
206: 39 23 and r19, r25
208: e1 e0 ldi r30, 0x01 ; 1
20a: 12 16 cp r1, r18
20c: 13 06 cpc r1, r19
20e: 0c f0 brlt .+2 ; 0x212 <button_clicked+0x3e>
210: e0 e0 ldi r30, 0x00 ; 0
212: 5e 17 cp r21, r30
214: 99 f0 breq .+38 ; 0x23c <button_clicked+0x68>
//if the pin is not equal to the stored state -> was pressed or released
//check is the button has been pressed or released
if((PIND & 0x03) == button+1){
216: 20 b3 in r18, 0x10 ; 16
218: 23 70 andi r18, 0x03 ; 3
21a: 30 e0 ldi r19, 0x00 ; 0
21c: 62 17 cp r22, r18
21e: 73 07 cpc r23, r19
220: 31 f4 brne .+12 ; 0x22e <button_clicked+0x5a>
//button is high -> pressed
flags |= (1<<button);
222: 84 2b or r24, r20
224: 80 93 77 00 sts 0x0077, r24 ; 0x800077 <flags>
return(1);
228: 81 e0 ldi r24, 0x01 ; 1
22a: 90 e0 ldi r25, 0x00 ; 0
22c: 08 95 ret
}
else{
//button is low -> released
flags &= ~(1<<button);
22e: 80 95 com r24
230: 48 23 and r20, r24
232: 40 93 77 00 sts 0x0077, r20 ; 0x800077 <flags>
return(0);
236: 80 e0 ldi r24, 0x00 ; 0
238: 90 e0 ldi r25, 0x00 ; 0
23a: 08 95 ret
}
}
return(0);
23c: 80 e0 ldi r24, 0x00 ; 0
23e: 90 e0 ldi r25, 0x00 ; 0
}
240: 08 95 ret
00000242 <main>:
TCNT1 = 63974;
}
int main(void)
{
DDRD = 0x00;
1b6: 11 ba out 0x11, r1 ; 17
flags &= ~(1<<butt1);
}
}
242: 11 ba out 0x11, r1 ; 17
TCNT1 = 63974; // for 1 sec at 16 MHz
244: 86 ee ldi r24, 0xE6 ; 230
246: 99 ef ldi r25, 0xF9 ; 249
248: 9d bd out 0x2d, r25 ; 45
24a: 8c bd out 0x2c, r24 ; 44
TCCR1A = 0x00;
24c: 1f bc out 0x2f, r1 ; 47
TCCR1B = (1<<CS10) | (1<<CS12);; // Timer mode with 1024 prescaler
24e: 85 e0 ldi r24, 0x05 ; 5
250: 8e bd out 0x2e, r24 ; 46
TIMSK = (1 << TOIE1) ; // Enable timer1 overflow interrupt(TOIE1)
252: 80 e8 ldi r24, 0x80 ; 128
254: 89 bf out 0x39, r24 ; 57
sei(); // Enable global interrupts by setting global interrupt enable bit in SREG
256: 78 94 sei
// flags &= ~(1<<butt1);
// }
// }
t1[0] = counter + 48;
1b8: c2 e7 ldi r28, 0x72 ; 114
1ba: d0 e0 ldi r29, 0x00 ; 0
258: c2 e7 ldi r28, 0x72 ; 114
25a: d0 e0 ldi r29, 0x00 ; 0
/* Replace with your application code */
while (1)
{
clock_state = clock_new_state;
1bc: 80 91 74 00 lds r24, 0x0074 ; 0x800074 <clock_new_state>
25c: 80 91 74 00 lds r24, 0x0074 ; 0x800074 <clock_new_state>
switch(clock_state){
1c0: 88 23 and r24, r24
1c2: 19 f0 breq .+6 ; 0x1ca <main+0x14>
1c4: 81 30 cpi r24, 0x01 ; 1
1c6: 51 f0 breq .+20 ; 0x1dc <main+0x26>
1c8: fb cf rjmp .-10 ; 0x1c0 <main+0xa>
1ca: 10 92 75 00 sts 0x0075, r1 ; 0x800075 <clock_state>
260: 88 23 and r24, r24
262: 19 f0 breq .+6 ; 0x26a <main+0x28>
264: 81 30 cpi r24, 0x01 ; 1
266: 51 f0 breq .+20 ; 0x27c <main+0x3a>
268: fb cf rjmp .-10 ; 0x260 <main+0x1e>
26a: 10 92 75 00 sts 0x0075, r1 ; 0x800075 <clock_state>
case CLOCK_INIT:
//do some init stuff...
lcd_init(); //I know, it's just c but I don't care
1ce: 8d df rcall .-230 ; 0xea <lcd_init>
26e: 3d df rcall .-390 ; 0xea <lcd_init>
lcd_instruct(lcd_DISPLAY_CLEAR);
1d0: 81 e0 ldi r24, 0x01 ; 1
1d2: 86 df rcall .-244 ; 0xe0 <lcd_instruct>
270: 81 e0 ldi r24, 0x01 ; 1
272: 36 df rcall .-404 ; 0xe0 <lcd_instruct>
//INIT done -> change to IDLE
clock_new_state = CLOCK_IDLE;
1d4: 81 e0 ldi r24, 0x01 ; 1
1d6: 80 93 74 00 sts 0x0074, r24 ; 0x800074 <clock_new_state>
274: 81 e0 ldi r24, 0x01 ; 1
276: 80 93 74 00 sts 0x0074, r24 ; 0x800074 <clock_new_state>
break;
1da: f0 cf rjmp .-32 ; 0x1bc <main+0x6>
1dc: 81 e0 ldi r24, 0x01 ; 1
1de: 80 93 75 00 sts 0x0075, r24 ; 0x800075 <clock_state>
27a: f0 cf rjmp .-32 ; 0x25c <main+0x1a>
27c: 81 e0 ldi r24, 0x01 ; 1
27e: 80 93 75 00 sts 0x0075, r24 ; 0x800075 <clock_state>
case CLOCK_IDLE:
//IDLE MODE
//print the IDLE Screen
lcd_write_text(0,0,t1);
1e2: 40 e6 ldi r20, 0x60 ; 96
1e4: 50 e0 ldi r21, 0x00 ; 0
1e6: 60 e0 ldi r22, 0x00 ; 0
1e8: 70 e0 ldi r23, 0x00 ; 0
1ea: 80 e0 ldi r24, 0x00 ; 0
1ec: 90 e0 ldi r25, 0x00 ; 0
1ee: b5 df rcall .-150 ; 0x15a <lcd_write_text>
282: 40 e6 ldi r20, 0x60 ; 96
284: 50 e0 ldi r21, 0x00 ; 0
286: 60 e0 ldi r22, 0x00 ; 0
288: 70 e0 ldi r23, 0x00 ; 0
28a: 80 e0 ldi r24, 0x00 ; 0
28c: 90 e0 ldi r25, 0x00 ; 0
28e: 77 df rcall .-274 ; 0x17e <lcd_write_text>
if(((PIND & 0x03) == 3) != (flags & 1<<butt1)){
1f0: 90 b3 in r25, 0x10 ; 16
1f2: 80 91 77 00 lds r24, 0x0077 ; 0x800077 <flags>
1f6: 93 70 andi r25, 0x03 ; 3
1f8: 21 e0 ldi r18, 0x01 ; 1
1fa: 93 30 cpi r25, 0x03 ; 3
1fc: 09 f0 breq .+2 ; 0x200 <main+0x4a>
1fe: 20 e0 ldi r18, 0x00 ; 0
200: 98 2f mov r25, r24
202: 91 70 andi r25, 0x01 ; 1
204: 29 17 cp r18, r25
206: a1 f0 breq .+40 ; 0x230 <main+0x7a>
if((PIND & 0x03) == 3){
208: 90 b3 in r25, 0x10 ; 16
20a: 93 70 andi r25, 0x03 ; 3
20c: 93 30 cpi r25, 0x03 ; 3
20e: 69 f4 brne .+26 ; 0x22a <main+0x74>
flags |= 1<<butt1;
210: 81 60 ori r24, 0x01 ; 1
212: 80 93 77 00 sts 0x0077, r24 ; 0x800077 <flags>
if(button_clicked(butt1)){
290: 80 e0 ldi r24, 0x00 ; 0
292: 90 e0 ldi r25, 0x00 ; 0
294: 9f df rcall .-194 ; 0x1d4 <button_clicked>
296: 89 2b or r24, r25
298: 51 f0 breq .+20 ; 0x2ae <main+0x6c>
counter++;
216: 80 91 72 00 lds r24, 0x0072 ; 0x800072 <__data_end>
21a: 90 91 73 00 lds r25, 0x0073 ; 0x800073 <__data_end+0x1>
21e: 01 96 adiw r24, 0x01 ; 1
220: 90 93 73 00 sts 0x0073, r25 ; 0x800073 <__data_end+0x1>
224: 80 93 72 00 sts 0x0072, r24 ; 0x800072 <__data_end>
228: 03 c0 rjmp .+6 ; 0x230 <main+0x7a>
}
else{
flags &= ~(1<<butt1);
22a: 8e 7f andi r24, 0xFE ; 254
22c: 80 93 77 00 sts 0x0077, r24 ; 0x800077 <flags>
29a: 80 91 72 00 lds r24, 0x0072 ; 0x800072 <__data_end>
29e: 90 91 73 00 lds r25, 0x0073 ; 0x800073 <__data_end+0x1>
2a2: 01 96 adiw r24, 0x01 ; 1
2a4: 90 93 73 00 sts 0x0073, r25 ; 0x800073 <__data_end+0x1>
2a8: 80 93 72 00 sts 0x0072, r24 ; 0x800072 <__data_end>
2ac: 1d c0 rjmp .+58 ; 0x2e8 <main+0xa6>
}
else if(button_clicked(butt2)){
2ae: 81 e0 ldi r24, 0x01 ; 1
2b0: 90 e0 ldi r25, 0x00 ; 0
2b2: 90 df rcall .-224 ; 0x1d4 <button_clicked>
2b4: 89 2b or r24, r25
2b6: 51 f0 breq .+20 ; 0x2cc <main+0x8a>
counter += 2;
2b8: 80 91 72 00 lds r24, 0x0072 ; 0x800072 <__data_end>
2bc: 90 91 73 00 lds r25, 0x0073 ; 0x800073 <__data_end+0x1>
2c0: 02 96 adiw r24, 0x02 ; 2
2c2: 90 93 73 00 sts 0x0073, r25 ; 0x800073 <__data_end+0x1>
2c6: 80 93 72 00 sts 0x0072, r24 ; 0x800072 <__data_end>
2ca: 0e c0 rjmp .+28 ; 0x2e8 <main+0xa6>
}
else if(button_clicked(butt3)){
2cc: 82 e0 ldi r24, 0x02 ; 2
2ce: 90 e0 ldi r25, 0x00 ; 0
2d0: 81 df rcall .-254 ; 0x1d4 <button_clicked>
2d2: 89 2b or r24, r25
2d4: 49 f0 breq .+18 ; 0x2e8 <main+0xa6>
counter += 3;
2d6: 80 91 72 00 lds r24, 0x0072 ; 0x800072 <__data_end>
2da: 90 91 73 00 lds r25, 0x0073 ; 0x800073 <__data_end+0x1>
2de: 03 96 adiw r24, 0x03 ; 3
2e0: 90 93 73 00 sts 0x0073, r25 ; 0x800073 <__data_end+0x1>
2e4: 80 93 72 00 sts 0x0072, r24 ; 0x800072 <__data_end>
// flags &= ~(1<<butt1);
// }
// }
t1[0] = counter + 48;
230: 88 81 ld r24, Y
232: 80 5d subi r24, 0xD0 ; 208
234: 80 93 60 00 sts 0x0060, r24 ; 0x800060 <__data_start>
2e8: 88 81 ld r24, Y
2ea: 80 5d subi r24, 0xD0 ; 208
2ec: 80 93 60 00 sts 0x0060, r24 ; 0x800060 <__data_start>
break;
238: c1 cf rjmp .-126 ; 0x1bc <main+0x6>
2f0: b5 cf rjmp .-150 ; 0x25c <main+0x1a>
0000023a <_exit>:
23a: f8 94 cli
000002f2 <_exit>:
2f2: f8 94 cli
0000023c <__stop_program>:
23c: ff cf rjmp .-2 ; 0x23c <__stop_program>
000002f4 <__stop_program>:
2f4: ff cf rjmp .-2 ; 0x2f4 <__stop_program>

View file

@ -203,7 +203,7 @@ END GROUP
.rela.plt
*(.rela.plt)
.text 0x00000000 0x23e
.text 0x00000000 0x2f6
*(.vectors)
.vectors 0x00000000 0x2a C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.172/gcc/dev/attiny2313a/avr25/tiny-stack/crtattiny2313a.o
0x00000000 __vector_default
@ -272,7 +272,6 @@ END GROUP
0x0000005c __vector_17
0x0000005c __vector_19
0x0000005c __vector_7
0x0000005c __vector_5
0x0000005c __vector_4
0x0000005c __vector_9
0x0000005c __vector_2
@ -299,16 +298,22 @@ END GROUP
.text.wait_100us
0x00000128 0x32 lcd_wait.o
0x00000128 wait_100us
.text.__vector_5
0x0000015a 0x24 main.o
0x0000015a __vector_5
.text.lcd_write_text
0x0000015a 0x5c main.o
0x0000015a lcd_write_text
.text.main 0x000001b6 0x84 main.o
0x000001b6 main
0x0000023a . = ALIGN (0x2)
0x0000017e 0x56 main.o
0x0000017e lcd_write_text
.text.button_clicked
0x000001d4 0x6e main.o
0x000001d4 button_clicked
.text.main 0x00000242 0xb0 main.o
0x00000242 main
0x000002f2 . = ALIGN (0x2)
*(.fini9)
.fini9 0x0000023a 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr25/tiny-stack\libgcc.a(_exit.o)
0x0000023a _exit
0x0000023a exit
.fini9 0x000002f2 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr25/tiny-stack\libgcc.a(_exit.o)
0x000002f2 _exit
0x000002f2 exit
*(.fini9)
*(.fini8)
*(.fini8)
@ -327,11 +332,11 @@ END GROUP
*(.fini1)
*(.fini1)
*(.fini0)
.fini0 0x0000023a 0x4 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr25/tiny-stack\libgcc.a(_exit.o)
.fini0 0x000002f2 0x4 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr25/tiny-stack\libgcc.a(_exit.o)
*(.fini0)
0x0000023e _etext = .
0x000002f6 _etext = .
.data 0x00800060 0x12 load address 0x0000023e
.data 0x00800060 0x12 load address 0x000002f6
0x00800060 PROVIDE (__data_start, .)
*(.data)
*(.data*)
@ -363,8 +368,8 @@ END GROUP
0x00800076 clock_old_state
0x00800077 flags
0x00800078 PROVIDE (__bss_end, .)
0x0000023e __data_load_start = LOADADDR (.data)
0x00000250 __data_load_end = (__data_load_start + SIZEOF (.data))
0x000002f6 __data_load_start = LOADADDR (.data)
0x00000308 __data_load_end = (__data_load_start + SIZEOF (.data))
.noinit 0x00800078 0x0
[!provide] PROVIDE (__noinit_start, .)
@ -437,60 +442,60 @@ END GROUP
.debug_sfnames
*(.debug_sfnames)
.debug_aranges 0x00000000 0x90
.debug_aranges 0x00000000 0xa0
*(.debug_aranges)
.debug_aranges
0x00000000 0x48 lcd4.o
.debug_aranges
0x00000048 0x20 lcd_wait.o
.debug_aranges
0x00000068 0x28 main.o
0x00000068 0x38 main.o
.debug_pubnames
*(.debug_pubnames)
.debug_info 0x00000000 0xa9b
.debug_info 0x00000000 0xb59
*(.debug_info .gnu.linkonce.wi.*)
.debug_info 0x00000000 0x456 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.172/gcc/dev/attiny2313a/avr25/tiny-stack/crtattiny2313a.o
.debug_info 0x00000456 0x31d lcd4.o
.debug_info 0x00000773 0xa3 lcd_wait.o
.debug_info 0x00000816 0x285 main.o
.debug_info 0x00000816 0x343 main.o
.debug_abbrev 0x00000000 0x6f0
.debug_abbrev 0x00000000 0x738
*(.debug_abbrev)
.debug_abbrev 0x00000000 0x41b C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.172/gcc/dev/attiny2313a/avr25/tiny-stack/crtattiny2313a.o
.debug_abbrev 0x0000041b 0xfe lcd4.o
.debug_abbrev 0x00000519 0x72 lcd_wait.o
.debug_abbrev 0x0000058b 0x165 main.o
.debug_abbrev 0x0000058b 0x1ad main.o
.debug_line 0x00000000 0x59a
.debug_line 0x00000000 0x61f
*(.debug_line .debug_line.* .debug_line_end)
.debug_line 0x00000000 0x10c C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.172/gcc/dev/attiny2313a/avr25/tiny-stack/crtattiny2313a.o
.debug_line 0x0000010c 0x291 lcd4.o
.debug_line 0x0000039d 0xbd lcd_wait.o
.debug_line 0x0000045a 0x140 main.o
.debug_line 0x0000045a 0x1c5 main.o
.debug_frame 0x00000000 0x120
.debug_frame 0x00000000 0x154
*(.debug_frame)
.debug_frame 0x00000000 0x9c lcd4.o
.debug_frame 0x0000009c 0x34 lcd_wait.o
.debug_frame 0x000000d0 0x50 main.o
.debug_frame 0x000000d0 0x84 main.o
.debug_str 0x00000000 0x446
.debug_str 0x00000000 0x470
*(.debug_str)
.debug_str 0x00000000 0x17b C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.172/gcc/dev/attiny2313a/avr25/tiny-stack/crtattiny2313a.o
.debug_str 0x0000017b 0x1c0 lcd4.o
0x1fd (size before relaxing)
.debug_str 0x0000033b 0x10 lcd_wait.o
0x166 (size before relaxing)
.debug_str 0x0000034b 0xfb main.o
0x2a9 (size before relaxing)
.debug_str 0x0000034b 0x125 main.o
0x2d3 (size before relaxing)
.debug_loc 0x00000000 0x3bb
.debug_loc 0x00000000 0x428
*(.debug_loc)
.debug_loc 0x00000000 0x244 lcd4.o
.debug_loc 0x00000244 0x48 lcd_wait.o
.debug_loc 0x0000028c 0x12f main.o
.debug_loc 0x0000028c 0x19c main.o
.debug_macinfo
*(.debug_macinfo)
@ -510,11 +515,11 @@ END GROUP
.debug_pubtypes
*(.debug_pubtypes)
.debug_ranges 0x00000000 0x78
.debug_ranges 0x00000000 0x88
*(.debug_ranges)
.debug_ranges 0x00000000 0x38 lcd4.o
.debug_ranges 0x00000038 0x10 lcd_wait.o
.debug_ranges 0x00000048 0x30 main.o
.debug_ranges 0x00000048 0x40 main.o
.debug_macro
*(.debug_macro)

View file

@ -1,10 +1,10 @@
S01A0000417454696E795F616C61726D5F636C6F636B2E73726563DA
S113000014C02CC02BC02AC029C028C027C026C0B9
S113000014C02CC02BC02AC029C0A7C027C026C03A
S113001025C024C023C022C021C020C01FC01EC0D0
S11300201DC01CC01BC01AC019C011241FBECFEDB7
S1130030CDBF10E0A0E6B0E0EEE3F2E002C0059030
S1130030CDBF10E0A0E6B0E0E6EFF2E002C005902C
S11300400D92A237B107D9F720E0A2E7B0E001C0D2
S11300501D92A837B207E1F7AED0EFC0D1CFCF934E
S11300501D92A837B207E1F7F4D04BC1D1CFCF93AB
S1130060C2E362D0C150E9F7CF910895CF93C62F70
S1130070843038F4823048F4882371F0813049F0B8
S11300800CC0843051F4939808C04F73833009F442
@ -20,21 +20,33 @@ S1130110E7DF87B3807F87BB8CE0E2DF86E0E0DF48
S113012082E0DEDF9CDF0895CF93DF931F92CDB78B
S1130130DD2784E4898389819FEF980F998388233D
S113014041F08981898189819FEF980F9983811179
S1130150F8CF0F90DF91CF910895EF92FF920F9314
S11301601F93CF937C01892B29F081E0E816F104D9
S113017031F00AC06894EE24E1F8F12C05C00F2E8A
S1130180F3E0EF2EF12CF02DFA0160816F3569F068
S11301908A010F5F1F4FC0E04C2F8E2D67DFF801DF
S11301A061918F01CF5F6F35B9F7CF911F910F9197
S11301B0FF90EF90089511BAC2E7D0E080917400E7
S11301C0882319F0813051F0FBCF109275008DDF38
S11301D081E086DF81E080937400F0CF81E080933A
S11301E0750040E650E060E070E080E090E0B5DF4C
S11301F090B380917700937021E0933009F020E070
S1130200982F91702917A1F090B39370933069F4EB
S113021081608093770080917200909173000196C1
S1130220909373008093720003C08E7F8093770055
S11102308881805D80936000C1CFF894FFCF79
S113023E2048616C6C6F5F5F5F5F5F5F5F5F5F5FE6
S105024E5F004B
S1130150F8CF0F90DF91CF9108951F920F920FB6B1
S11301600F9211248F939F9386EE99EF9DBD8CBDC2
S11301709F918F910F900FBE0F901F901895EF9243
S1130180FF920F931F93CF937C01892B29F081E079
S1130190E816F10431F00AC06894EE24E1F8F12C79
S11301A005C00F2EF3E0EF2EF12CF02D042F152FA8
S11301B0C0E0F80161918F016F3519F04C2F8E2D3D
S11301C055DFCF5FC031A9F7CF911F910F91FF90F9
S11301D0EF90089520B3BC016F5F7F4F409177008B
S11301E0E1E0F0E0DF0102C0AA0FBB1F8A95E2F74D
S11301F0CD01237030E051E02617370709F050E0B5
S1130200242F30E028233923E1E0121613060CF0E2
S1130210E0E05E1799F020B3237030E062177307B3
S113022031F4842B8093770081E090E008958095E9
S113023048234093770080E090E0089580E090E0C8
S1130240089511BA86EE99EF9DBD8CBD1FBC85E063
S11302508EBD80E889BF7894C2E7D0E080917400B5
S1130260882319F0813051F0FBCF109275003DDFE7
S113027081E036DF81E080937400F0CF81E08093E9
S1130280750040E650E060E070E080E090E077DFE9
S113029080E090E09FDF892B51F080917200909173
S11302A07300019690937300809372001DC081E0E7
S11302B090E090DF892B51F080917200909173004F
S11302C0029690937300809372000EC082E090E0D7
S11302D081DF892B49F0809172009091730003961D
S11302E090937300809372008881805D8093600096
S10902F0B5CFF894FFCF26
S11302F62048616C6C6F5F5F5F5F5F5F5F5F5F5F2E
S10503065F0092
S9030000FC

View file

@ -10,6 +10,7 @@ main.d main.o: .././main.c \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\version.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\fuse.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\interrupt.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdlib.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stddef.h \
.././lcd4.h
@ -36,6 +37,8 @@ c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\interrupt.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdlib.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stddef.h:

Binary file not shown.

50
main.c
View file

@ -6,10 +6,13 @@
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include "lcd4.h"
#define butt1 0
#define butt2 1
#define butt3 2
typedef enum {CLOCK_INIT = 0, CLOCK_IDLE, CLOCK_ALARM, CLOCK_STOPWATCH_RUNNING, CLOCK_STOPWATCH_STOPPED, CLOCK_STOPWATCH_NOT_SET, CLOCK_USER_INPUT, CLOCK_SET_TIME} clock_state_e;
@ -22,10 +25,22 @@ int counter = 0;
uint8_t flags;
ISR (TIMER1_OVF_vect) // Timer1 ISR
{
//counter++;
TCNT1 = 63974;
}
int main(void)
{
DDRD = 0x00;
TCNT1 = 63974; // for 1 sec at 16 MHz
TCCR1A = 0x00;
TCCR1B = (1<<CS10) | (1<<CS12);; // Timer mode with 1024 prescaler
TIMSK = (1 << TOIE1) ; // Enable timer1 overflow interrupt(TOIE1)
sei(); // Enable global interrupts by setting global interrupt enable bit in SREG
/* Replace with your application code */
@ -49,15 +64,15 @@ int main(void)
lcd_write_text(0,0,t1);
if(((PIND & 0x03) == 3) != (flags & 1<<butt1)){
if((PIND & 0x03) == 3){
flags |= 1<<butt1;
if(button_clicked(butt1)){
counter++;
}
else{
flags &= ~(1<<butt1);
else if(button_clicked(butt2)){
counter += 2;
}
else if(button_clicked(butt3)){
counter += 3;
}
@ -78,10 +93,29 @@ void lcd_write_text(int row, int col, uint8_t text[16])
row = line2;
break;
}
int i=0;
while(text[i] != 0x5F){
for(int i=0;i<=15;i++){
if(text[i] != 0x5F){
lcd_write(row, text[i], 0+i);
i++;
}
}
}
int button_clicked(int button)
{
if(((PIND & 0x03) == button+1) != ((flags & (1<<button))>0)){
//if the pin is not equal to the stored state -> was pressed or released
//check is the button has been pressed or released
if((PIND & 0x03) == button+1){
//button is high -> pressed
flags |= (1<<button);
return(1);
}
else{
//button is low -> released
flags &= ~(1<<button);
return(0);
}
}
return(0);
}