Commit 40e8c892 authored by Petter Breedveld's avatar Petter Breedveld
Browse files

Finished day 3

parent 6d7fe9d0
:1000000019C02AC029C028C027C026C025C024C0C6
:1000100023C022C021C020C01FC01EC01DC01CC0E4
:100020001BC01AC019C018C017C016C0A2C014C087
:1000300013C012C011241FBECFEFCDBFDFE3DEBF60
:100040002EE3A0E0BEE301C01D92A430B207E1F7A9
:100050000E944E000C94E0000C940000E0E0F6E0FA
:1000600080818460808381818260818382818061DC
:100070008283828182838081816080830895E0E031
:10008000F6E08683838581608387808581608087B1
:10009000838580FFFDCF8091100608956CE675E0A2
:1000A00080E090E00E9497000E942E007894CDECB2
:1000B00086E00E943F0080958C9F912D112496959B
:1000C00096959695392F330F232F220F220F230F4A
:1000D000821B8093013E9C9F812D112486958695DD
:1000E0008695382F330F232F220F220F230F921BB9
:1000F0009093023E8093033E8093003E805D0E9479
:10010000AF008091023E805D0E94AF008091013E71
:10011000805D0E94AF0080E20E94AF002AE28CE284
:100120009AE0215080409040E1F70000C1CF0F934A
:100130001F93E0E2F4E024E025832183072F182FAA
:10014000292F3327E0E0F8E0018760878681806C03
:1001500086838581806885831F910F910895E0E0F3
:10016000F8E0948195FFFDCFE0E0F8E01382828310
:1001700008951F920F920FB60F9211242F933F9361
:100180004F935F936F937F938F939F93AF93BF939F
:10019000EF93FF93809100088F5F0E94AF00FF9163
:1001A000EF91BF91AF919F918F917F916F915F91EF
:1001B0004F913F912F910F900FBE0F901F90189568
:0401C000F894FFCFE1
:1000000019C035C034C033C032C031C030C02FC079
:100010002EC02DC02CC02BC02AC029C028C027C08C
:1000200026C025C024C023C022C021C089C01FC053
:100030001EC01DC011241FBECFEFCDBFDFE3DEBF4A
:100040001EE3A0E0BEE3E0E2FAE002C005900D92FC
:10005000AA33B107D9F72EE3AAE3BEE301C01D928C
:10006000A534B207E1F70E9459000C940E050C94D8
:100070000000E0E0F6E0808184608083818182601E
:100080008183828180618283828182838081816099
:1000900080830895E0E0F6E086838385816083872E
:1000A000808581608087838580FFFDCF80911006E9
:1000B00008956CE675E080E090E00E9487000E9461
:1000C00039007894C6E0DEE386E00E944A0080951D
:1000D00080933A3E1F928F93DF93CF930E94F90053
:1000E0009AE22CE28AE0915020408040E1F7000043
:1000F0000F900F900F900F90E7CFE0E0F8E0948121
:1001000095FFFDCF8093020880E090E00895E0E243
:10011000F4E0258124602583218124602183E0E0AF
:10012000F8E0608771878681806C8683858180682E
:10013000858360E070E08DE790E00E94AE00089556
:100140001F920F920FB60F9211248F938091000887
:100150008F910F900FBE0F901F9018950F931F93C4
:10016000CF93DF93009731F46115710519F480E0A6
:1001700090E03AC08B01EC016EE070E081E090E02D
:100180000E94E102FC01892B91F380E88383011531
:10019000110571F00287138781E8838380913B3ECC
:1001A00090913C3E892B21F4E0933B3EF0933C3E02
:1001B0002097C9F0C087D187838182608383809133
:1001C0003D3E90913E3E892B71F4E0933D3EF0938D
:1001D0003E3E80913F3E9091403E892B21F4E0933A
:1001E0003F3EF093403ECF01DF91CF911F910F91A1
:1001F0000895A0E0B0E0EFEFF0E00C94ED04AE0164
:100200004B5F5F4FFA0161917191AF0180913D3E6B
:1002100090913E3E0E940F01E2E00C940605ACE096
:10022000B0E0E5E1F1E00C94DD047C016B018A01B2
:10023000FC0116821782838181FFBDC1CE01019628
:100240004C01F7019381F60193FD859193FF819114
:100250006F01882309F4ABC1853239F493FD859190
:1002600093FF81916F01853229F4B70190E00E94DC
:100270004704E7CF512C312C20E02032A0F48B3200
:1002800069F030F4803259F0833269F420612CC077
:100290008D3239F0803339F4216026C02260246029
:1002A00023C0286021C027FD27C030ED380F3A3029
:1002B00078F426FF06C0FAE05F9E300D1124532E1D
:1002C00013C08AE0389E300D1124332E20620CC0FA
:1002D0008E3221F426FD6BC1206406C08C3611F4E9
:1002E000206802C0883641F4F60193FD859193FFA2
:1002F00081916F018111C1CF982F9F7D95549330CB
:1003000028F40C5F1F4FFFE3F9830DC0833631F0F3
:10031000833771F0833509F05BC022C0F80180811A
:1003200089830E5F1F4F44244394512C540115C000
:100330003801F2E06F0E711CF801A080B18026FF39
:1003400003C0652D70E002C06FEF7FEFC5012C8701
:100350000E943C042C0183012C852F77222E17C08C
:100360003801F2E06F0E711CF801A080B18026FF09
:1003700003C0652D70E002C06FEF7FEFC5012C87D1
:100380000E942A042C012C852068222E830123FC44
:100390001BC0832D90E048165906B0F4B70180E2E7
:1003A00090E00E9447043A94F4CFF50127FC859130
:1003B00027FE81915F01B70190E00E944704311050
:1003C0003A94F1E04F1A51084114510471F7E5C015
:1003D000843611F0893639F5F80127FF07C06081AE
:1003E0007181828193810C5F1F4F08C06081718190
:1003F000072E000C880B990B0E5F1F4F2F76722E65
:1004000097FF09C090958095709561957F4F8F4FAC
:100410009F4F2068722E2AE030E0A4010E947F04E2
:10042000A82EA81844C0853729F42F7EB22E2AE0C2
:1004300030E025C0F22FF97FBF2E8F36C1F018F4BF
:10044000883579F0B4C0803719F0883721F0AFC013
:100450002F2F2061B22EB4FE0DC08B2D8460B82EDC
:1004600009C024FF0AC09F2F9660B92E06C028E05D
:1004700030E005C020E130E002C020E132E0F801C8
:10048000B7FE07C060817181828193810C5F1F4F2D
:1004900006C06081718180E090E00E5F1F4FA40173
:1004A0000E947F04A82EA818FB2DFF777F2E76FED2
:1004B0000BC0372D3E7FA51450F474FE0AC072FCA9
:1004C00008C0372D3E7E05C0BA2C372D03C0BA2C8C
:1004D00001C0B52C34FF0DC0FE01EA0DF11D808175
:1004E000803311F4397E09C032FF06C0B394B3944F
:1004F00004C0832F867809F0B39433FD13C030FF16
:1005000006C05A2CB31418F4530C5B18B32CB31454
:1005100068F4B70180E290E03C870E944704B394FE
:100520003C85F5CFB31410F43B1801C0312C34FFD7
:1005300012C0B70180E390E03C870E9447043C85ED
:1005400032FF17C031FD03C088E790E002C088E5A4
:1005500090E0B7010CC0832F867859F031FF02C0BC
:100560008BE201C080E237FD8DE2B70190E00E948E
:100570004704A51438F4B70180E390E00E944704D3
:100580005A94F7CFAA94F401EA0DF11D8081B701C6
:1005900090E00E944704A110F5CF332009F451CE1A
:1005A000B70180E290E00E9447043A94F6CFF70149
:1005B0008681978102C08FEF9FEF2C96E2E10C9429
:1005C000F6040F931F93CF93DF93869F8001879F3D
:1005D000100D969F100D1124C8010E94FD02EC0120
:1005E000009729F0A80160E070E00E943504CE0178
:1005F000DF91CF911F910F910895CF93DF938230B8
:10060000910510F482E090E0E091433EF091443E89
:1006100020E030E0C0E0D0E0309711F1408151811E
:1006200048175907C0F04817590761F48281938130
:10063000209719F08A839B832BC08093433E90932D
:10064000443E26C02115310519F04217530718F40E
:100650009A01BE01DF01EF010280F381E02DDCCFC2
:100660002115310509F1281B390B2430310590F48F
:1006700012968D919C9113976115710521F0FB01E4
:100680008283938304C08093433E9093443EFD0154
:10069000329644C0FD01E20FF31F819391932250E3
:1006A00031092D933C933AC02091413E3091423E16
:1006B000232B41F42091023E3091033E2093413E92
:1006C0003093423E2091003E3091013E211531058C
:1006D00041F42DB73EB74091043E5091053E241B96
:1006E000350BE091413EF091423EE217F307A0F452
:1006F0002E1B3F0B2817390778F0AC014E5F5F4F78
:100700002417350748F04E0F5F1F4093413E50932A
:10071000423E8193919302C0E0E0F0E0CF01DF918F
:10072000CF9108950F931F93CF93DF93009709F410
:100730008CC0FC013297128213820091433E1091CB
:10074000443E0115110581F420813181820F931FF0
:100750002091413E3091423E2817390779F5E093C8
:10076000413EF093423E71C0D80140E050E0AE17E8
:10077000BF0750F412962D913C911397AD012115AE
:10078000310509F1D901F3CF9D01DA0122833383C9
:1007900060817181860F971F8217930769F4EC01BE
:1007A00028813981260F371F2E5F3F4F20833183E9
:1007B0008A819B8182839383452B29F4E093433E76
:1007C000F093443E42C01296ED93FC931397ED01D3
:1007D000499159919E01240F351FE217F30771F4D7
:1007E00080819181840F951F02968D939C93119720
:1007F0008281938112968D939C931397E0E0F0E0B1
:10080000D80112968D919C911397009719F0F801D9
:100810008C01F6CF8D919C9198012E5F3F4F820FF6
:10082000931F2091413E3091423E2817390769F4C9
:10083000309729F41092433E1092443E02C0128237
:1008400013820093413E1093423EDF91CF911F915E
:100850000F910895FC010590615070400110D8F788
:10086000809590958E0F9F1F0895DC0101C06D93B8
:1008700041505040E0F70895FC01615070400190F4
:100880000110D8F7809590958E0F9F1F08950F93B4
:100890001F93CF93DF93FB01238121FD03C08FEFD3
:1008A0009FEF28C022FF16C04681578124813581E1
:1008B0004217530744F4A081B1819D012F5F3F4F40
:1008C000208331838C93268137812F5F3F4F26838E
:1008D000378310C0EB01092F182F0084F185E02D1C
:1008E0000995892BE1F68E819F8101968E839F83E6
:1008F000812F902FDF91CF911F910F910895FA01D1
:10090000AA27283051F1203181F1E8946F936E7F4E
:100910006E5F7F4F8F4F9F4FAF4FB1E03ED0B4E03F
:100920003CD0670F781F891F9A1FA11D680F791F80
:100930008A1F911DA11D6A0F711D811D911DA11D91
:1009400020D009F468943F912AE0269F11243019A1
:10095000305D3193DEF6CF010895462F4770405D3C
:100960004193B3E00FD0C9F7F6CF462F4F70405DEB
:100970004A3318F0495D31FD4052419302D0A9F746
:10098000EACFB4E0A6959795879577956795BA9540
:10099000C9F700976105710508959B01AC010A2E06
:1009A00006945795479537952795BA95C9F7620FDD
:1009B000731F841F951FA01D08952F923F924F9281
:1009C0005F926F927F928F929F92AF92BF92CF92DF
:1009D000DF92EF92FF920F931F93CF93DF93CDB7E8
:1009E000DEB7CA1BDB0BCDBFDEBF09942A8839886E
:1009F00048885F846E847D848C849B84AA84B984B7
:100A0000C884DF80EE80FD800C811B81AA81B981C2
:100A1000CE0FD11DCDBFDEBFED010895F894FFCFFD
:100A20000000453E20004C6967687420696E74655B
:100A30006E736974792069732063757272656E7460
:100A40006C79202564206272696768746E657373BF
:0A0A500020706F696E7473210A00B4
:00000001FF
......@@ -3,62 +3,62 @@ Task1_LF.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000000 00803e00 00803e00 00000238 2**0
0 .data 0000003a 00803e00 00000a20 00000ab4 2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 000001c4 00000000 00000000 00000074 2**1
1 .text 00000a20 00000000 00000000 00000094 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .bss 00000004 00803e00 00803e00 00000238 2**0
2 .bss 0000000b 00803e3a 00803e3a 00000aee 2**0
ALLOC
3 .comment 00000030 00000000 00000000 00000238 2**0
3 .comment 0000005c 00000000 00000000 00000aee 2**0
CONTENTS, READONLY
4 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00000268 2**2
4 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00000b4c 2**2
CONTENTS, READONLY
5 .debug_aranges 00000078 00000000 00000000 000002a4 2**0
5 .debug_aranges 00000078 00000000 00000000 00000b88 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_info 00002043 00000000 00000000 0000031c 2**0
6 .debug_info 00002156 00000000 00000000 00000c00 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_abbrev 000018bf 00000000 00000000 0000235f 2**0
7 .debug_abbrev 00001959 00000000 00000000 00002d56 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_line 000004f3 00000000 00000000 00003c1e 2**0
8 .debug_line 000004b7 00000000 00000000 000046af 2**0
CONTENTS, READONLY, DEBUGGING
9 .debug_frame 000000f0 00000000 00000000 00004114 2**2
9 .debug_frame 000000bc 00000000 00000000 00004b68 2**2
CONTENTS, READONLY, DEBUGGING
10 .debug_str 00000fc2 00000000 00000000 00004204 2**0
10 .debug_str 00000fe4 00000000 00000000 00004c24 2**0
CONTENTS, READONLY, DEBUGGING
11 .debug_loc 00000147 00000000 00000000 000051c6 2**0
11 .debug_loc 0000010b 00000000 00000000 00005c08 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_ranges 00000048 00000000 00000000 0000530d 2**0
12 .debug_ranges 00000048 00000000 00000000 00005d13 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 19 c0 rjmp .+50 ; 0x34 <__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: 1e c0 rjmp .+60 ; 0x58 <__bad_interrupt>
1c: 1d c0 rjmp .+58 ; 0x58 <__bad_interrupt>
1e: 1c c0 rjmp .+56 ; 0x58 <__bad_interrupt>
20: 1b c0 rjmp .+54 ; 0x58 <__bad_interrupt>
22: 1a c0 rjmp .+52 ; 0x58 <__bad_interrupt>
24: 19 c0 rjmp .+50 ; 0x58 <__bad_interrupt>
26: 18 c0 rjmp .+48 ; 0x58 <__bad_interrupt>
28: 17 c0 rjmp .+46 ; 0x58 <__bad_interrupt>
2a: 16 c0 rjmp .+44 ; 0x58 <__bad_interrupt>
2c: a2 c0 rjmp .+324 ; 0x172 <__vector_22>
2e: 14 c0 rjmp .+40 ; 0x58 <__bad_interrupt>
30: 13 c0 rjmp .+38 ; 0x58 <__bad_interrupt>
32: 12 c0 rjmp .+36 ; 0x58 <__bad_interrupt>
2: 35 c0 rjmp .+106 ; 0x6e <__bad_interrupt>
4: 34 c0 rjmp .+104 ; 0x6e <__bad_interrupt>
6: 33 c0 rjmp .+102 ; 0x6e <__bad_interrupt>
8: 32 c0 rjmp .+100 ; 0x6e <__bad_interrupt>
a: 31 c0 rjmp .+98 ; 0x6e <__bad_interrupt>
c: 30 c0 rjmp .+96 ; 0x6e <__bad_interrupt>
e: 2f c0 rjmp .+94 ; 0x6e <__bad_interrupt>
10: 2e c0 rjmp .+92 ; 0x6e <__bad_interrupt>
12: 2d c0 rjmp .+90 ; 0x6e <__bad_interrupt>
14: 2c c0 rjmp .+88 ; 0x6e <__bad_interrupt>
16: 2b c0 rjmp .+86 ; 0x6e <__bad_interrupt>
18: 2a c0 rjmp .+84 ; 0x6e <__bad_interrupt>
1a: 29 c0 rjmp .+82 ; 0x6e <__bad_interrupt>
1c: 28 c0 rjmp .+80 ; 0x6e <__bad_interrupt>
1e: 27 c0 rjmp .+78 ; 0x6e <__bad_interrupt>
20: 26 c0 rjmp .+76 ; 0x6e <__bad_interrupt>
22: 25 c0 rjmp .+74 ; 0x6e <__bad_interrupt>
24: 24 c0 rjmp .+72 ; 0x6e <__bad_interrupt>
26: 23 c0 rjmp .+70 ; 0x6e <__bad_interrupt>
28: 22 c0 rjmp .+68 ; 0x6e <__bad_interrupt>
2a: 21 c0 rjmp .+66 ; 0x6e <__bad_interrupt>
2c: 89 c0 rjmp .+274 ; 0x140 <__vector_22>
2e: 1f c0 rjmp .+62 ; 0x6e <__bad_interrupt>
30: 1e c0 rjmp .+60 ; 0x6e <__bad_interrupt>
32: 1d c0 rjmp .+58 ; 0x6e <__bad_interrupt>
00000034 <__ctors_end>:
34: 11 24 eor r1, r1
......@@ -68,302 +68,1337 @@ Disassembly of section .text:
3c: df e3 ldi r29, 0x3F ; 63
3e: de bf out 0x3e, r29 ; 62
00000040 <__do_clear_bss>:
40: 2e e3 ldi r18, 0x3E ; 62
00000040 <__do_copy_data>:
40: 1e e3 ldi r17, 0x3E ; 62
42: a0 e0 ldi r26, 0x00 ; 0
44: be e3 ldi r27, 0x3E ; 62
46: 01 c0 rjmp .+2 ; 0x4a <.do_clear_bss_start>
46: e0 e2 ldi r30, 0x20 ; 32
48: fa e0 ldi r31, 0x0A ; 10
4a: 02 c0 rjmp .+4 ; 0x50 <__do_copy_data+0x10>
4c: 05 90 lpm r0, Z+
4e: 0d 92 st X+, r0
50: aa 33 cpi r26, 0x3A ; 58
52: b1 07 cpc r27, r17
54: d9 f7 brne .-10 ; 0x4c <__do_copy_data+0xc>
00000048 <.do_clear_bss_loop>:
48: 1d 92 st X+, r1
00000056 <__do_clear_bss>:
56: 2e e3 ldi r18, 0x3E ; 62
58: aa e3 ldi r26, 0x3A ; 58
5a: be e3 ldi r27, 0x3E ; 62
5c: 01 c0 rjmp .+2 ; 0x60 <.do_clear_bss_start>
0000004a <.do_clear_bss_start>:
4a: a4 30 cpi r26, 0x04 ; 4
4c: b2 07 cpc r27, r18
4e: e1 f7 brne .-8 ; 0x48 <.do_clear_bss_loop>
50: 0e 94 4e 00 call 0x9c ; 0x9c <main>
54: 0c 94 e0 00 jmp 0x1c0 ; 0x1c0 <_exit>
0000005e <.do_clear_bss_loop>:
5e: 1d 92 st X+, r1
00000058 <__bad_interrupt>:
58: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
00000060 <.do_clear_bss_start>:
60: a5 34 cpi r26, 0x45 ; 69
62: b2 07 cpc r27, r18
64: e1 f7 brne .-8 ; 0x5e <.do_clear_bss_loop>
66: 0e 94 59 00 call 0xb2 ; 0xb2 <main>
6a: 0c 94 0e 05 jmp 0xa1c ; 0xa1c <_exit>
0000005c <adc_init>:
0000006e <__bad_interrupt>:
6e: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
00000072 <adc_init>:
*/
#include <avr/io.h>
void adc_init(){
ADC0.CTRLA |= (ADC_RESSEL_8BIT_gc); //Set resolution, we choose 8 bits
5c: e0 e0 ldi r30, 0x00 ; 0
5e: f6 e0 ldi r31, 0x06 ; 6
60: 80 81 ld r24, Z
62: 84 60 ori r24, 0x04 ; 4
64: 80 83 st Z, r24
72: e0 e0 ldi r30, 0x00 ; 0
74: f6 e0 ldi r31, 0x06 ; 6
76: 80 81 ld r24, Z
78: 84 60 ori r24, 0x04 ; 4
7a: 80 83 st Z, r24
ADC0.CTRLB |= (ADC_SAMPLNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4
66: 81 81 ldd r24, Z+1 ; 0x01
68: 82 60 ori r24, 0x02 ; 2
6a: 81 83 std Z+1, r24 ; 0x01
7c: 81 81 ldd r24, Z+1 ; 0x01
7e: 82 60 ori r24, 0x02 ; 2
80: 81 83 std Z+1, r24 ; 0x01
//More samples gives a better result but takes longer
ADC0.CTRLC |= (ADC_REFSEL_VDDREF_gc); //We select to use the supply voltage (VDD) as voltage reference
6c: 82 81 ldd r24, Z+2 ; 0x02
6e: 80 61 ori r24, 0x10 ; 16
70: 82 83 std Z+2, r24 ; 0x02
82: 82 81 ldd r24, Z+2 ; 0x02
84: 80 61 ori r24, 0x10 ; 16
86: 82 83 std Z+2, r24 ; 0x02
ADC0.CTRLC |= (ADC_PRESC_DIV2_gc); //ADC clock prescaler, best accuracy when run below 2MHz. (Here div2 ~1.46 MHz)
72: 82 81 ldd r24, Z+2 ; 0x02
74: 82 83 std Z+2, r24 ; 0x02
88: 82 81 ldd r24, Z+2 ; 0x02
8a: 82 83 std Z+2, r24 ; 0x02
ADC0.CTRLA |= (ADC_ENABLE_bm); //Enable the ADC
76: 80 81 ld r24, Z
78: 81 60 ori r24, 0x01 ; 1
7a: 80 83 st Z, r24
7c: 08 95 ret
8c: 80 81 ld r24, Z
8e: 81 60 ori r24, 0x01 ; 1
90: 80 83 st Z, r24
92: 08 95 ret
0000007e <adc_read>:
00000094 <adc_read>:
}
uint8_t adc_read(uint8_t channel){
ADC0.MUXPOS = channel; //Select input on the ADC mux
7e: e0 e0 ldi r30, 0x00 ; 0
80: f6 e0 ldi r31, 0x06 ; 6
82: 86 83 std Z+6, r24 ; 0x06
94: e0 e0 ldi r30, 0x00 ; 0
96: f6 e0 ldi r31, 0x06 ; 6
98: 86 83 std Z+6, r24 ; 0x06
//NOTE: We can use = here because this is the only thing the register holds. Neat!
ADC0.INTFLAGS |= (ADC_RESRDY_bm); //Clear the results ready flag
84: 83 85 ldd r24, Z+11 ; 0x0b
86: 81 60 ori r24, 0x01 ; 1
88: 83 87 std Z+11, r24 ; 0x0b
9a: 83 85 ldd r24, Z+11 ; 0x0b
9c: 81 60 ori r24, 0x01 ; 1
9e: 83 87 std Z+11, r24 ; 0x0b
ADC0.COMMAND |= (ADC_STCONV_bm); //Start a conversion
8a: 80 85 ldd r24, Z+8 ; 0x08
8c: 81 60 ori r24, 0x01 ; 1
8e: 80 87 std Z+8, r24 ; 0x08
while(!(ADC0.INTFLAGS & ADC_RESRDY_bm)); //Wait for the results ready flag to be set
90: 83 85 ldd r24, Z+11 ; 0x0b
92: 80 ff sbrs r24, 0
94: fd cf rjmp .-6 ; 0x90 <adc_read+0x12>
a0: 80 85 ldd r24, Z+8 ; 0x08
a2: 81 60 ori r24, 0x01 ; 1
a4: 80 87 std Z+8, r24 ; 0x08
while(!(ADC0.INTFLAGS & ADC_RESRDY_bm)){
a6: 83 85 ldd r24, Z+11 ; 0x0b
a8: 80 ff sbrs r24, 0
aa: fd cf rjmp .-6 ; 0xa6 <adc_read+0x12>
//Wait for the results ready flag to be set
}
return ADC0.RESL; //Return 8 bit result
96: 80 91 10 06 lds r24, 0x0610 ; 0x800610 <__TEXT_REGION_LENGTH__+0x700610>
ac: 80 91 10 06 lds r24, 0x0610 ; 0x800610 <__TEXT_REGION_LENGTH__+0x700610>
}
9a: 08 95 ret
b0: 08 95 ret
0000009c <main>:
000000b2 <main>:
uint8_t data, ones, tens, hundreds;
int main(void)
{
uart_init(BAUD_9600);
9c: 6c e6 ldi r22, 0x6C ; 108
9e: 75 e0 ldi r23, 0x05 ; 5
a0: 80 e0 ldi r24, 0x00 ; 0
a2: 90 e0 ldi r25, 0x00 ; 0
a4: 0e 94 97 00 call 0x12e ; 0x12e <uart_init>
uart_init(BAUD_9600); //Initiate the uart (provided in uart.c) with a baudrate of 9600
b2: 6c e6 ldi r22, 0x6C ; 108
b4: 75 e0 ldi r23, 0x05 ; 5
b6: 80 e0 ldi r24, 0x00 ; 0
b8: 90 e0 ldi r25, 0x00 ; 0
ba: 0e 94 87 00 call 0x10e ; 0x10e <uart_init>
adc_init();
a8: 0e 94 2e 00 call 0x5c ; 0x5c <adc_init>
adc_init(); //Initiate the adc (The student has to write this function)
be: 0e 94 39 00 call 0x72 ; 0x72 <adc_init>
sei();
ac: 78 94 sei
while (1)
{
data = adc_read(6);
data = 0xff - data;
sei(); //If we want to receive via UART we need interrupts enabled.
c2: 78 94 sei
data = adc_read(LIGHT); //Read the analog voltage on channel 6, connected to light sensor
ones = (data%10);
ae: cd ec ldi r28, 0xCD ; 205
sei();
//The light sensor returns the ones complement (the opposite) of the brightness:
data = 0xff - data;
printf("Light intensity is currently %d brightness points!\n", data); //Print out the value neatly using printf
c4: c6 e0 ldi r28, 0x06 ; 6
c6: de e3 ldi r29, 0x3E ; 62
sei(); //If we want to receive via UART we need interrupts enabled.
//NOTE: UART isn't used to receive here and as such this isn't required.
while (1)
{
data = adc_read(6);
b0: 86 e0 ldi r24, 0x06 ; 6
b2: 0e 94 3f 00 call 0x7e ; 0x7e <adc_read>
data = 0xff - data;
b6: 80 95 com r24
data = adc_read(LIGHT); //Read the analog voltage on channel 6, connected to light sensor
c8: 86 e0 ldi r24, 0x06 ; 6
ca: 0e 94 4a 00 call 0x94 ; 0x94 <adc_read>
ones = (data%10);
b8: 8c 9f mul r24, r28
ba: 91 2d mov r25, r1
bc: 11 24 eor r1, r1
be: 96 95 lsr r25
c0: 96 95 lsr r25
c2: 96 95 lsr r25
c4: 39 2f mov r19, r25
c6: 33 0f add r19, r19
c8: 23 2f mov r18, r19
ca: 22 0f add r18, r18
cc: 22 0f add r18, r18
ce: 23 0f add r18, r19
d0: 82 1b sub r24, r18
d2: 80 93 01 3e sts 0x3E01, r24 ; 0x803e01 <ones>
data /= 10;
tens = (data%10);
d6: 9c 9f mul r25, r28
d8: 81 2d mov r24, r1
da: 11 24 eor r1, r1
dc: 86 95 lsr r24
de: 86 95 lsr r24
e0: 86 95 lsr r24
e2: 38 2f mov r19, r24
e4: 33 0f add r19, r19
e6: 23 2f mov r18, r19
e8: 22 0f add r18, r18
ea: 22 0f add r18, r18
ec: 23 0f add r18, r19
ee: 92 1b sub r25, r18
f0: 90 93 02 3e sts 0x3E02, r25 ; 0x803e02 <tens>
data /= 10;
f4: 80 93 03 3e sts 0x3E03, r24 ; 0x803e03 <data>
hundreds = (data%10);
f8: 80 93 00 3e sts 0x3E00, r24 ; 0x803e00 <_edata>
//The light sensor returns the ones complement (the opposite) of the brightness:
data = 0xff - data;
ce: 80 95 com r24
d0: 80 93 3a 3e sts 0x3E3A, r24 ; 0x803e3a <__data_end>
uart_transmit(hundreds + 48);
fc: 80 5d subi r24, 0xD0 ; 208
fe: 0e 94 af 00 call 0x15e ; 0x15e <uart_transmit>
uart_transmit(tens + 48);
102: 80 91 02 3e lds r24, 0x3E02 ; 0x803e02 <tens>
106: 80 5d subi r24, 0xD0 ; 208
108: 0e 94 af 00 call 0x15e ; 0x15e <uart_transmit>
uart_transmit(ones + 48);
10c: 80 91 01 3e lds r24, 0x3E01 ; 0x803e01 <ones>
110: 80 5d subi r24, 0xD0 ; 208
112: 0e 94 af 00 call 0x15e ; 0x15e <uart_transmit>
uart_transmit(0x20); //Space
116: 80 e2 ldi r24, 0x20 ; 32
118: 0e 94 af 00 call 0x15e ; 0x15e <uart_transmit>
printf("Light intensity is currently %d brightness points!\n", data); //Print out the value neatly using printf
d4: 1f 92 push r1
d6: 8f 93 push r24
d8: df 93 push r29
da: cf 93 push r28
dc: 0e 94 f9 00 call 0x1f2 ; 0x1f2 <printf>
#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif
__builtin_avr_delay_cycles(__ticks_dc);
11c: 2a e2 ldi r18, 0x2A ; 42
11e: 8c e2 ldi r24, 0x2C ; 44
120: 9a e0 ldi r25, 0x0A ; 10
122: 21 50 subi r18, 0x01 ; 1
124: 80 40 sbci r24, 0x00 ; 0
126: 90 40 sbci r25, 0x00 ; 0
128: e1 f7 brne .-8 ; 0x122 <main+0x86>
12a: 00 00 nop
12c: c1 cf rjmp .-126 ; 0xb0 <main+0x14>
0000012e <uart_init>:
e0: 9a e2 ldi r25, 0x2A ; 42
e2: 2c e2 ldi r18, 0x2C ; 44
e4: 8a e0 ldi r24, 0x0A ; 10
e6: 91 50 subi r25, 0x01 ; 1
e8: 20 40 sbci r18, 0x00 ; 0
ea: 80 40 sbci r24, 0x00 ; 0
ec: e1 f7 brne .-8 ; 0xe6 <main+0x34>
ee: 00 00 nop
f0: 0f 90 pop r0
f2: 0f 90 pop r0
f4: 0f 90 pop r0
f6: 0f 90 pop r0
f8: e7 cf rjmp .-50 ; 0xc8 <main+0x16>
#include <avr/io.h>
#include <avr/interrupt.h>
000000fa <uart_transmit>:
// function to transmit data
int uart_transmit(char data, FILE* stream){
while (!(USART0.STATUS & (1 << USART_DREIF_bp))){
fa: e0 e0 ldi r30, 0x00 ; 0
fc: f8 e0 ldi r31, 0x08 ; 8
fe: 94 81 ldd r25, Z+4 ; 0x04
100: 95 ff sbrs r25, 5
102: fd cf rjmp .-6 ; 0xfe <uart_transmit+0x4>
//Wait for ongoing transmission to finish (if there is one)
}
USART0.TXDATAL = data; //Put new data in register
104: 80 93 02 08 sts 0x0802, r24 ; 0x800802 <__TEXT_REGION_LENGTH__+0x700802>
return 0;
}
108: 80 e0 ldi r24, 0x00 ; 0
10a: 90 e0 ldi r25, 0x00 ; 0
10c: 08 95 ret