This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmain.lss
executable file
·1417 lines (1306 loc) · 48.5 KB
/
main.lss
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
main.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000071a 00000000 00000000 00000094 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000002 00800060 0000071a 000007ae 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000009 00800062 00800062 000007b0 2**0
ALLOC
3 .debug_aranges 00000040 00000000 00000000 000007b0 2**0
CONTENTS, READONLY, DEBUGGING
4 .debug_pubnames 000000fa 00000000 00000000 000007f0 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_info 0000076b 00000000 00000000 000008ea 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_abbrev 000001ca 00000000 00000000 00001055 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_line 000006c8 00000000 00000000 0000121f 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_frame 000000a0 00000000 00000000 000018e8 2**2
CONTENTS, READONLY, DEBUGGING
9 .debug_str 00000152 00000000 00000000 00001988 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_loc 0000031f 00000000 00000000 00001ada 2**0
CONTENTS, READONLY, DEBUGGING
11 .debug_ranges 00000060 00000000 00000000 00001df9 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 10 c0 rjmp .+32 ; 0x22 <__ctors_end>
2: 2a c0 rjmp .+84 ; 0x58 <__bad_interrupt>
4: 29 c0 rjmp .+82 ; 0x58 <__bad_interrupt>
6: 28 c0 rjmp .+80 ; 0x58 <__bad_interrupt>
8: 27 c0 rjmp .+78 ; 0x58 <__bad_interrupt>
a: 26 c0 rjmp .+76 ; 0x58 <__bad_interrupt>
c: 25 c0 rjmp .+74 ; 0x58 <__bad_interrupt>
e: 24 c0 rjmp .+72 ; 0x58 <__bad_interrupt>
10: 23 c0 rjmp .+70 ; 0x58 <__bad_interrupt>
12: 22 c0 rjmp .+68 ; 0x58 <__bad_interrupt>
14: 21 c0 rjmp .+66 ; 0x58 <__bad_interrupt>
16: 20 c0 rjmp .+64 ; 0x58 <__bad_interrupt>
18: 1f c0 rjmp .+62 ; 0x58 <__bad_interrupt>
1a: 29 c0 rjmp .+82 ; 0x6e <__vector_13>
1c: 1d c0 rjmp .+58 ; 0x58 <__bad_interrupt>
1e: 1c c0 rjmp .+56 ; 0x58 <__bad_interrupt>
20: 1b c0 rjmp .+54 ; 0x58 <__bad_interrupt>
00000022 <__ctors_end>:
22: 11 24 eor r1, r1
24: 1f be out 0x3f, r1 ; 63
26: cf e5 ldi r28, 0x5F ; 95
28: d1 e0 ldi r29, 0x01 ; 1
2a: de bf out 0x3e, r29 ; 62
2c: cd bf out 0x3d, r28 ; 61
0000002e <__do_copy_data>:
2e: 10 e0 ldi r17, 0x00 ; 0
30: a0 e6 ldi r26, 0x60 ; 96
32: b0 e0 ldi r27, 0x00 ; 0
34: ea e1 ldi r30, 0x1A ; 26
36: f7 e0 ldi r31, 0x07 ; 7
38: 02 c0 rjmp .+4 ; 0x3e <.do_copy_data_start>
0000003a <.do_copy_data_loop>:
3a: 05 90 lpm r0, Z+
3c: 0d 92 st X+, r0
0000003e <.do_copy_data_start>:
3e: a2 36 cpi r26, 0x62 ; 98
40: b1 07 cpc r27, r17
42: d9 f7 brne .-10 ; 0x3a <.do_copy_data_loop>
00000044 <__do_clear_bss>:
44: 10 e0 ldi r17, 0x00 ; 0
46: a2 e6 ldi r26, 0x62 ; 98
48: b0 e0 ldi r27, 0x00 ; 0
4a: 01 c0 rjmp .+2 ; 0x4e <.do_clear_bss_start>
0000004c <.do_clear_bss_loop>:
4c: 1d 92 st X+, r1
0000004e <.do_clear_bss_start>:
4e: ab 36 cpi r26, 0x6B ; 107
50: b1 07 cpc r27, r17
52: e1 f7 brne .-8 ; 0x4c <.do_clear_bss_loop>
54: 42 d0 rcall .+132 ; 0xda <main>
56: 5f c3 rjmp .+1726 ; 0x716 <_exit>
00000058 <__bad_interrupt>:
58: d3 cf rjmp .-90 ; 0x0 <__vectors>
0000005a <delay_ms>:
milliseconds can be achieved.
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
5a: 2a ef ldi r18, 0xFA ; 250
5c: 30 e0 ldi r19, 0x00 ; 0
5e: 04 c0 rjmp .+8 ; 0x68 <delay_ms+0xe>
60: f9 01 movw r30, r18
62: 31 97 sbiw r30, 0x01 ; 1
64: f1 f7 brne .-4 ; 0x62 <delay_ms+0x8>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
66: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
68: 00 97 sbiw r24, 0x00 ; 0
6a: d1 f7 brne .-12 ; 0x60 <delay_ms+0x6>
_delay_ms(1);
ms--;
}
}
6c: 08 95 ret
0000006e <__vector_13>:
ISR(SIG_ADC) // ADC interrupt. Simply pulls the value and returns, letting the program process the data later.
{
6e: 1f 92 push r1
70: 0f 92 push r0
72: 0f b6 in r0, 0x3f ; 63
74: 0f 92 push r0
76: 11 24 eor r1, r1
78: 2f 93 push r18
7a: 3f 93 push r19
7c: 8f 93 push r24
7e: 9f 93 push r25
80: ef 93 push r30
82: ff 93 push r31
//PORTB ^= (1<<PB0);
if(adcExpected == 1)
84: 80 91 62 00 lds r24, 0x0062
88: 81 30 cpi r24, 0x01 ; 1
8a: 39 f4 brne .+14 ; 0x9a <__vector_13+0x2c>
result1 = ADC;
8c: 84 b1 in r24, 0x04 ; 4
8e: 95 b1 in r25, 0x05 ; 5
90: 90 93 68 00 sts 0x0068, r25
94: 80 93 67 00 sts 0x0067, r24
98: 0a c0 rjmp .+20 ; 0xae <__vector_13+0x40>
else if(adcExpected == 2)
9a: 80 91 62 00 lds r24, 0x0062
9e: 82 30 cpi r24, 0x02 ; 2
a0: 31 f4 brne .+12 ; 0xae <__vector_13+0x40>
result2 = ADC;
a2: 84 b1 in r24, 0x04 ; 4
a4: 95 b1 in r25, 0x05 ; 5
a6: 90 93 6a 00 sts 0x006A, r25
aa: 80 93 69 00 sts 0x0069, r24
adcExpected = 0;
ae: 10 92 62 00 sts 0x0062, r1
b2: 84 e6 ldi r24, 0x64 ; 100
b4: 90 e0 ldi r25, 0x00 ; 0
b6: 2a ef ldi r18, 0xFA ; 250
b8: 30 e0 ldi r19, 0x00 ; 0
ba: f9 01 movw r30, r18
bc: 31 97 sbiw r30, 0x01 ; 1
be: f1 f7 brne .-4 ; 0xbc <__vector_13+0x4e>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
c0: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
c2: d9 f7 brne .-10 ; 0xba <__vector_13+0x4c>
result2 = ADC;
adcExpected = 0;
delay_ms(100);
//PORTB ^= (1<<PB0);
}
c4: ff 91 pop r31
c6: ef 91 pop r30
c8: 9f 91 pop r25
ca: 8f 91 pop r24
cc: 3f 91 pop r19
ce: 2f 91 pop r18
d0: 0f 90 pop r0
d2: 0f be out 0x3f, r0 ; 63
d4: 0f 90 pop r0
d6: 1f 90 pop r1
d8: 18 95 reti
000000da <main>:
delay_ms(100);
PORTA ^= (1<<PA3);
}*/
int main(void)
{
da: ff 92 push r15
dc: 0f 93 push r16
de: 1f 93 push r17
e0: cf 93 push r28
e2: df 93 push r29
e4: 8a e0 ldi r24, 0x0A ; 10
e6: 90 e0 ldi r25, 0x00 ; 0
e8: 2a ef ldi r18, 0xFA ; 250
ea: 30 e0 ldi r19, 0x00 ; 0
ec: f9 01 movw r30, r18
ee: 31 97 sbiw r30, 0x01 ; 1
f0: f1 f7 brne .-4 ; 0xee <main+0x14>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
f2: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
f4: d9 f7 brne .-10 ; 0xec <main+0x12>
int main(void)
{
delay_ms(10); // Let the power stabilize.
cli(); // Disable interrupts.
f6: f8 94 cli
// Initialize the ADC.
// Note that an interrupt is generated when the ADC finishes.
// This interrupt is handled in main.c, not analog.c.
adcOn();
f8: 4a d1 rcall .+660 ; 0x38e <adcOn>
// Initialize the LEDs and relay, then run test patterns.
DDRA = (1<<PA2)|(1<<PA3); // Chg, fault.
fa: 8c e0 ldi r24, 0x0C ; 12
fc: 8a bb out 0x1a, r24 ; 26
DDRB = (1<<PB0)|(1<<PB2); // Pwr, relay.
fe: 85 e0 ldi r24, 0x05 ; 5
100: 87 bb out 0x17, r24 ; 23
PORTA |= (1<<PA2)|(1<<PA3);
102: 8b b3 in r24, 0x1b ; 27
104: 8c 60 ori r24, 0x0C ; 12
106: 8b bb out 0x1b, r24 ; 27
PORTB |= (1<<PB0);
108: c0 9a sbi 0x18, 0 ; 24
10a: 80 e9 ldi r24, 0x90 ; 144
10c: 91 e0 ldi r25, 0x01 ; 1
10e: 2a ef ldi r18, 0xFA ; 250
110: 30 e0 ldi r19, 0x00 ; 0
112: f9 01 movw r30, r18
114: 31 97 sbiw r30, 0x01 ; 1
116: f1 f7 brne .-4 ; 0x114 <main+0x3a>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
118: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
11a: d9 f7 brne .-10 ; 0x112 <main+0x38>
DDRB = (1<<PB0)|(1<<PB2); // Pwr, relay.
PORTA |= (1<<PA2)|(1<<PA3);
PORTB |= (1<<PB0);
delay_ms(400); // All 3 lights on.
PORTA &= ~((1<<PA2)|(1<<PA3));
11c: 8b b3 in r24, 0x1b ; 27
11e: 83 7f andi r24, 0xF3 ; 243
120: 8b bb out 0x1b, r24 ; 27
PORTB |= (1<<PB2);
122: c2 9a sbi 0x18, 2 ; 24
124: 88 ec ldi r24, 0xC8 ; 200
126: 90 e0 ldi r25, 0x00 ; 0
128: 2a ef ldi r18, 0xFA ; 250
12a: 30 e0 ldi r19, 0x00 ; 0
12c: f9 01 movw r30, r18
12e: 31 97 sbiw r30, 0x01 ; 1
130: f1 f7 brne .-4 ; 0x12e <main+0x54>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
132: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
134: d9 f7 brne .-10 ; 0x12c <main+0x52>
PORTB |= (1<<PB0);
delay_ms(400); // All 3 lights on.
PORTA &= ~((1<<PA2)|(1<<PA3));
PORTB |= (1<<PB2);
delay_ms(200); // Pwr on, relay closed.
PORTB &= ~(1<<PB2);
136: c2 98 cbi 0x18, 2 ; 24
138: 88 ec ldi r24, 0xC8 ; 200
13a: 90 e0 ldi r25, 0x00 ; 0
13c: 2a ef ldi r18, 0xFA ; 250
13e: 30 e0 ldi r19, 0x00 ; 0
140: f9 01 movw r30, r18
142: 31 97 sbiw r30, 0x01 ; 1
144: f1 f7 brne .-4 ; 0x142 <main+0x68>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
146: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
148: d9 f7 brne .-10 ; 0x140 <main+0x66>
PORTA &= ~((1<<PA2)|(1<<PA3));
PORTB |= (1<<PB2);
delay_ms(200); // Pwr on, relay closed.
PORTB &= ~(1<<PB2);
delay_ms(200); // Pwr on, relay open.
PORTB &= ~(1<<PB0);
14a: c0 98 cbi 0x18, 0 ; 24
PORTB |= (1<<PB2);
14c: c2 9a sbi 0x18, 2 ; 24
PORTA |= (1<<PA2);
14e: da 9a sbi 0x1b, 2 ; 27
150: 88 ec ldi r24, 0xC8 ; 200
152: 90 e0 ldi r25, 0x00 ; 0
154: 2a ef ldi r18, 0xFA ; 250
156: 30 e0 ldi r19, 0x00 ; 0
158: f9 01 movw r30, r18
15a: 31 97 sbiw r30, 0x01 ; 1
15c: f1 f7 brne .-4 ; 0x15a <main+0x80>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
15e: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
160: d9 f7 brne .-10 ; 0x158 <main+0x7e>
delay_ms(200); // Pwr on, relay open.
PORTB &= ~(1<<PB0);
PORTB |= (1<<PB2);
PORTA |= (1<<PA2);
delay_ms(200); // Chg on, relay closed.
PORTB &= ~(1<<PB2);
162: c2 98 cbi 0x18, 2 ; 24
164: 88 ec ldi r24, 0xC8 ; 200
166: 90 e0 ldi r25, 0x00 ; 0
168: 2a ef ldi r18, 0xFA ; 250
16a: 30 e0 ldi r19, 0x00 ; 0
16c: f9 01 movw r30, r18
16e: 31 97 sbiw r30, 0x01 ; 1
170: f1 f7 brne .-4 ; 0x16e <__stack+0xf>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
172: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
174: d9 f7 brne .-10 ; 0x16c <__stack+0xd>
PORTB |= (1<<PB2);
PORTA |= (1<<PA2);
delay_ms(200); // Chg on, relay closed.
PORTB &= ~(1<<PB2);
delay_ms(200); // Chg on, relay open.
PORTA &= ~(1<<PA2);
176: da 98 cbi 0x1b, 2 ; 27
PORTA |= (1<<PA3);
178: db 9a sbi 0x1b, 3 ; 27
PORTB |= (1<<PB2);
17a: c2 9a sbi 0x18, 2 ; 24
17c: 88 ec ldi r24, 0xC8 ; 200
17e: 90 e0 ldi r25, 0x00 ; 0
180: 2a ef ldi r18, 0xFA ; 250
182: 30 e0 ldi r19, 0x00 ; 0
184: f9 01 movw r30, r18
186: 31 97 sbiw r30, 0x01 ; 1
188: f1 f7 brne .-4 ; 0x186 <__stack+0x27>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
18a: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
18c: d9 f7 brne .-10 ; 0x184 <__stack+0x25>
delay_ms(200); // Chg on, relay open.
PORTA &= ~(1<<PA2);
PORTA |= (1<<PA3);
PORTB |= (1<<PB2);
delay_ms(200); // Fault on, relay closed.
PORTB &= ~(1<<PB2);
18e: c2 98 cbi 0x18, 2 ; 24
190: 88 ec ldi r24, 0xC8 ; 200
192: 90 e0 ldi r25, 0x00 ; 0
194: 2a ef ldi r18, 0xFA ; 250
196: 30 e0 ldi r19, 0x00 ; 0
198: f9 01 movw r30, r18
19a: 31 97 sbiw r30, 0x01 ; 1
19c: f1 f7 brne .-4 ; 0x19a <__stack+0x3b>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
19e: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
1a0: d9 f7 brne .-10 ; 0x198 <__stack+0x39>
PORTA |= (1<<PA3);
PORTB |= (1<<PB2);
delay_ms(200); // Fault on, relay closed.
PORTB &= ~(1<<PB2);
delay_ms(200); // Fault on, relay open.
PORTA &= ~(1<<PA3); // Fault off.
1a2: db 98 cbi 0x1b, 3 ; 27
PORTB |= (1<<PB0); // Power on.
1a4: c0 9a sbi 0x18, 0 ; 24
//TCCR1B = (1<<CS12);
//TIMSK1 |= (1<<TOIE1); // Enable overflow interrupt.
// Enable interrupts.
sei();
1a6: 78 94 sei
1a8: 82 e3 ldi r24, 0x32 ; 50
1aa: 90 e0 ldi r25, 0x00 ; 0
1ac: 2a ef ldi r18, 0xFA ; 250
1ae: 30 e0 ldi r19, 0x00 ; 0
1b0: f9 01 movw r30, r18
1b2: 31 97 sbiw r30, 0x01 ; 1
1b4: f1 f7 brne .-4 ; 0x1b2 <__stack+0x53>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
1b6: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
1b8: d9 f7 brne .-10 ; 0x1b0 <__stack+0x51>
sei();
delay_ms(50);
// Get some initial reads.
adcExpected = 1;
1ba: 81 e0 ldi r24, 0x01 ; 1
1bc: 80 93 62 00 sts 0x0062, r24
startConvert(0);
1c0: 80 e0 ldi r24, 0x00 ; 0
1c2: 15 d1 rcall .+554 ; 0x3ee <startConvert>
while(adcExpected);
1c4: 80 91 62 00 lds r24, 0x0062
1c8: 88 23 and r24, r24
1ca: e1 f7 brne .-8 ; 0x1c4 <__stack+0x65>
adcExpected = 2;
1cc: 82 e0 ldi r24, 0x02 ; 2
1ce: 80 93 62 00 sts 0x0062, r24
startConvert(1);
1d2: 81 e0 ldi r24, 0x01 ; 1
1d4: 0c d1 rcall .+536 ; 0x3ee <startConvert>
while(adcExpected);
1d6: 80 91 62 00 lds r24, 0x0062
1da: 88 23 and r24, r24
1dc: e1 f7 brne .-8 ; 0x1d6 <__stack+0x77>
newData = 1;
1de: 81 e0 ldi r24, 0x01 ; 1
1e0: 80 93 63 00 sts 0x0063, r24
1e4: 82 e3 ldi r24, 0x32 ; 50
1e6: 90 e0 ldi r25, 0x00 ; 0
1e8: 2a ef ldi r18, 0xFA ; 250
1ea: 30 e0 ldi r19, 0x00 ; 0
1ec: f9 01 movw r30, r18
1ee: 31 97 sbiw r30, 0x01 ; 1
1f0: f1 f7 brne .-4 ; 0x1ee <__stack+0x8f>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
1f2: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
1f4: d9 f7 brne .-10 ; 0x1ec <__stack+0x8d>
sleep_cpu(); // And nappy time. Wake up only on power cycle / external reset.
}
}
else if(voltageOut < 100) // If there's less than 10v on the output, there's probably no battery attached.
{
faultBlink = 1;
1f6: 11 e0 ldi r17, 0x01 ; 1
1f8: ca ef ldi r28, 0xFA ; 250
1fa: d0 e0 ldi r29, 0x00 ; 0
goodCount = 0; // Reset the good count. If it was a false alarm (very possible), the next ADC run will
} // catch it and start up charging again. There's no good way to check charge while charging...
delay_ms(500); // Keep everything at a good pace and let the voltages stablize before doing more readings.
if(faultBlink) PORTA ^= (1<<PA3); // Fault LED toggle.
1fc: 88 e0 ldi r24, 0x08 ; 8
1fe: f8 2e mov r15, r24
// And run another round of ADC.
adcExpected = 1;
startConvert(0);
while(adcExpected);
adcExpected = 2;
200: 02 e0 ldi r16, 0x02 ; 2
while(1) // Main loop.
{
if(newData)
202: 80 91 63 00 lds r24, 0x0063
206: 88 23 and r24, r24
208: 09 f4 brne .+2 ; 0x20c <__stack+0xad>
20a: 91 c0 rjmp .+290 ; 0x32e <__stack+0x1cf>
{
// Get the actual voltage values.
voltageIn = analog2v1(result1);
20c: 80 91 67 00 lds r24, 0x0067
210: 90 91 68 00 lds r25, 0x0068
214: c6 d0 rcall .+396 ; 0x3a2 <analog2v1>
216: 80 93 60 00 sts 0x0060, r24
voltageOut = analog2v2(result2);
21a: 80 91 69 00 lds r24, 0x0069
21e: 90 91 6a 00 lds r25, 0x006A
222: d2 d0 rcall .+420 ; 0x3c8 <analog2v2>
224: 80 93 61 00 sts 0x0061, r24
faultBlink = 0; // If there's still a fault, we'll keep blinking.
228: 10 92 66 00 sts 0x0066, r1
if(voltageIn < 124) // If the input voltage is too low, we must stop consuming power.
22c: 80 91 60 00 lds r24, 0x0060
230: 8c 37 cpi r24, 0x7C ; 124
232: a0 f5 brcc .+104 ; 0x29c <__stack+0x13d>
{
PORTB &= ~(1<<PB2); // Turn off the relay.
234: c2 98 cbi 0x18, 2 ; 24
PORTA &= ~(1<<PA2); // Turn off the chg LED.
236: da 98 cbi 0x1b, 2 ; 27
238: 80 e1 ldi r24, 0x10 ; 16
23a: 97 e2 ldi r25, 0x27 ; 39
23c: fe 01 movw r30, r28
23e: 31 97 sbiw r30, 0x01 ; 1
240: f1 f7 brne .-4 ; 0x23e <__stack+0xdf>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
242: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
244: d9 f7 brne .-10 ; 0x23c <__stack+0xdd>
{
PORTB &= ~(1<<PB2); // Turn off the relay.
PORTA &= ~(1<<PA2); // Turn off the chg LED.
delay_ms(10000); // Wait 10 seconds, this may just be that car starting...
// Check voltageIn again.
adcExpected = 1;
246: 10 93 62 00 sts 0x0062, r17
startConvert(0);
24a: 80 e0 ldi r24, 0x00 ; 0
24c: d0 d0 rcall .+416 ; 0x3ee <startConvert>
while(adcExpected);
24e: 80 91 62 00 lds r24, 0x0062
252: 88 23 and r24, r24
254: e1 f7 brne .-8 ; 0x24e <__stack+0xef>
voltageIn = analog2v1(result1);
256: 80 91 67 00 lds r24, 0x0067
25a: 90 91 68 00 lds r25, 0x0068
25e: a1 d0 rcall .+322 ; 0x3a2 <analog2v1>
260: 80 93 60 00 sts 0x0060, r24
if(voltageIn < 124) // And if we're still low, go ahead and shut down.
264: 80 91 60 00 lds r24, 0x0060
268: 8c 37 cpi r24, 0x7C ; 124
26a: 08 f0 brcs .+2 ; 0x26e <__stack+0x10f>
26c: 56 c0 rjmp .+172 ; 0x31a <__stack+0x1bb>
{
PORTA |= (1<<PA3); // Fault LED on.
26e: db 9a sbi 0x1b, 3 ; 27
270: 88 ee ldi r24, 0xE8 ; 232
272: 93 e0 ldi r25, 0x03 ; 3
274: fe 01 movw r30, r28
276: 31 97 sbiw r30, 0x01 ; 1
278: f1 f7 brne .-4 ; 0x276 <__stack+0x117>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
27a: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
27c: d9 f7 brne .-10 ; 0x274 <__stack+0x115>
if(voltageIn < 124) // And if we're still low, go ahead and shut down.
{
PORTA |= (1<<PA3); // Fault LED on.
delay_ms(1000);
PORTA = 0;
27e: 1b ba out 0x1b, r1 ; 27
PORTB = 0;
280: 18 ba out 0x18, r1 ; 24
// Sleep mode...
cli(); // Disable interrupts.
282: f8 94 cli
adcOff(); // Shut down ADC.
284: 8a d0 rcall .+276 ; 0x39a <adcOff>
DDRA = 0; DDRB = 0; // Set all ports to hi-Z.
286: 1a ba out 0x1a, r1 ; 26
288: 17 ba out 0x17, r1 ; 23
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep level to practically off.
28a: 85 b7 in r24, 0x35 ; 53
28c: 87 7e andi r24, 0xE7 ; 231
28e: 80 61 ori r24, 0x10 ; 16
290: 85 bf out 0x35, r24 ; 53
sleep_enable(); // Duh.
292: 85 b7 in r24, 0x35 ; 53
294: 80 62 ori r24, 0x20 ; 32
296: 85 bf out 0x35, r24 ; 53
sleep_cpu(); // And nappy time. Wake up only on power cycle / external reset.
298: 88 95 sleep
29a: 3f c0 rjmp .+126 ; 0x31a <__stack+0x1bb>
}
}
else if(voltageOut < 100) // If there's less than 10v on the output, there's probably no battery attached.
29c: 80 91 61 00 lds r24, 0x0061
2a0: 84 36 cpi r24, 0x64 ; 100
2a2: 28 f4 brcc .+10 ; 0x2ae <__stack+0x14f>
{
faultBlink = 1;
2a4: 10 93 66 00 sts 0x0066, r17
PORTB &= ~(1<<PB2); // Turn off the relay.
2a8: c2 98 cbi 0x18, 2 ; 24
PORTA &= ~(1<<PA2); // Turn off the chg LED.
2aa: da 98 cbi 0x1b, 2 ; 27
2ac: 36 c0 rjmp .+108 ; 0x31a <__stack+0x1bb>
}
else if(abs(voltageIn - voltageOut) > 10) // If the voltage difference between in and out is greater then 1v, don't charge.
2ae: 80 91 60 00 lds r24, 0x0060
2b2: 90 91 61 00 lds r25, 0x0061
2b6: 28 2f mov r18, r24
2b8: 30 e0 ldi r19, 0x00 ; 0
2ba: 29 1b sub r18, r25
2bc: 31 09 sbc r19, r1
2be: 37 ff sbrs r19, 7
2c0: 03 c0 rjmp .+6 ; 0x2c8 <__stack+0x169>
2c2: 30 95 com r19
2c4: 21 95 neg r18
2c6: 3f 4f sbci r19, 0xFF ; 255
2c8: 2b 30 cpi r18, 0x0B ; 11
2ca: 31 05 cpc r19, r1
2cc: 44 f0 brlt .+16 ; 0x2de <__stack+0x17f>
{ // That's a recepie for blown traces.
PORTA |= (1<<PA3); // Fault light on.
2ce: db 9a sbi 0x1b, 3 ; 27
PORTB &= ~(1<<PB2); // Turn off the relay.
2d0: c2 98 cbi 0x18, 2 ; 24
PORTA &= ~(1<<PA2); // Turn off the chg LED.
2d2: da 98 cbi 0x1b, 2 ; 27
goodCount = 0;
2d4: 10 92 65 00 sts 0x0065, r1
2d8: 10 92 64 00 sts 0x0064, r1
2dc: 1e c0 rjmp .+60 ; 0x31a <__stack+0x1bb>
}
else if(voltageOut > 128) // If the battery has been sufficently charged, prepare to stop charging it.
2de: 80 91 61 00 lds r24, 0x0061
2e2: 81 38 cpi r24, 0x81 ; 129
2e4: 50 f0 brcs .+20 ; 0x2fa <__stack+0x19b>
{
goodCount++;
2e6: 80 91 64 00 lds r24, 0x0064
2ea: 90 91 65 00 lds r25, 0x0065
2ee: 01 96 adiw r24, 0x01 ; 1
2f0: 90 93 65 00 sts 0x0065, r25
2f4: 80 93 64 00 sts 0x0064, r24
2f8: 0e c0 rjmp .+28 ; 0x316 <__stack+0x1b7>
faultBlink = 0;
}
else if((voltageOut < 124) && (voltageIn > 124)) // If the battery needs charging and we have
2fa: 80 91 61 00 lds r24, 0x0061
2fe: 8c 37 cpi r24, 0x7C ; 124
300: 60 f4 brcc .+24 ; 0x31a <__stack+0x1bb>
302: 80 91 60 00 lds r24, 0x0060
306: 8d 37 cpi r24, 0x7D ; 125
308: 40 f0 brcs .+16 ; 0x31a <__stack+0x1bb>
{ // sufficent voltage to charge, begin charging.
PORTB |= (1<<PB2); // Turn on the relay.
30a: c2 9a sbi 0x18, 2 ; 24
PORTA |= (1<<PA2); // Turn on the chg LED.
30c: da 9a sbi 0x1b, 2 ; 27
goodCount = 0;
30e: 10 92 65 00 sts 0x0065, r1
312: 10 92 64 00 sts 0x0064, r1
faultBlink = 0;
316: 10 92 66 00 sts 0x0066, r1
}
if(voltageOut < 128) goodCount = 0; // Reset the good count if we get a too-low voltage.
31a: 80 91 61 00 lds r24, 0x0061
31e: 87 fd sbrc r24, 7
320: 04 c0 rjmp .+8 ; 0x32a <__stack+0x1cb>
322: 10 92 65 00 sts 0x0065, r1
326: 10 92 64 00 sts 0x0064, r1
newData = 0; // We're done processing the new data.
32a: 10 92 63 00 sts 0x0063, r1
}
if(goodCount > (120 * 5)) // If the battery reads good for over 5 minutes, disconnect it from the charge power.
32e: 80 91 64 00 lds r24, 0x0064
332: 90 91 65 00 lds r25, 0x0065
336: 89 55 subi r24, 0x59 ; 89
338: 92 40 sbci r25, 0x02 ; 2
33a: 30 f0 brcs .+12 ; 0x348 <__stack+0x1e9>
{
PORTB &= ~(1<<PB2); // Turn off the relay.
33c: c2 98 cbi 0x18, 2 ; 24
PORTA &= ~(1<<PA2); // Turn off the chg LED.
33e: da 98 cbi 0x1b, 2 ; 27
goodCount = 0; // Reset the good count. If it was a false alarm (very possible), the next ADC run will
340: 10 92 65 00 sts 0x0065, r1
344: 10 92 64 00 sts 0x0064, r1
348: 84 ef ldi r24, 0xF4 ; 244
34a: 91 e0 ldi r25, 0x01 ; 1
34c: fe 01 movw r30, r28
34e: 31 97 sbiw r30, 0x01 ; 1
350: f1 f7 brne .-4 ; 0x34e <__stack+0x1ef>
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
_delay_ms(1);
ms--;
352: 01 97 sbiw r24, 0x01 ; 1
void delay_ms(uint16_t ms)
{
// Apparently this makes the delay cheaper? (Yeah, I dunno either.)
while(ms){
354: d9 f7 brne .-10 ; 0x34c <__stack+0x1ed>
goodCount = 0; // Reset the good count. If it was a false alarm (very possible), the next ADC run will
} // catch it and start up charging again. There's no good way to check charge while charging...
delay_ms(500); // Keep everything at a good pace and let the voltages stablize before doing more readings.
if(faultBlink) PORTA ^= (1<<PA3); // Fault LED toggle.
356: 80 91 66 00 lds r24, 0x0066
35a: 88 23 and r24, r24
35c: 21 f0 breq .+8 ; 0x366 <__stack+0x207>
35e: 8b b3 in r24, 0x1b ; 27
360: 8f 25 eor r24, r15
362: 8b bb out 0x1b, r24 ; 27
364: 01 c0 rjmp .+2 ; 0x368 <__stack+0x209>
else PORTA &= ~(1<<PA3); // If we're not blinking, make sure it's off.
366: db 98 cbi 0x1b, 3 ; 27
// And run another round of ADC.
adcExpected = 1;
368: 10 93 62 00 sts 0x0062, r17
startConvert(0);
36c: 80 e0 ldi r24, 0x00 ; 0
36e: 3f d0 rcall .+126 ; 0x3ee <startConvert>
while(adcExpected);
370: 80 91 62 00 lds r24, 0x0062
374: 88 23 and r24, r24
376: e1 f7 brne .-8 ; 0x370 <__stack+0x211>
adcExpected = 2;
378: 00 93 62 00 sts 0x0062, r16
startConvert(1);
37c: 81 e0 ldi r24, 0x01 ; 1
37e: 37 d0 rcall .+110 ; 0x3ee <startConvert>
while(adcExpected);
380: 80 91 62 00 lds r24, 0x0062
384: 88 23 and r24, r24
386: e1 f7 brne .-8 ; 0x380 <__stack+0x221>
newData = 1;
388: 10 93 63 00 sts 0x0063, r17
38c: 3a cf rjmp .-396 ; 0x202 <__stack+0xa3>
0000038e <adcOn>:
void adcOn(void)
{
// Set up the ADC and enable the interrupt.
// Use Vcc as Vref.
ADMUX = 0x00;
38e: 17 b8 out 0x07, r1 ; 7
DIDR0 = (1<<ADC0D)|(1<<ADC1D); // Disable the digital circuitry on the ADC inputs.
390: 83 e0 ldi r24, 0x03 ; 3
392: 81 b9 out 0x01, r24 ; 1
// Enable the A/D Converter, set the prescaler div8 (125kHz), enable the interrupt.
ADCSRA=(1<<ADEN)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE);
394: 8b e8 ldi r24, 0x8B ; 139
396: 86 b9 out 0x06, r24 ; 6
}
398: 08 95 ret
0000039a <adcOff>:
void adcOff(void)
{
ADCSRA &= ~((1<<ADEN)|(1<<ADIE));
39a: 86 b1 in r24, 0x06 ; 6
39c: 87 77 andi r24, 0x77 ; 119
39e: 86 b9 out 0x06, r24 ; 6
// Shut off the ADC and disable the interrupt.
// This lowers the power consumption of the uC.
}
3a0: 08 95 ret
000003a2 <analog2v1>:
// convert adc reading to voltage (readout is multiplied by 10)
uint8_t analog2v1(uint16_t aval)
{
3a2: a0 e0 ldi r26, 0x00 ; 0
3a4: b0 e0 ldi r27, 0x00 ; 0
3a6: bc 01 movw r22, r24
3a8: cd 01 movw r24, r26
3aa: bc d0 rcall .+376 ; 0x524 <__floatunsisf>
3ac: 2d e5 ldi r18, 0x5D ; 93
3ae: 3c ed ldi r19, 0xDC ; 220
3b0: 46 e3 ldi r20, 0x36 ; 54
3b2: 5f e3 ldi r21, 0x3F ; 63
3b4: 45 d1 rcall .+650 ; 0x640 <__mulsf3>
3b6: 23 ea ldi r18, 0xA3 ; 163
3b8: 33 e2 ldi r19, 0x23 ; 35
3ba: 49 ec ldi r20, 0xC9 ; 201
3bc: 5f e3 ldi r21, 0x3F ; 63
3be: 22 d0 rcall .+68 ; 0x404 <__addsf3>
3c0: 85 d0 rcall .+266 ; 0x4cc <__fixunssfsi>
3c2: dc 01 movw r26, r24
3c4: cb 01 movw r24, r22
// 1024
//
//return (uint8_t)(((double)aval * 1.2) - 73.6); // These numbers were generated by calibrating against two known voltage reads.
return (uint8_t)(((double)aval * (double)0.7143) + (double)1.5714);
//return((uint8_t)r);
}
3c6: 08 95 ret
000003c8 <analog2v2>:
uint8_t analog2v2(uint16_t aval)
{
3c8: a0 e0 ldi r26, 0x00 ; 0
3ca: b0 e0 ldi r27, 0x00 ; 0
3cc: bc 01 movw r22, r24
3ce: cd 01 movw r24, r26
3d0: a9 d0 rcall .+338 ; 0x524 <__floatunsisf>
3d2: 2d e5 ldi r18, 0x5D ; 93
3d4: 3c ed ldi r19, 0xDC ; 220
3d6: 46 e3 ldi r20, 0x36 ; 54
3d8: 5f e3 ldi r21, 0x3F ; 63
3da: 32 d1 rcall .+612 ; 0x640 <__mulsf3>
3dc: 23 ea ldi r18, 0xA3 ; 163
3de: 33 e2 ldi r19, 0x23 ; 35
3e0: 49 ec ldi r20, 0xC9 ; 201
3e2: 5f e3 ldi r21, 0x3F ; 63
3e4: 0f d0 rcall .+30 ; 0x404 <__addsf3>
3e6: 72 d0 rcall .+228 ; 0x4cc <__fixunssfsi>
3e8: dc 01 movw r26, r24
3ea: cb 01 movw r24, r22
return (uint8_t)(((double)aval * (double)0.7143) + (double)1.5714); // These numbers were generated by calibrating against two known voltage reads.
}
3ec: 08 95 ret
000003ee <startConvert>:
// Start the ADC conversion. Results are handled by an interrupt in main.c.
void startConvert(uint8_t channel)
{
// Set channel
ADMUX &= ~0x1F; // Clear out existing channel value.
3ee: 97 b1 in r25, 0x07 ; 7
3f0: 90 7e andi r25, 0xE0 ; 224
3f2: 97 b9 out 0x07, r25 ; 7
ADMUX |= (channel & 0x1F); // Fill in new channel.
3f4: 97 b1 in r25, 0x07 ; 7
3f6: 8f 71 andi r24, 0x1F ; 31
3f8: 89 2b or r24, r25
3fa: 87 b9 out 0x07, r24 ; 7
// start conversion
if(bit_is_clear(ADCSRA,ADSC))
3fc: 36 9b sbis 0x06, 6 ; 6
ADCSRA |= (1<<ADSC);
3fe: 36 9a sbi 0x06, 6 ; 6
400: 08 95 ret
00000402 <__subsf3>:
402: 50 58 subi r21, 0x80 ; 128
00000404 <__addsf3>:
404: bb 27 eor r27, r27
406: aa 27 eor r26, r26
408: 0e d0 rcall .+28 ; 0x426 <__addsf3x>
40a: e0 c0 rjmp .+448 ; 0x5cc <__fp_round>
40c: d1 d0 rcall .+418 ; 0x5b0 <__fp_pscA>
40e: 30 f0 brcs .+12 ; 0x41c <__addsf3+0x18>
410: d6 d0 rcall .+428 ; 0x5be <__fp_pscB>
412: 20 f0 brcs .+8 ; 0x41c <__addsf3+0x18>
414: 31 f4 brne .+12 ; 0x422 <__addsf3+0x1e>
416: 9f 3f cpi r25, 0xFF ; 255
418: 11 f4 brne .+4 ; 0x41e <__addsf3+0x1a>
41a: 1e f4 brtc .+6 ; 0x422 <__addsf3+0x1e>
41c: c6 c0 rjmp .+396 ; 0x5aa <__fp_nan>
41e: 0e f4 brtc .+2 ; 0x422 <__addsf3+0x1e>