diff --git a/MIC-Week1/.vs/MIC-Week1/v14/.atsuo b/MIC-Week1/.vs/MIC-Week1/v14/.atsuo index 126b84e..bcfcc67 100644 Binary files a/MIC-Week1/.vs/MIC-Week1/v14/.atsuo and b/MIC-Week1/.vs/MIC-Week1/v14/.atsuo differ diff --git a/MIC-Week5/Debug/MIC-Week5.lss b/MIC-Week5/Debug/MIC-Week5.lss index ff9c4f0..7ed76a6 100644 --- a/MIC-Week5/Debug/MIC-Week5.lss +++ b/MIC-Week5/Debug/MIC-Week5.lss @@ -3,29 +3,29 @@ MIC-Week5.elf: file format elf32-avr Sections: Idx Name Size VMA LMA File off Algn - 0 .data 00000000 00800100 00800100 00000158 2**0 + 0 .data 00000000 00800100 00800100 000002c6 2**0 CONTENTS, ALLOC, LOAD, DATA - 1 .text 00000104 00000000 00000000 00000054 2**1 + 1 .text 00000272 00000000 00000000 00000054 2**1 CONTENTS, ALLOC, LOAD, READONLY, CODE - 2 .comment 00000030 00000000 00000000 00000158 2**0 + 2 .comment 00000030 00000000 00000000 000002c6 2**0 CONTENTS, READONLY - 3 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00000188 2**2 + 3 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 000002f8 2**2 CONTENTS, READONLY - 4 .debug_aranges 00000078 00000000 00000000 000001c4 2**0 + 4 .debug_aranges 000000c0 00000000 00000000 00000334 2**0 CONTENTS, READONLY, DEBUGGING - 5 .debug_info 000004a3 00000000 00000000 0000023c 2**0 + 5 .debug_info 00000cbd 00000000 00000000 000003f4 2**0 CONTENTS, READONLY, DEBUGGING - 6 .debug_abbrev 000002f6 00000000 00000000 000006df 2**0 + 6 .debug_abbrev 00000327 00000000 00000000 000010b1 2**0 CONTENTS, READONLY, DEBUGGING - 7 .debug_line 00000325 00000000 00000000 000009d5 2**0 + 7 .debug_line 0000066f 00000000 00000000 000013d8 2**0 CONTENTS, READONLY, DEBUGGING - 8 .debug_frame 000000dc 00000000 00000000 00000cfc 2**2 + 8 .debug_frame 00000190 00000000 00000000 00001a48 2**2 CONTENTS, READONLY, DEBUGGING - 9 .debug_str 0000022e 00000000 00000000 00000dd8 2**0 + 9 .debug_str 000002e3 00000000 00000000 00001bd8 2**0 CONTENTS, READONLY, DEBUGGING - 10 .debug_loc 000001a4 00000000 00000000 00001006 2**0 + 10 .debug_loc 0000043c 00000000 00000000 00001ebb 2**0 CONTENTS, READONLY, DEBUGGING - 11 .debug_ranges 00000058 00000000 00000000 000011aa 2**0 + 11 .debug_ranges 000000a0 00000000 00000000 000022f7 2**0 CONTENTS, READONLY, DEBUGGING Disassembly of section .text: @@ -109,30 +109,24 @@ Disassembly of section .text: 92: d0 e1 ldi r29, 0x10 ; 16 94: de bf out 0x3e, r29 ; 62 96: cd bf out 0x3d, r28 ; 61 - 98: 1b d0 rcall .+54 ; 0xd0
- 9a: 32 c0 rjmp .+100 ; 0x100 <_exit> + 98: 41 d0 rcall .+130 ; 0x11c
+ 9a: e9 c0 rjmp .+466 ; 0x26e <_exit> 0000009c <__bad_interrupt>: 9c: b1 cf rjmp .-158 ; 0x0 <__vectors> 0000009e : + spi_write(i); // digit value: i (= digit place) + spi_slaveDeSelect(0); // Deselect display chip -// wait(): busy waiting for 'ms' millisecond -// Used library: util/delay.h -void wait( int ms ) -{ - for (int tms=0; tms a4: 20 e0 ldi r18, 0x00 ; 0 a6: 30 e0 ldi r19, 0x00 ; 0 - #else - //round up by default - __ticks_dc = (uint32_t)(ceil(fabs(__tmp))); - #endif - - __builtin_avr_delay_cycles(__ticks_dc); a8: ef ec ldi r30, 0xCF ; 207 aa: f7 e0 ldi r31, 0x07 ; 7 ac: 31 97 sbiw r30, 0x01 ; 1 @@ -146,101 +140,348 @@ void wait( int ms ) bc: a9 f7 brne .-22 ; 0xa8 be: 08 95 ret -000000c0 : +000000c0 : - -// send/receive uart - dB-meter -int opgaveb1( void ) +int test2(void) { - usart0_init(); // initialize USART0 - c0: 08 d0 rcall .+16 ; 0xd2 - usart0_start(); - c2: 10 d0 rcall .+32 ; 0xe4 + c0: cf 93 push r28 + c2: df 93 push r29 + DDRB=0x01; // Set PB0 pin as output for display select + c4: 81 e0 ldi r24, 0x01 ; 1 + c6: 87 bb out 0x17, r24 ; 23 - while (1) + spi_masterInit(); // Initialize spi module + c8: 2d d0 rcall .+90 ; 0x124 + displayDriverInit(); // Initialize display chip + ca: 4e d0 rcall .+156 ; 0x168 + + for(int i=-999; i<=9999; i++) { - wait(50); // every 50 ms (busy waiting) - c4: 82 e3 ldi r24, 0x32 ; 50 - c6: 90 e0 ldi r25, 0x00 ; 0 - c8: ea df rcall .-44 ; 0x9e + writeLedDisplay(i); + cc: 89 e1 ldi r24, 0x19 ; 25 + ce: 9c ef ldi r25, 0xFC ; 252 + d0: 7b d0 rcall .+246 ; 0x1c8 + wait(5); + d2: 85 e0 ldi r24, 0x05 ; 5 + d4: 90 e0 ldi r25, 0x00 ; 0 + d6: e3 df rcall .-58 ; 0x9e + DDRB=0x01; // Set PB0 pin as output for display select - char c = uart0_receiveChar(); // receive string from uart - ca: 16 d0 rcall .+44 ; 0xf8 - uart0_sendChar(c); - cc: 0f d0 rcall .+30 ; 0xec + spi_masterInit(); // Initialize spi module + displayDriverInit(); // Initialize display chip - //uart0_sendChar('*'); + for(int i=-999; i<=9999; i++) + d8: c9 e1 ldi r28, 0x19 ; 25 + da: dc ef ldi r29, 0xFC ; 252 + dc: 0e c0 rjmp .+28 ; 0xfa + { + writeLedDisplay(i); + de: ce 01 movw r24, r28 + e0: 73 d0 rcall .+230 ; 0x1c8 + wait(5); + e2: 85 e0 ldi r24, 0x05 ; 5 + e4: 90 e0 ldi r25, 0x00 ; 0 + e6: db df rcall .-74 ; 0x9e + e8: ce 01 movw r24, r28 + ea: 87 50 subi r24, 0x07 ; 7 + ec: 9f 4f sbci r25, 0xFF ; 255 + + if(i < -150 && i > -250) + ee: 83 36 cpi r24, 0x63 ; 99 + f0: 91 05 cpc r25, r1 + f2: 18 f4 brcc .+6 ; 0xfa + wait(75); + f4: 8b e4 ldi r24, 0x4B ; 75 + f6: 90 e0 ldi r25, 0x00 ; 0 + f8: d2 df rcall .-92 ; 0x9e + fa: ce 01 movw r24, r28 + fc: 87 59 subi r24, 0x97 ; 151 + fe: 91 09 sbc r25, r1 + + if(i > 150 && i < 250) + 100: 83 36 cpi r24, 0x63 ; 99 + 102: 91 05 cpc r25, r1 + 104: 18 f4 brcc .+6 ; 0x10c + wait(75); + 106: 8b e4 ldi r24, 0x4B ; 75 + 108: 90 e0 ldi r25, 0x00 ; 0 + 10a: c9 df rcall .-110 ; 0x9e + DDRB=0x01; // Set PB0 pin as output for display select + + spi_masterInit(); // Initialize spi module + displayDriverInit(); // Initialize display chip + + for(int i=-999; i<=9999; i++) + 10c: 21 96 adiw r28, 0x01 ; 1 + 10e: c0 31 cpi r28, 0x10 ; 16 + 110: 87 e2 ldi r24, 0x27 ; 39 + 112: d8 07 cpc r29, r24 + 114: 21 f7 brne .-56 ; 0xde + if(i > 150 && i < 250) + wait(75); } - ce: fa cf rjmp .-12 ; 0xc4 -000000d0
: + + 116: df 91 pop r29 + 118: cf 91 pop r28 + 11a: 08 95 ret + +0000011c
: + + //opgaveb3(); + //opgaveb4(); + + //test(); + test2(); + 11c: d1 df rcall .-94 ; 0xc0 + return 0; +} + 11e: 80 e0 ldi r24, 0x00 ; 0 + 120: 90 e0 ldi r25, 0x00 ; 0 + 122: 08 95 ret + +00000124 : +void displayOff() +{ + spi_slaveSelect(0); // Select display chip + spi_write(0x0C); // Register 0B: Shutdown register + spi_write(0x00); // -> 1 = Normal operation + spi_slaveDeSelect(0); // Deselect display chip + 124: 8f ef ldi r24, 0xFF ; 255 + 126: 87 bb out 0x17, r24 ; 23 + 128: bb 98 cbi 0x17, 3 ; 23 + 12a: c0 9a sbi 0x18, 0 ; 24 + 12c: 82 e5 ldi r24, 0x52 ; 82 + 12e: 8d b9 out 0x0d, r24 ; 13 + 130: 08 95 ret + +00000132 : + 132: 8f b9 out 0x0f, r24 ; 15 + 134: 77 9b sbis 0x0e, 7 ; 14 + 136: fe cf rjmp .-4 ; 0x134 + 138: 08 95 ret + +0000013a : + 13a: 98 b3 in r25, 0x18 ; 24 + 13c: 21 e0 ldi r18, 0x01 ; 1 + 13e: 30 e0 ldi r19, 0x00 ; 0 + 140: 02 c0 rjmp .+4 ; 0x146 + 142: 22 0f add r18, r18 + 144: 33 1f adc r19, r19 + 146: 8a 95 dec r24 + 148: e2 f7 brpl .-8 ; 0x142 + 14a: 20 95 com r18 + 14c: 29 23 and r18, r25 + 14e: 28 bb out 0x18, r18 ; 24 + 150: 08 95 ret + +00000152 : + 152: 98 b3 in r25, 0x18 ; 24 + 154: 21 e0 ldi r18, 0x01 ; 1 + 156: 30 e0 ldi r19, 0x00 ; 0 + 158: 02 c0 rjmp .+4 ; 0x15e + 15a: 22 0f add r18, r18 + 15c: 33 1f adc r19, r19 + 15e: 8a 95 dec r24 + 160: e2 f7 brpl .-8 ; 0x15a + 162: 29 2b or r18, r25 + 164: 28 bb out 0x18, r18 ; 24 + 166: 08 95 ret + +00000168 : + 168: 80 e0 ldi r24, 0x00 ; 0 + 16a: e7 df rcall .-50 ; 0x13a + 16c: 89 e0 ldi r24, 0x09 ; 9 + 16e: e1 df rcall .-62 ; 0x132 + 170: 8f ef ldi r24, 0xFF ; 255 + 172: df df rcall .-66 ; 0x132 + 174: 80 e0 ldi r24, 0x00 ; 0 + 176: ed df rcall .-38 ; 0x152 + 178: 80 e0 ldi r24, 0x00 ; 0 + 17a: df df rcall .-66 ; 0x13a + 17c: 8a e0 ldi r24, 0x0A ; 10 + 17e: d9 df rcall .-78 ; 0x132 + 180: 8f e0 ldi r24, 0x0F ; 15 + 182: d7 df rcall .-82 ; 0x132 + 184: 80 e0 ldi r24, 0x00 ; 0 + 186: e5 df rcall .-54 ; 0x152 + 188: 80 e0 ldi r24, 0x00 ; 0 + 18a: d7 df rcall .-82 ; 0x13a + 18c: 8b e0 ldi r24, 0x0B ; 11 + 18e: d1 df rcall .-94 ; 0x132 + 190: 83 e0 ldi r24, 0x03 ; 3 + 192: cf df rcall .-98 ; 0x132 + 194: 80 e0 ldi r24, 0x00 ; 0 + 196: dd df rcall .-70 ; 0x152 + 198: 80 e0 ldi r24, 0x00 ; 0 + 19a: cf df rcall .-98 ; 0x13a + 19c: 8c e0 ldi r24, 0x0C ; 12 + 19e: c9 df rcall .-110 ; 0x132 + 1a0: 81 e0 ldi r24, 0x01 ; 1 + 1a2: c7 df rcall .-114 ; 0x132 + 1a4: 80 e0 ldi r24, 0x00 ; 0 + 1a6: d5 cf rjmp .-86 ; 0x152 + 1a8: 08 95 ret + +000001aa : +} + +void spi_writeWord( unsigned char adress, unsigned char data ) +{ + 1aa: cf 93 push r28 + 1ac: df 93 push r29 + 1ae: d8 2f mov r29, r24 + 1b0: c6 2f mov r28, r22 + spi_slaveSelect(0); // Select display chip + 1b2: 80 e0 ldi r24, 0x00 ; 0 + 1b4: c2 df rcall .-124 ; 0x13a + spi_write(adress); // Write address + 1b6: 8d 2f mov r24, r29 + 1b8: bc df rcall .-136 ; 0x132 + spi_write(data); // Write data + 1ba: 8c 2f mov r24, r28 + 1bc: ba df rcall .-140 ; 0x132 + spi_slaveDeSelect(0); // Deselect display chip + 1be: 80 e0 ldi r24, 0x00 ; 0 + 1c0: c8 df rcall .-112 ; 0x152 +} + 1c2: df 91 pop r29 + 1c4: cf 91 pop r28 + 1c6: 08 95 ret + +000001c8 : + +void writeLedDisplay( int value ) +{ + 1c8: cf 93 push r28 + 1ca: df 93 push r29 + if(value > 9999 || value < -999) + 1cc: 9c 01 movw r18, r24 + 1ce: 29 51 subi r18, 0x19 ; 25 + 1d0: 3c 4f sbci r19, 0xFC ; 252 + 1d2: 27 3f cpi r18, 0xF7 ; 247 + 1d4: 3a 42 sbci r19, 0x2A ; 42 + 1d6: 08 f5 brcc .+66 ; 0x21a + return; + + if(value < 0) + 1d8: 99 23 and r25, r25 + 1da: 44 f4 brge .+16 ; 0x1ec + { + value = value - (value + value); + 1dc: cc 27 eor r28, r28 + 1de: dd 27 eor r29, r29 + 1e0: c8 1b sub r28, r24 + 1e2: d9 0b sbc r29, r25 + spi_writeWord(4, 10); + 1e4: 6a e0 ldi r22, 0x0A ; 10 + 1e6: 84 e0 ldi r24, 0x04 ; 4 + 1e8: e0 df rcall .-64 ; 0x1aa + 1ea: 06 c0 rjmp .+12 ; 0x1f8 + } + else + { + //Display 4 + int d4 = value / 1000; + value = value % 1000; + 1ec: 68 ee ldi r22, 0xE8 ; 232 + 1ee: 73 e0 ldi r23, 0x03 ; 3 + 1f0: 17 d0 rcall .+46 ; 0x220 <__divmodhi4> + 1f2: ec 01 movw r28, r24 + spi_writeWord(4, d4); + 1f4: 84 e0 ldi r24, 0x04 ; 4 + 1f6: d9 df rcall .-78 ; 0x1aa } -} -int main( void ) -{ - opgaveb1(); - d0: f7 df rcall .-18 ; 0xc0 + //Display 3 + int d3 = value / 100; + value = value % 100; + 1f8: ce 01 movw r24, r28 + 1fa: 64 e6 ldi r22, 0x64 ; 100 + 1fc: 70 e0 ldi r23, 0x00 ; 0 + 1fe: 10 d0 rcall .+32 ; 0x220 <__divmodhi4> + 200: ec 01 movw r28, r24 + spi_writeWord(3, d3); + 202: 83 e0 ldi r24, 0x03 ; 3 + 204: d2 df rcall .-92 ; 0x1aa -000000d2 : + //Display 2 + int d2 = value / 10; + 206: ce 01 movw r24, r28 + 208: 6a e0 ldi r22, 0x0A ; 10 + 20a: 70 e0 ldi r23, 0x00 ; 0 + 20c: 09 d0 rcall .+18 ; 0x220 <__divmodhi4> + 20e: c8 2f mov r28, r24 + value = value % 10; + spi_writeWord(2, d2); + 210: 82 e0 ldi r24, 0x02 ; 2 + 212: cb df rcall .-106 ; 0x1aa + //Display 1 + int d1 = value; + spi_writeWord(1, d1); + 214: 6c 2f mov r22, r28 + 216: 81 e0 ldi r24, 0x01 ; 1 + 218: c8 df rcall .-112 ; 0x1aa + 21a: df 91 pop r29 + 21c: cf 91 pop r28 + 21e: 08 95 ret -void usart0_init( void ) // initialize USART0 - receive/transmit -{ - int ubrr = MYUBRR; - UBRR0H = ubrr>>8; // baudrate register, hoge byte - d2: 10 92 90 00 sts 0x0090, r1 - UBRR0L = ubrr; // baudrate register, lage byte - d6: 83 e3 ldi r24, 0x33 ; 51 - d8: 89 b9 out 0x09, r24 ; 9 - UCSR0C = 0b00000110; // asynchroon, 8 data - 1 stop - no parity - da: 86 e0 ldi r24, 0x06 ; 6 - dc: 80 93 95 00 sts 0x0095, r24 - UCSR0B = 0b00000000; // receiver & transmitter enable - e0: 1a b8 out 0x0a, r1 ; 10 - e2: 08 95 ret +00000220 <__divmodhi4>: + 220: 97 fb bst r25, 7 + 222: 07 2e mov r0, r23 + 224: 16 f4 brtc .+4 ; 0x22a <__divmodhi4+0xa> + 226: 00 94 com r0 + 228: 06 d0 rcall .+12 ; 0x236 <__divmodhi4_neg1> + 22a: 77 fd sbrc r23, 7 + 22c: 08 d0 rcall .+16 ; 0x23e <__divmodhi4_neg2> + 22e: 0b d0 rcall .+22 ; 0x246 <__udivmodhi4> + 230: 07 fc sbrc r0, 7 + 232: 05 d0 rcall .+10 ; 0x23e <__divmodhi4_neg2> + 234: 3e f4 brtc .+14 ; 0x244 <__divmodhi4_exit> -000000e4 : -} +00000236 <__divmodhi4_neg1>: + 236: 90 95 com r25 + 238: 81 95 neg r24 + 23a: 9f 4f sbci r25, 0xFF ; 255 + 23c: 08 95 ret -void usart0_start( void ) // receiver & transmitter enable -{ - UCSR0B |= BIT(RXEN)|BIT(TXEN); // set bit RXEN = Receiver enable and TXEN = Transmitter enable - e4: 8a b1 in r24, 0x0a ; 10 - e6: 88 61 ori r24, 0x18 ; 24 - e8: 8a b9 out 0x0a, r24 ; 10 - ea: 08 95 ret +0000023e <__divmodhi4_neg2>: + 23e: 70 95 com r23 + 240: 61 95 neg r22 + 242: 7f 4f sbci r23, 0xFF ; 255 -000000ec : -} +00000244 <__divmodhi4_exit>: + 244: 08 95 ret -int uart0_sendChar( char ch ) -{ - while (!(UCSR0A & BIT(UDRE0))) ; // wait until UDRE0 is set: transmit buffer is ready - ec: 5d 9b sbis 0x0b, 5 ; 11 - ee: fe cf rjmp .-4 ; 0xec - UDR0 = ch; // send ch - f0: 8c b9 out 0x0c, r24 ; 12 - return 0; // OK -} - f2: 80 e0 ldi r24, 0x00 ; 0 - f4: 90 e0 ldi r25, 0x00 ; 0 - f6: 08 95 ret +00000246 <__udivmodhi4>: + 246: aa 1b sub r26, r26 + 248: bb 1b sub r27, r27 + 24a: 51 e1 ldi r21, 0x11 ; 17 + 24c: 07 c0 rjmp .+14 ; 0x25c <__udivmodhi4_ep> -000000f8 : +0000024e <__udivmodhi4_loop>: + 24e: aa 1f adc r26, r26 + 250: bb 1f adc r27, r27 + 252: a6 17 cp r26, r22 + 254: b7 07 cpc r27, r23 + 256: 10 f0 brcs .+4 ; 0x25c <__udivmodhi4_ep> + 258: a6 1b sub r26, r22 + 25a: b7 0b sbc r27, r23 -char uart0_receiveChar( void ) -{ - while (!(UCSR0A & BIT(RXC0))) ; // if RX0 is set: unread data present in buffer - f8: 5f 9b sbis 0x0b, 7 ; 11 - fa: fe cf rjmp .-4 ; 0xf8 - return UDR0; // read ch - fc: 8c b1 in r24, 0x0c ; 12 -} - fe: 08 95 ret +0000025c <__udivmodhi4_ep>: + 25c: 88 1f adc r24, r24 + 25e: 99 1f adc r25, r25 + 260: 5a 95 dec r21 + 262: a9 f7 brne .-22 ; 0x24e <__udivmodhi4_loop> + 264: 80 95 com r24 + 266: 90 95 com r25 + 268: bc 01 movw r22, r24 + 26a: cd 01 movw r24, r26 + 26c: 08 95 ret -00000100 <_exit>: - 100: f8 94 cli +0000026e <_exit>: + 26e: f8 94 cli -00000102 <__stop_program>: - 102: ff cf rjmp .-2 ; 0x102 <__stop_program> +00000270 <__stop_program>: + 270: ff cf rjmp .-2 ; 0x270 <__stop_program> diff --git a/MIC-Week5/Debug/MIC-Week5.map b/MIC-Week5/Debug/MIC-Week5.map index 1ad2dfa..37ed8b3 100644 --- a/MIC-Week5/Debug/MIC-Week5.map +++ b/MIC-Week5/Debug/MIC-Week5.map @@ -1,7 +1,11 @@ Archive member included to satisfy reference by file (symbol) +c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + spi.o (__divmodhi4) c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/1.0.91/gcc/dev/atmega128/avr51/crtatmega128.o (exit) +c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) (__udivmodhi4) Discarded input sections @@ -37,13 +41,61 @@ Discarded input sections .text 0x00000000 0x0 main.o .data 0x00000000 0x0 main.o .bss 0x00000000 0x0 main.o + .text.opgaveb1 + 0x00000000 0x24 main.o .text.opgaveb2 0x00000000 0x50 main.o + .text.opgaveb3 + 0x00000000 0x6e main.o + .text.opgaveb4 + 0x00000000 0x72 main.o + .text.test 0x00000000 0x50 main.o + .text 0x00000000 0x0 spi.o + .data 0x00000000 0x0 spi.o + .bss 0x00000000 0x0 spi.o + .text.spi_writeRead + 0x00000000 0xa spi.o + .text.displayOn + 0x00000000 0x1a spi.o + .text.displayOff + 0x00000000 0x1a spi.o .text 0x00000000 0x0 uart0.o .data 0x00000000 0x0 uart0.o .bss 0x00000000 0x0 uart0.o + .text.usart0_init + 0x00000000 0x12 uart0.o + .text.usart0_start + 0x00000000 0x8 uart0.o + .text.uart0_sendChar + 0x00000000 0xc uart0.o + .text.uart0_receiveChar + 0x00000000 0x8 uart0.o .text.uart0_receiveString 0x00000000 0x26 uart0.o + .debug_info 0x00000000 0x152 uart0.o + .debug_abbrev 0x00000000 0x11c uart0.o + .debug_loc 0x00000000 0xe0 uart0.o + .debug_aranges + 0x00000000 0x40 uart0.o + .debug_ranges 0x00000000 0x30 uart0.o + .debug_line 0x00000000 0x144 uart0.o + .debug_str 0x00000000 0x1c0 uart0.o + .comment 0x00000000 0x31 uart0.o + .debug_frame 0x00000000 0x78 uart0.o + .text 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .data 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .bss 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .text.libgcc.mul + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .text.libgcc 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .text.libgcc.prologue + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .text.libgcc.builtins + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .text.libgcc.fmul + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + .text.libgcc.fixed + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) .text 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) .data 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) .bss 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) @@ -60,6 +112,20 @@ Discarded input sections 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) .text.libgcc.fixed 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) + .text 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .data 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .bss 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .text.libgcc.mul + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .text.libgcc 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .text.libgcc.prologue + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .text.libgcc.builtins + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .text.libgcc.fmul + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + .text.libgcc.fixed + 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) Memory Configuration @@ -79,6 +145,7 @@ Address of section .data set to 0x800100 LOAD C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/1.0.91/gcc/dev/atmega128/avr51/crtatmega128.o LOAD lcd.o LOAD main.o +LOAD spi.o LOAD uart0.o START GROUP LOAD c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr51\libm.a @@ -180,7 +247,7 @@ END GROUP .rela.plt *(.rela.plt) -.text 0x00000000 0x104 +.text 0x00000000 0x272 *(.vectors) .vectors 0x00000000 0x8c C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/1.0.91/gcc/dev/atmega128/avr51/crtatmega128.o 0x00000000 __vector_default @@ -272,28 +339,43 @@ END GROUP *(.text.*) .text.wait 0x0000009e 0x22 main.o 0x0000009e wait - .text.opgaveb1 - 0x000000c0 0x10 main.o - 0x000000c0 opgaveb1 - .text.main 0x000000d0 0x2 main.o - 0x000000d0 main - .text.usart0_init - 0x000000d2 0x12 uart0.o - 0x000000d2 usart0_init - .text.usart0_start - 0x000000e4 0x8 uart0.o - 0x000000e4 usart0_start - .text.uart0_sendChar - 0x000000ec 0xc uart0.o - 0x000000ec uart0_sendChar - .text.uart0_receiveChar - 0x000000f8 0x8 uart0.o - 0x000000f8 uart0_receiveChar - 0x00000100 . = ALIGN (0x2) + .text.test2 0x000000c0 0x5c main.o + 0x000000c0 test2 + .text.main 0x0000011c 0x8 main.o + 0x0000011c main + .text.spi_masterInit + 0x00000124 0xe spi.o + 0x00000124 spi_masterInit + .text.spi_write + 0x00000132 0x8 spi.o + 0x00000132 spi_write + .text.spi_slaveSelect + 0x0000013a 0x18 spi.o + 0x0000013a spi_slaveSelect + .text.spi_slaveDeSelect + 0x00000152 0x16 spi.o + 0x00000152 spi_slaveDeSelect + .text.displayDriverInit + 0x00000168 0x42 spi.o + 0x00000168 displayDriverInit + .text.spi_writeWord + 0x000001aa 0x1e spi.o + 0x000001aa spi_writeWord + .text.writeLedDisplay + 0x000001c8 0x58 spi.o + 0x000001c8 writeLedDisplay + .text.libgcc.div + 0x00000220 0x26 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_divmodhi4.o) + 0x00000220 _div + 0x00000220 __divmodhi4 + .text.libgcc.div + 0x00000246 0x28 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_udivmodhi4.o) + 0x00000246 __udivmodhi4 + 0x0000026e . = ALIGN (0x2) *(.fini9) - .fini9 0x00000100 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) - 0x00000100 _exit - 0x00000100 exit + .fini9 0x0000026e 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) + 0x0000026e _exit + 0x0000026e exit *(.fini9) *(.fini8) *(.fini8) @@ -312,11 +394,11 @@ END GROUP *(.fini1) *(.fini1) *(.fini0) - .fini0 0x00000100 0x4 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) + .fini0 0x0000026e 0x4 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avr51\libgcc.a(_exit.o) *(.fini0) - 0x00000104 _etext = . + 0x00000272 _etext = . -.data 0x00800100 0x0 load address 0x00000104 +.data 0x00800100 0x0 load address 0x00000272 0x00800100 PROVIDE (__data_start, .) *(.data) *(.data*) @@ -333,8 +415,8 @@ END GROUP *(.bss*) *(COMMON) 0x00800100 PROVIDE (__bss_end, .) - 0x00000104 __data_load_start = LOADADDR (.data) - 0x00000104 __data_load_end = (__data_load_start + SIZEOF (.data)) + 0x00000272 __data_load_start = LOADADDR (.data) + 0x00000272 __data_load_end = (__data_load_start + SIZEOF (.data)) .noinit 0x00800100 0x0 0x00800100 PROVIDE (__noinit_start, .) @@ -384,7 +466,7 @@ END GROUP *(.comment) .comment 0x00000000 0x30 main.o 0x31 (size before relaxing) - .comment 0x00000030 0x31 uart0.o + .comment 0x00000030 0x31 spi.o .note.gnu.avr.deviceinfo 0x00000000 0x3c @@ -406,47 +488,47 @@ END GROUP .debug_sfnames *(.debug_sfnames) -.debug_aranges 0x00000000 0x78 +.debug_aranges 0x00000000 0xc0 *(.debug_aranges) .debug_aranges - 0x00000000 0x38 main.o + 0x00000000 0x58 main.o .debug_aranges - 0x00000038 0x40 uart0.o + 0x00000058 0x68 spi.o .debug_pubnames *(.debug_pubnames) -.debug_info 0x00000000 0x4a3 +.debug_info 0x00000000 0xcbd *(.debug_info .gnu.linkonce.wi.*) - .debug_info 0x00000000 0x351 main.o - .debug_info 0x00000351 0x152 uart0.o + .debug_info 0x00000000 0x835 main.o + .debug_info 0x00000835 0x488 spi.o -.debug_abbrev 0x00000000 0x2f6 +.debug_abbrev 0x00000000 0x327 *(.debug_abbrev) - .debug_abbrev 0x00000000 0x1da main.o - .debug_abbrev 0x000001da 0x11c uart0.o + .debug_abbrev 0x00000000 0x1ed main.o + .debug_abbrev 0x000001ed 0x13a spi.o -.debug_line 0x00000000 0x325 +.debug_line 0x00000000 0x66f *(.debug_line .debug_line.* .debug_line_end) - .debug_line 0x00000000 0x1e1 main.o - .debug_line 0x000001e1 0x144 uart0.o + .debug_line 0x00000000 0x3f5 main.o + .debug_line 0x000003f5 0x27a spi.o -.debug_frame 0x00000000 0xdc +.debug_frame 0x00000000 0x190 *(.debug_frame) - .debug_frame 0x00000000 0x64 main.o - .debug_frame 0x00000064 0x78 uart0.o + .debug_frame 0x00000000 0xc4 main.o + .debug_frame 0x000000c4 0xcc spi.o -.debug_str 0x00000000 0x22e +.debug_str 0x00000000 0x2e3 *(.debug_str) - .debug_str 0x00000000 0x208 main.o - 0x241 (size before relaxing) - .debug_str 0x00000208 0x26 uart0.o - 0x1c0 (size before relaxing) + .debug_str 0x00000000 0x28a main.o + 0x2c3 (size before relaxing) + .debug_str 0x0000028a 0x59 spi.o + 0x20a (size before relaxing) -.debug_loc 0x00000000 0x1a4 +.debug_loc 0x00000000 0x43c *(.debug_loc) - .debug_loc 0x00000000 0xc4 main.o - .debug_loc 0x000000c4 0xe0 uart0.o + .debug_loc 0x00000000 0x235 main.o + .debug_loc 0x00000235 0x207 spi.o .debug_macinfo *(.debug_macinfo) @@ -466,10 +548,10 @@ END GROUP .debug_pubtypes *(.debug_pubtypes) -.debug_ranges 0x00000000 0x58 +.debug_ranges 0x00000000 0xa0 *(.debug_ranges) - .debug_ranges 0x00000000 0x28 main.o - .debug_ranges 0x00000028 0x30 uart0.o + .debug_ranges 0x00000000 0x48 main.o + .debug_ranges 0x00000048 0x58 spi.o .debug_macro *(.debug_macro) diff --git a/MIC-Week5/Debug/MIC-Week5.srec b/MIC-Week5/Debug/MIC-Week5.srec index 41134af..dfd7aff 100644 --- a/MIC-Week5/Debug/MIC-Week5.srec +++ b/MIC-Week5/Debug/MIC-Week5.srec @@ -8,12 +8,35 @@ S113005025C0000023C0000021C000001FC0000014 S11300601DC000001BC0000019C0000017C0000024 S113007015C0000013C0000011C000000FC0000034 S11300800DC000000BC0000009C0000011241FBEF9 -S1130090CFEFD0E1DEBFCDBF1BD032C0B1CF181639 +S1130090CFEFD0E1DEBFCDBF41D0E9C0B1CF18165C S11300A019066CF420E030E0EFECF7E03197F1F75B S11300B000C000002F5F3F4F28173907A9F70895A4 -S11300C008D010D082E390E0EADF16D00FD0FACF48 -S11300D0F7DF1092900083E389B986E0809395005E -S11300E01AB808958AB188618AB908955D9BFECFD4 -S11300F08CB980E090E008955F9BFECF8CB10895A9 -S1070100F894FFCF9D +S11300C0CF93DF9381E087BB2DD04ED089E19CEFA5 +S11300D07BD085E090E0E3DFC9E1DCEF0EC0CE0128 +S11300E073D085E090E0DBDFCE0187509F4F8336ED +S11300F0910518F48BE490E0D2DFCE018759910981 +S11301008336910518F48BE490E0C9DF2196C03161 +S113011087E2D80721F7DF91CF910895D1DF80E0FE +S113012090E008958FEF87BBBB98C09A82E58DB9A4 +S113013008958FB9779BFECF089598B321E030E0FE +S113014002C0220F331F8A95E2F72095292328BB8A +S1130150089598B321E030E002C0220F331F8A953E +S1130160E2F7292B28BB089580E0E7DF89E0E1DF8F +S11301708FEFDFDF80E0EDDF80E0DFDF8AE0D9DFD3 +S11301808FE0D7DF80E0E5DF80E0D7DF8BE0D1DFF1 +S113019083E0CFDF80E0DDDF80E0CFDF8CE0C9DF0C +S11301A081E0C7DF80E0D5CF0895CF93DF93D82FC8 +S11301B0C62F80E0C2DF8D2FBCDF8C2FBADF80E03A +S11301C0C8DFDF91CF910895CF93DF939C0129512C +S11301D03C4F273F3A4208F5992344F4CC27DD27C6 +S11301E0C81BD90B6AE084E0E0DF06C068EE73E068 +S11301F017D0EC0184E0D9DFCE0164E670E010D0C2 +S1130200EC0183E0D2DFCE016AE070E009D0C82FB0 +S113021082E0CBDF6C2F81E0C8DFDF91CF910895BE +S113022097FB072E16F4009406D077FD08D00BD068 +S113023007FC05D03EF4909581959F4F08957095E5 +S113024061957F4F0895AA1BBB1B51E107C0AA1FEC +S1130250BB1FA617B70710F0A61BB70B881F991F63 +S11302605A95A9F780959095BC01CD010895F8940D +S1050270FFCFBA S9030000FC diff --git a/MIC-Week5/Debug/Makefile b/MIC-Week5/Debug/Makefile index 294e483..12b86c8 100644 --- a/MIC-Week5/Debug/Makefile +++ b/MIC-Week5/Debug/Makefile @@ -39,6 +39,7 @@ SUBDIRS := C_SRCS += \ ../lcd.c \ ../main.c \ +../spi.c \ ../uart0.c @@ -51,21 +52,25 @@ ASM_SRCS += OBJS += \ lcd.o \ main.o \ +spi.o \ uart0.o OBJS_AS_ARGS += \ lcd.o \ main.o \ +spi.o \ uart0.o C_DEPS += \ lcd.d \ main.d \ +spi.d \ uart0.d C_DEPS_AS_ARGS += \ lcd.d \ main.d \ +spi.d \ uart0.d OUTPUT_FILE_PATH +=MIC-Week5.elf @@ -89,6 +94,8 @@ LINKER_SCRIPT_DEP+= + + ./%.o: .././%.c @echo Building file: $< @echo Invoking: AVR/GNU C Compiler : 4.9.2 diff --git a/MIC-Week5/Debug/main.d b/MIC-Week5/Debug/main.d index 70f8456..b1141cd 100644 --- a/MIC-Week5/Debug/main.d +++ b/MIC-Week5/Debug/main.d @@ -14,7 +14,7 @@ main.d main.o: .././main.c .././uart0.h \ c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\util\delay_basic.h \ c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\math.h \ c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\interrupt.h \ - .././lcd.h + .././lcd.h .././spi.h .././uart0.h: @@ -49,3 +49,5 @@ 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\interrupt.h: .././lcd.h: + +.././spi.h: diff --git a/MIC-Week5/Debug/makedep.mk b/MIC-Week5/Debug/makedep.mk index e31f8b7..1ca791d 100644 --- a/MIC-Week5/Debug/makedep.mk +++ b/MIC-Week5/Debug/makedep.mk @@ -6,5 +6,7 @@ lcd.c main.c +spi.c + uart0.c diff --git a/MIC-Week5/Debug/spi.d b/MIC-Week5/Debug/spi.d new file mode 100644 index 0000000..e68ca70 --- /dev/null +++ b/MIC-Week5/Debug/spi.d @@ -0,0 +1,46 @@ +spi.d spi.o: .././spi.c \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\4.9.2\include\stdint.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h \ + C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.0.91\include/avr/iom128.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h \ + 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\util\delay.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\util\delay_basic.h \ + c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\math.h \ + .././spi.h + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\4.9.2\include\stdint.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h: + +C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.0.91\include/avr/iom128.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h: + +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\util\delay.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\util\delay_basic.h: + +c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\math.h: + +.././spi.h: diff --git a/MIC-Week5/MIC-Week5.cproj b/MIC-Week5/MIC-Week5.cproj index f4798e4..2fcf781 100644 --- a/MIC-Week5/MIC-Week5.cproj +++ b/MIC-Week5/MIC-Week5.cproj @@ -28,85 +28,85 @@ 1 - - - - - - - - - + + + + + + + + + - -mmcu=atmega128 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\gcc\dev\atmega128" - True - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include - - - Optimize for size (-Os) - True - True - True - - - libm - - - + -mmcu=atmega128 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\gcc\dev\atmega128" + True + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + - -mmcu=atmega128 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\gcc\dev\atmega128" - True - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - + -mmcu=atmega128 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\gcc\dev\atmega128" + True + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + @@ -119,6 +119,12 @@ compile + + compile + + + compile + compile diff --git a/MIC-Week5/main.c b/MIC-Week5/main.c index cfc7951..f258215 100644 --- a/MIC-Week5/main.c +++ b/MIC-Week5/main.c @@ -17,6 +17,7 @@ #include "uart0.h" #include "lcd.h" +#include "spi.h" // wait(): busy waiting for 'ms' millisecond // Used library: util/delay.h @@ -30,9 +31,14 @@ void wait( int ms ) int main( void ) { - opgaveb1(); + //opgaveb1(); //opgaveb2(); + //opgaveb3(); + //opgaveb4(); + + //test(); + test2(); return 0; } @@ -48,6 +54,11 @@ int opgaveb1( void ) wait(50); // every 50 ms (busy waiting) char c = uart0_receiveChar(); // receive string from uart + + if(c >= 'a' && c <= 'z'){ + c = ('A' + c - 'a'); + } + uart0_sendChar(c); //uart0_sendChar('*'); @@ -75,4 +86,114 @@ int opgaveb2( void ) clear_display(); display_text(0, buffer, 3); } +} + +int opgaveb3( void ) +{ + DDRB=0x01; // Set PB0 pin as output for display select + + spi_masterInit(); // Initialize spi module + displayDriverInit(); // Initialize display chip + + // clear display (all zero's) + for (char i =1; i<=4; i++) + { + spi_slaveSelect(0); // Select display chip + spi_write(i); // digit adress: (digit place) + spi_write(0); // digit value: 0 + spi_slaveDeSelect(0); // Deselect display chip + } + + wait(1000); + + // write 4-digit data + for (char i =1; i<=4; i++) + { + spi_slaveSelect(0); // Select display chip + spi_write(i); // digit adress: (digit place) + spi_write(i); // digit value: i (= digit place) + spi_slaveDeSelect(0); // Deselect display chip + wait(1000); + } + + wait(1000); + return (1); +} + +int opgaveb4( void ) +{ + DDRB=0x01; // Set PB0 pin as output for display select + + spi_masterInit(); // Initialize spi module + displayDriverInit(); // Initialize display chip + + int i = 4321; + writeLedDisplay(i); + + i = 1234; + wait(1000); + writeLedDisplay(i); + + i = 567; + wait(1000); + writeLedDisplay(i); + + i = 98; + wait(1000); + writeLedDisplay(i); + + i = -123; + wait(1000); + writeLedDisplay(i); + + i = -23; + wait(1000); + writeLedDisplay(i); + + wait(5000); + return (1); +} + +int test(void) +{ + DDRB=0x01; // Set PB0 pin as output for display select + + spi_masterInit(); // Initialize spi module + displayDriverInit(); // Initialize display chip + + for(int i=0; i<=127; i++) + { + writeLedDisplay(i); + + wait(10); + + spi_slaveSelect(0); // Select display chip + spi_write(4); // digit adress: (digit place) + spi_write(i); // digit value: i (= digit place) + spi_slaveDeSelect(0); // Deselect display chip + + wait(500); + } +} + +int test2(void) +{ + DDRB=0x01; // Set PB0 pin as output for display select + + spi_masterInit(); // Initialize spi module + displayDriverInit(); // Initialize display chip + + for(int i=-999; i<=9999; i++) + { + writeLedDisplay(i); + wait(5); + + if(i < -150 && i > -250) + wait(75); + + if(i > 150 && i < 250) + wait(75); + } + + } \ No newline at end of file diff --git a/MIC-Week5/spi.c b/MIC-Week5/spi.c new file mode 100644 index 0000000..11d04b9 --- /dev/null +++ b/MIC-Week5/spi.c @@ -0,0 +1,137 @@ +/* +* Project name : Demo5_7a : spi - 7 segments display +* Author : Avans-TI, WvdE, JW +* Revision History : 20110228: - initial release; 20120307: - this version +* Description : This program sends data to a 4-digit display with spi +* Test configuration: + MCU: ATmega128 + Dev.Board: BIGAVR6 + Oscillator: External Clock 08.0000 MHz + Ext. Modules: Serial 7-seg display + SW: AVR-GCC +* NOTES : Turn ON switch 15, PB1/PB2/PB3 to MISO/MOSI/SCK +*/ +#include +#include + +#include "spi.h" + +void spi_masterInit(void) +{ + DDR_SPI = 0xff; // All pins output: MOSI, SCK, SS, SS_display + DDR_SPI &= ~BIT(SPI_MISO); // except: MISO input + PORT_SPI |= BIT(SPI_SS); // SS_ADC == 1: deselect slave + SPCR = (1< starts transmission + while( !(SPSR & BIT(SPIF)) ); // Wait for transmission complete +} + +// Write a byte from master to slave and read a byte from slave - not used here +char spi_writeRead( unsigned char data ) +{ + SPDR = data; // Load byte --> starts transmission + + while( !(SPSR & BIT(SPIF)) ); // Wait for transmission complete + data = SPDR; // New received data (eventually, MISO) in SPDR + + return data; // Return received byte +} + +// Select device on pinnumer PORTB +void spi_slaveSelect(unsigned char chipNumber) +{ + PORTB &= ~BIT(chipNumber); +} + +// Deselect device on pinnumer PORTB +void spi_slaveDeSelect(unsigned char chipNumber) +{ + PORTB |= BIT(chipNumber); +} + +// Initialize the driver chip (type MAX 7219) +void displayDriverInit() +{ + spi_slaveSelect(0); // Select display chip (MAX7219) + spi_write(0x09); // Register 09: Decode Mode + spi_write(0xFF); // -> 1's = BCD mode for all digits + spi_slaveDeSelect(0); // Deselect display chip + spi_slaveSelect(0); // Select dispaly chip + spi_write(0x0A); // Register 0A: Intensity + spi_write(0x0F); // -> Level 4 (in range [1..F]) + spi_slaveDeSelect(0); // Deselect display chip + spi_slaveSelect(0); // Select display chip + spi_write(0x0B); // Register 0B: Scan-limit + spi_write(0x03); // -> 1 = Display digits 0..3 + spi_slaveDeSelect(0); // Deselect display chip + spi_slaveSelect(0); // Select display chip + spi_write(0x0C); // Register 0B: Shutdown register + spi_write(0x01); // -> 1 = Normal operation + spi_slaveDeSelect(0); // Deselect display chip +} + +// Set display on ('normal operation') +void displayOn() +{ + spi_slaveSelect(0); // Select display chip + spi_write(0x0C); // Register 0B: Shutdown register + spi_write(0x01); // -> 1 = Normal operation + spi_slaveDeSelect(0); // Deselect display chip +} + +// Set display off ('shut down') +void displayOff() +{ + spi_slaveSelect(0); // Select display chip + spi_write(0x0C); // Register 0B: Shutdown register + spi_write(0x00); // -> 1 = Normal operation + spi_slaveDeSelect(0); // Deselect display chip +} + +void spi_writeWord( unsigned char adress, unsigned char data ) +{ + spi_slaveSelect(0); // Select display chip + spi_write(adress); // Write address + spi_write(data); // Write data + spi_slaveDeSelect(0); // Deselect display chip +} + +void writeLedDisplay( int value ) +{ + if(value > 9999 || value < -999) + return; + + if(value < 0) + { + value = value - (value + value); + spi_writeWord(4, 10); + } + else + { + //Display 4 + int d4 = value / 1000; + value = value % 1000; + spi_writeWord(4, d4); + } + + //Display 3 + int d3 = value / 100; + value = value % 100; + spi_writeWord(3, d3); + + //Display 2 + int d2 = value / 10; + value = value % 10; + spi_writeWord(2, d2); + + //Display 1 + int d1 = value; + spi_writeWord(1, d1); +} \ No newline at end of file diff --git a/MIC-Week5/spi.h b/MIC-Week5/spi.h new file mode 100644 index 0000000..915addc --- /dev/null +++ b/MIC-Week5/spi.h @@ -0,0 +1,47 @@ +/* + * spi.h + * + * Created: 21-3-2016 15:05:54 + * Author: kenny + */ + + +#ifndef SPI_H_ +#define SPI_H_ + +/* +* Project name : Demo5_7a : spi - 7 segments display +* Author : Avans-TI, WvdE, JW +* Revision History : 20110228: - initial release; 20120307: - this version +* Description : This program sends data to a 4-digit display with spi +* Test configuration: + MCU: ATmega128 + Dev.Board: BIGAVR6 + Oscillator: External Clock 08.0000 MHz + Ext. Modules: Serial 7-seg display + SW: AVR-GCC +* NOTES : Turn ON switch 15, PB1/PB2/PB3 to MISO/MOSI/SCK +*/ +#define BIT(x) ( 1<