Task1_LF.lss 12.1 KB
Newer Older
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

Task1_LF.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000000  00803e00  00803e00  00000238  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         000001c4  00000000  00000000  00000074  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .bss          00000004  00803e00  00803e00  00000238  2**0
                  ALLOC
  3 .comment      00000030  00000000  00000000  00000238  2**0
                  CONTENTS, READONLY
  4 .note.gnu.avr.deviceinfo 0000003c  00000000  00000000  00000268  2**2
                  CONTENTS, READONLY
  5 .debug_aranges 00000078  00000000  00000000  000002a4  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_info   00002043  00000000  00000000  0000031c  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_abbrev 000018bf  00000000  00000000  0000235f  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_line   000004f3  00000000  00000000  00003c1e  2**0
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_frame  000000f0  00000000  00000000  00004114  2**2
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_str    00000fc2  00000000  00000000  00004204  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_loc    00000147  00000000  00000000  000051c6  2**0
                  CONTENTS, READONLY, DEBUGGING
 12 .debug_ranges 00000048  00000000  00000000  0000530d  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>

00000034 <__ctors_end>:
  34:	11 24       	eor	r1, r1
  36:	1f be       	out	0x3f, r1	; 63
  38:	cf ef       	ldi	r28, 0xFF	; 255
  3a:	cd bf       	out	0x3d, r28	; 61
  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
  42:	a0 e0       	ldi	r26, 0x00	; 0
  44:	be e3       	ldi	r27, 0x3E	; 62
  46:	01 c0       	rjmp	.+2      	; 0x4a <.do_clear_bss_start>

00000048 <.do_clear_bss_loop>:
  48:	1d 92       	st	X+, r1

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>

00000058 <__bad_interrupt>:
  58:	0c 94 00 00 	jmp	0	; 0x0 <__vectors>

0000005c <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
	
	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
	
	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
	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
	
	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

0000007e <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
	
	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
	
	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>
	
	return ADC0.RESL; //Return 8 bit result
  96:	80 91 10 06 	lds	r24, 0x0610	; 0x800610 <__TEXT_REGION_LENGTH__+0x700610>

}
  9a:	08 95       	ret

