investigate why variable delay is not working

This commit is contained in:
Vineet K 2024-04-15 22:38:55 -04:00 committed by kar
parent fc85413fa9
commit 9d751dc020

51
main.c
View File

@ -9,6 +9,7 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#define F_CPU 16000000UL #define F_CPU 16000000UL
#define __DELAY_BACKWARD_COMPATIBLE__ /* to use variables with _delay_u/ms */
#include <util/delay.h> #include <util/delay.h>
#define P_RX 0 #define P_RX 0
@ -16,29 +17,29 @@
#define P_SPKR 2 #define P_SPKR 2
unsigned short freqs[] = { unsigned short freqs[] = {
100, 1 / 100 * 1e6 / 2,
200, 1 / 200 * 1e6 / 2,
250, 1 / 250 * 1e6 / 2,
300, 1 / 300 * 1e6 / 2,
350, 1 / 350 * 1e6 / 2,
400, 1 / 400 * 1e6 / 2,
500, 1 / 500 * 1e6 / 2,
600, 1 / 600 * 1e6 / 2,
700, 1 / 700 * 1e6 / 2,
750, 1 / 750 * 1e6 / 2,
1000, 1 / 1000 * 1e6 / 2,
1250, 1 / 1250 * 1e6 / 2,
1500, 1 / 1500 * 1e6 / 2,
1750, 1 / 1750 * 1e6 / 2,
2000, 1 / 2000 * 1e6 / 2,
3000, 1 / 3000 * 1e6 / 2,
4000, 1 / 4000 * 1e6 / 2,
5000, 1 / 5000 * 1e6 / 2,
6000, 1 / 6000 * 1e6 / 2,
7000, 1 / 7000 * 1e6 / 2,
8000 1 / 8000 * 1e6 / 2
}; };
unsigned char note = 0; unsigned char note = 8;
unsigned char buttonpressed = 1; unsigned char buttonpressed = 1;
int int
@ -57,8 +58,10 @@ main(void)
//for (;;); //for (;;);
for (unsigned char n = 0;; n = (n + 1) % 2) { for (unsigned char n = 0;; n = (n + 1) % 2) {
if (!buttonpressed) continue; if (!buttonpressed && n == 0) continue;
_delay_us(71.43); _delay_us(freqs[note]);
// _delay_us(714.2857);
// _delay_us(70);
PORTD ^= 1 << P_SPKR; PORTD ^= 1 << P_SPKR;
} }
} }