diff --git a/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.lss b/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.lss index bed2744..afcd37b 100644 --- a/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.lss +++ b/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.lss @@ -3,29 +3,29 @@ ultrasonicSensor.elf: file format elf32-avr Sections: Idx Name Size VMA LMA File off Algn - 0 .data 00000000 00800100 00800100 00000166 2**0 + 0 .data 00000002 00800100 0000017c 000001f0 2**0 CONTENTS, ALLOC, LOAD, DATA - 1 .text 00000112 00000000 00000000 00000054 2**1 + 1 .text 0000017c 00000000 00000000 00000074 2**1 CONTENTS, ALLOC, LOAD, READONLY, CODE - 2 .comment 00000030 00000000 00000000 00000166 2**0 + 2 .comment 00000030 00000000 00000000 000001f2 2**0 CONTENTS, READONLY - 3 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00000198 2**2 + 3 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00000224 2**2 CONTENTS, READONLY - 4 .debug_aranges 00000030 00000000 00000000 000001d4 2**0 + 4 .debug_aranges 00000040 00000000 00000000 00000260 2**0 CONTENTS, READONLY, DEBUGGING - 5 .debug_info 000009ad 00000000 00000000 00000204 2**0 + 5 .debug_info 00000a15 00000000 00000000 000002a0 2**0 CONTENTS, READONLY, DEBUGGING - 6 .debug_abbrev 0000084e 00000000 00000000 00000bb1 2**0 + 6 .debug_abbrev 000008a7 00000000 00000000 00000cb5 2**0 CONTENTS, READONLY, DEBUGGING - 7 .debug_line 0000030d 00000000 00000000 000013ff 2**0 + 7 .debug_line 00000384 00000000 00000000 0000155c 2**0 CONTENTS, READONLY, DEBUGGING - 8 .debug_frame 00000044 00000000 00000000 0000170c 2**2 + 8 .debug_frame 00000080 00000000 00000000 000018e0 2**2 CONTENTS, READONLY, DEBUGGING - 9 .debug_str 0000043a 00000000 00000000 00001750 2**0 + 9 .debug_str 00000498 00000000 00000000 00001960 2**0 CONTENTS, READONLY, DEBUGGING - 10 .debug_loc 000000d2 00000000 00000000 00001b8a 2**0 + 10 .debug_loc 0000013d 00000000 00000000 00001df8 2**0 CONTENTS, READONLY, DEBUGGING - 11 .debug_ranges 00000020 00000000 00000000 00001c5c 2**0 + 11 .debug_ranges 00000030 00000000 00000000 00001f35 2**0 CONTENTS, READONLY, DEBUGGING Disassembly of section .text: @@ -33,7 +33,7 @@ Disassembly of section .text: 00000000 <__vectors>: 0: 45 c0 rjmp .+138 ; 0x8c <__ctors_end> 2: 00 00 nop - 4: 58 c0 rjmp .+176 ; 0xb6 <__bad_interrupt> + 4: 82 c0 rjmp .+260 ; 0x10a <__vector_1> 6: 00 00 nop 8: 56 c0 rjmp .+172 ; 0xb6 <__bad_interrupt> a: 00 00 nop @@ -114,25 +114,25 @@ Disassembly of section .text: 98: 11 e0 ldi r17, 0x01 ; 1 9a: a0 e0 ldi r26, 0x00 ; 0 9c: b1 e0 ldi r27, 0x01 ; 1 - 9e: e2 e1 ldi r30, 0x12 ; 18 + 9e: ec e7 ldi r30, 0x7C ; 124 a0: f1 e0 ldi r31, 0x01 ; 1 a2: 00 e0 ldi r16, 0x00 ; 0 a4: 0b bf out 0x3b, r16 ; 59 a6: 02 c0 rjmp .+4 ; 0xac <__do_copy_data+0x14> a8: 07 90 elpm r0, Z+ aa: 0d 92 st X+, r0 - ac: a0 30 cpi r26, 0x00 ; 0 + ac: a2 30 cpi r26, 0x02 ; 2 ae: b1 07 cpc r27, r17 b0: d9 f7 brne .-10 ; 0xa8 <__do_copy_data+0x10> - b2: 1e d0 rcall .+60 ; 0xf0
- b4: 2c c0 rjmp .+88 ; 0x10e <_exit> + b2: 47 d0 rcall .+142 ; 0x142
+ b4: 61 c0 rjmp .+194 ; 0x178 <_exit> 000000b6 <__bad_interrupt>: b6: a4 cf rjmp .-184 ; 0x0 <__vectors> 000000b8 : - -#include "lcd_control.h" + +static enum interrupt_status int_stat = INTERRUPT_RISING; void wait_us(unsigned int us) { @@ -193,39 +193,133 @@ void wait_ms(unsigned int ms) } ee: 08 95 ret -000000f0
: +000000f0 : + +void ultrasonic_send_pulse() +{ + f0: cf 93 push r28 + f2: df 93 push r29 + PORTG = 0x00; // 10 us low pulse + f4: c5 e6 ldi r28, 0x65 ; 101 + f6: d0 e0 ldi r29, 0x00 ; 0 + f8: 18 82 st Y, r1 + wait_us(10); + fa: 8a e0 ldi r24, 0x0A ; 10 + fc: 90 e0 ldi r25, 0x00 ; 0 + fe: dc df rcall .-72 ; 0xb8 + PORTG = 0x01; + 100: 81 e0 ldi r24, 0x01 ; 1 + 102: 88 83 st Y, r24 +} + 104: df 91 pop r29 + 106: cf 91 pop r28 + 108: 08 95 ret + +0000010a <__vector_1>: + +ISR(INT0_vect) +{ + 10a: 1f 92 push r1 + 10c: 0f 92 push r0 + 10e: 0f b6 in r0, 0x3f ; 63 + 110: 0f 92 push r0 + 112: 11 24 eor r1, r1 + 114: 8f 93 push r24 + + // if the interrupt was generated on a rising edge (start sending echo) + if (int_stat == INTERRUPT_RISING) + 116: 80 91 00 01 lds r24, 0x0100 ; 0x800100 <__DATA_REGION_ORIGIN__> + 11a: 81 30 cpi r24, 0x01 ; 1 + 11c: 31 f4 brne .+12 ; 0x12a <__vector_1+0x20> + { + // set interrupt pin 0 on PORTD to falling edge + EICRA = 0x02; + 11e: 82 e0 ldi r24, 0x02 ; 2 + 120: 80 93 6a 00 sts 0x006A, r24 ; 0x80006a <__TEXT_REGION_LENGTH__+0x7e006a> + + // set interrupt status + int_stat = INTERRUPT_FALLING; + 124: 10 92 00 01 sts 0x0100, r1 ; 0x800100 <__DATA_REGION_ORIGIN__> + 128: 06 c0 rjmp .+12 ; 0x136 <__vector_1+0x2c> + } else + // else if it was generated on a falling edge (end sending echo) + { + // set interrupt pin 0 on PORTD to rising edge + EICRA = 0x03; + 12a: 83 e0 ldi r24, 0x03 ; 3 + 12c: 80 93 6a 00 sts 0x006A, r24 ; 0x80006a <__TEXT_REGION_LENGTH__+0x7e006a> + + // set interrupt status + int_stat = INTERRUPT_RISING; + 130: 81 e0 ldi r24, 0x01 ; 1 + 132: 80 93 00 01 sts 0x0100, r24 ; 0x800100 <__DATA_REGION_ORIGIN__> + } + +} + 136: 8f 91 pop r24 + 138: 0f 90 pop r0 + 13a: 0f be out 0x3f, r0 ; 63 + 13c: 0f 90 pop r0 + 13e: 1f 90 pop r1 + 140: 18 95 reti + +00000142
: int main(void) { - DDRG = 0x01; // port g pin 0 on output, 1 on input. 0 is trig, 1 is echo - f0: 81 e0 ldi r24, 0x01 ; 1 - f2: 80 93 64 00 sts 0x0064, r24 ; 0x800064 <__TEXT_REGION_LENGTH__+0x7e0064> + DDRG = 0xFF; // port g all output. pin 0 is trig, the rest is for debug + 142: 8f ef ldi r24, 0xFF ; 255 + 144: 80 93 64 00 sts 0x0064, r24 ; 0x800064 <__TEXT_REGION_LENGTH__+0x7e0064> + DDRD = 0x00; // port D pin 0 on input. 0 is echo and also interrupt + 148: 11 ba out 0x11, r1 ; 17 + DDRA = 0xFF; + 14a: 8a bb out 0x1a, r24 ; 26 + + EICRA |= 0x03; // interrupt PORTD on pin 0, rising edge + 14c: ea e6 ldi r30, 0x6A ; 106 + 14e: f0 e0 ldi r31, 0x00 ; 0 + 150: 80 81 ld r24, Z + 152: 83 60 ori r24, 0x03 ; 3 + 154: 80 83 st Z, r24 + + EIMSK |= 0x01; // enable interrupt on pin 0 (INT0) + 156: 89 b7 in r24, 0x39 ; 57 + 158: 81 60 ori r24, 0x01 ; 1 + 15a: 89 bf out 0x39, r24 ; 57 + + sei(); // turn on interrupt system + 15c: 78 94 sei /* Replace with your application code */ while (1) { - PORTG = 0x00; // 10 us low pulse - f6: c5 e6 ldi r28, 0x65 ; 101 - f8: d0 e0 ldi r29, 0x00 ; 0 - fa: 18 82 st Y, r1 - wait_us(10); - fc: 8a e0 ldi r24, 0x0A ; 10 - fe: 90 e0 ldi r25, 0x00 ; 0 - 100: db df rcall .-74 ; 0xb8 - PORTG = 0x01; - 102: 81 e0 ldi r24, 0x01 ; 1 - 104: 88 83 st Y, r24 + ultrasonic_send_pulse(); + 15e: c8 df rcall .-112 ; 0xf0 + if (int_stat == INTERRUPT_FALLING) + 160: 80 91 00 01 lds r24, 0x0100 ; 0x800100 <__DATA_REGION_ORIGIN__> + 164: 81 11 cpse r24, r1 + 166: 03 c0 rjmp .+6 ; 0x16e + { + PORTA = 0xFF; + 168: 8f ef ldi r24, 0xFF ; 255 + 16a: 8b bb out 0x1b, r24 ; 27 + 16c: 01 c0 rjmp .+2 ; 0x170 + } else { + PORTA = 0x00; + 16e: 1b ba out 0x1b, r1 ; 27 + } - wait_ms(100); - 106: 84 e6 ldi r24, 0x64 ; 100 - 108: 90 e0 ldi r25, 0x00 ; 0 - 10a: e3 df rcall .-58 ; 0xd2 - 10c: f4 cf rjmp .-24 ; 0xf6 + wait_ms(1000); + 170: 88 ee ldi r24, 0xE8 ; 232 + 172: 93 e0 ldi r25, 0x03 ; 3 + 174: ae df rcall .-164 ; 0xd2 + } + 176: f3 cf rjmp .-26 ; 0x15e -0000010e <_exit>: - 10e: f8 94 cli +00000178 <_exit>: + 178: f8 94 cli -00000110 <__stop_program>: - 110: ff cf rjmp .-2 ; 0x110 <__stop_program> +0000017a <__stop_program>: + 17a: ff cf rjmp .-2 ; 0x17a <__stop_program> diff --git a/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.srec b/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.srec index 6a916ec..6f6627c 100644 --- a/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.srec +++ b/Microcontrollers/ultrasonicSensor/Debug/ultrasonicSensor.srec @@ -1,5 +1,5 @@ S0180000756C747261736F6E696353656E736F722E737265634E -S113000045C0000058C0000056C0000054C00000A5 +S113000045C0000082C0000056C0000054C000007B S113001052C0000050C000004EC000004CC00000A0 S11300204AC0000048C0000046C0000044C00000B0 S113003042C0000040C000003EC000003CC00000C0 @@ -8,13 +8,20 @@ S113005032C0000030C000002EC000002CC00000E0 S11300602AC0000028C0000026C0000024C00000F0 S113007022C0000020C000001EC000001CC0000000 S11300801AC0000018C0000016C0000011241FBED2 -S1130090CFEFD0E1DEBFCDBF11E0A0E0B1E0E2E1FF -S11300A0F1E000E00BBF02C007900D92A030B10751 -S11300B0D9F71ED02CC0A4CF20E030E006C046E023 +S1130090CFEFD0E1DEBFCDBF11E0A0E0B1E0ECE7EF +S11300A0F1E000E00BBF02C007900D92A230B1074F +S11300B0D9F747D061C0A4CF20E030E006C046E0C5 S11300C04A95F1F700C02F5F3F4F28173907B8F35F S11300D0089520E030E008C0E7E8F3E13197F1F754 S11300E000C000002F5F3F4F28173907A8F3089579 -S11300F081E080936400C5E6D0E018828AE090E055 -S1130100DBDF81E0888384E690E0E3DFF4CFF894DA -S1050110FFCF1B +S11300F0CF93DF93C5E6D0E018828AE090E0DCDF9E +S113010081E08883DF91CF9108951F920F920FB6FB +S11301100F9211248F9380910001813031F482E099 +S113012080936A001092000106C083E080936A0005 +S113013081E0809300018F910F900FBE0F901F906C +S113014018958FEF8093640011BA8ABBEAE6F0E059 +S113015080818360808389B7816089BF7894C8DF98 +S113016080910001811103C08FEF8BBB01C01BBACA +S10F017088EE93E0AEDFF3CFF894FFCFED +S105017C01007C S9030000FC diff --git a/Microcontrollers/ultrasonicSensor/main.c b/Microcontrollers/ultrasonicSensor/main.c index 9919583..4108632 100644 --- a/Microcontrollers/ultrasonicSensor/main.c +++ b/Microcontrollers/ultrasonicSensor/main.c @@ -20,6 +20,7 @@ #include #include +#include #include "lcd_control.h" @@ -53,13 +54,22 @@ void ultrasonic_send_pulse() ISR(INT0_vect) { - // set interrupt pin 0 on PORTD to falling edge + + // if the interrupt was generated on a rising edge (start sending echo) if (int_stat == INTERRUPT_RISING) { + // set interrupt pin 0 on PORTD to falling edge + EICRA = 0x02; + // set interrupt status int_stat = INTERRUPT_FALLING; - } else { + } else + // else if it was generated on a falling edge (end sending echo) + { + // set interrupt pin 0 on PORTD to rising edge + EICRA = 0x03; + // set interrupt status int_stat = INTERRUPT_RISING; } @@ -68,7 +78,10 @@ ISR(INT0_vect) int main(void) { - DDRG = 0x01; // port g pin 0 on output, 1 on input. 0 is trig, 1 is echo + DDRG = 0xFF; // port g all output. pin 0 is trig, the rest is for debug + DDRD = 0x00; // port D pin 0 on input. 0 is echo and also interrupt + + DDRA = 0xFF; EICRA |= 0x03; // interrupt PORTD on pin 0, rising edge @@ -80,6 +93,12 @@ int main(void) while (1) { ultrasonic_send_pulse(); + if (int_stat == INTERRUPT_FALLING) + { + PORTA = 0xFF; + } else { + PORTA = 0x00; + } wait_ms(100); }