0000009c <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>
	
	adc_init();
  a8:	0e 94 2e 00 	call	0x5c	; 0x5c <adc_init>
	
	sei();
  ac:	78 94       	sei
	while (1)
	{
		data = adc_read(6);
		data = 0xff - data;
		
		ones = (data%10);
  ae:	cd ec       	ldi	r28, 0xCD	; 205
	
	sei();
	
	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
		
		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>
		
		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>
	#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>:

#include <avr/io.h>
#include <avr/interrupt.h>


void uart_init(unsigned long baud){
 12e:	0f 93       	push	r16
 130:	1f 93       	push	r17
	
	//From chapter 24.3 in datasheet
	PORTB.OUTSET = (1 << PIN2_bp);
 132:	e0 e2       	ldi	r30, 0x20	; 32
 134:	f4 e0       	ldi	r31, 0x04	; 4
 136:	24 e0       	ldi	r18, 0x04	; 4
 138:	25 83       	std	Z+5, r18	; 0x05
	PORTB.DIRSET = (1 << PIN2_bp); 		//Setting up TX pin as output
 13a:	21 83       	std	Z+1, r18	; 0x01
	USART0.BAUDH = (baud >> 8); 	//Shift register right by 8 bits
 13c:	07 2f       	mov	r16, r23
 13e:	18 2f       	mov	r17, r24
 140:	29 2f       	mov	r18, r25
 142:	33 27       	eor	r19, r19
 144:	e0 e0       	ldi	r30, 0x00	; 0
 146:	f8 e0       	ldi	r31, 0x08	; 8
 148:	01 87       	std	Z+9, r16	; 0x09
	USART0.BAUDL = baud; 			//Set baud rate
 14a:	60 87       	std	Z+8, r22	; 0x08
	//USART.CTRLC CMODE bits default to: async, 1 stop bit, 8 bit character size
	USART0.CTRLB |= (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp);	//Enable RX and TX
 14c:	86 81       	ldd	r24, Z+6	; 0x06
 14e:	80 6c       	ori	r24, 0xC0	; 192
 150:	86 83       	std	Z+6, r24	; 0x06
	
	
	USART0.CTRLA |= (1 << USART_RXCIE_bp); //Enable interupts on RX
 152:	85 81       	ldd	r24, Z+5	; 0x05
 154:	80 68       	ori	r24, 0x80	; 128
 156:	85 83       	std	Z+5, r24	; 0x05
}
 158:	1f 91       	pop	r17
 15a:	0f 91       	pop	r16
 15c:	08 95       	ret

0000015e <uart_transmit>:


// function to transmit data
void uart_transmit(unsigned char data){
	while (!(USART0.STATUS & (1 << USART_DREIF_bp)));
 15e:	e0 e0       	ldi	r30, 0x00	; 0
 160:	f8 e0       	ldi	r31, 0x08	; 8
 162:	94 81       	ldd	r25, Z+4	; 0x04
 164:	95 ff       	sbrs	r25, 5
 166:	fd cf       	rjmp	.-6      	; 0x162 <uart_transmit+0x4>
	USART0.TXDATAH = 0x00; //Is required!
 168:	e0 e0       	ldi	r30, 0x00	; 0
 16a:	f8 e0       	ldi	r31, 0x08	; 8
 16c:	13 82       	std	Z+3, r1	; 0x03
	USART0.TXDATAL = data;
 16e:	82 83       	std	Z+2, r24	; 0x02
 170:	08 95       	ret

00000172 <__vector_22>:
}

//Interrupt service routine for the receiver.
ISR(USART0_RXC_vect){
 172:	1f 92       	push	r1
 174:	0f 92       	push	r0
 176:	0f b6       	in	r0, 0x3f	; 63
 178:	0f 92       	push	r0
 17a:	11 24       	eor	r1, r1
 17c:	2f 93       	push	r18
 17e:	3f 93       	push	r19
 180:	4f 93       	push	r20
 182:	5f 93       	push	r21
 184:	6f 93       	push	r22
 186:	7f 93       	push	r23
 188:	8f 93       	push	r24
 18a:	9f 93       	push	r25
 18c:	af 93       	push	r26
 18e:	bf 93       	push	r27
 190:	ef 93       	push	r30
 192:	ff 93       	push	r31
	
	uint8_t data = USART0.RXDATAL; //We must read the data to clear the interrupt flag
 194:	80 91 00 08 	lds	r24, 0x0800	; 0x800800 <__TEXT_REGION_LENGTH__+0x700800>
	//Do things with data (if you want)
	uart_transmit(data + 1);
 198:	8f 5f       	subi	r24, 0xFF	; 255
 19a:	0e 94 af 00 	call	0x15e	; 0x15e <uart_transmit>
 19e:	ff 91       	pop	r31
 1a0:	ef 91       	pop	r30
 1a2:	bf 91       	pop	r27
 1a4:	af 91       	pop	r26
 1a6:	9f 91       	pop	r25
 1a8:	8f 91       	pop	r24
 1aa:	7f 91       	pop	r23
 1ac:	6f 91       	pop	r22
 1ae:	5f 91       	pop	r21
 1b0:	4f 91       	pop	r20
 1b2:	3f 91       	pop	r19
 1b4:	2f 91       	pop	r18
 1b6:	0f 90       	pop	r0
 1b8:	0f be       	out	0x3f, r0	; 63
 1ba:	0f 90       	pop	r0
 1bc:	1f 90       	pop	r1
 1be:	18 95       	reti

000001c0 <_exit>:
 1c0:	f8 94       	cli

000001c2 <__stop_program>:
 1c2:	ff cf       	rjmp	.-2      	; 0x1c2 <__stop_program>