-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.c
96 lines (79 loc) · 2.51 KB
/
main.c
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
/*
* Antispy ultrasonic device for preventing voice recording
* with ultrasonic waves generation
* based on ATTINY13 chip
* ATTINY13 fuses have to be set for 9,6 MHz internal clock
* with Resistor Ladder 5-bit Digital-to-Analog converter
* and piezzo-electric driver
* (C) Adam Loboda 2021, [email protected]
*/
#include <stdint.h>
#include <util/delay.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
// PIN - PORT ASSIGNMENT DEFINITION FOR 5-BIT DAC DEVICE
#define OUTPUTPORT PORTB
#define OUTPUTPORTCTRL DDRB
// DEFINE 32 VALUES for ULTRASONIC WAVE SHAPE
// VIA 5-BIT Digital to Analog conversion
// saw like wave
/*const uint8_t waveshape[] PROGMEM =
{
0, 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, 20, 31
};
*/
// sinusoidal waveform created in Excell / Libreoffice
const uint8_t waveshape[] PROGMEM =
{ 18, 21, 23, 26, 27, 29, 30, 30,
30, 29, 27, 26, 23, 21, 18, 15,
12, 9, 7, 4, 3, 1, 0, 0,
0, 1, 3, 4, 7, 9, 12, 15
};
int main(void)
{
uint8_t sequence;
uint8_t frequency;
uint8_t dacvalue;
uint8_t delayusec;
// SET OUTPUT PIN ON ALL OUTPUT PORTS
OUTPUTPORTCTRL = 0b00011111; //set all 5 LOWER bit pins as output
OUTPUTPORT = 0b00000000; //set all 5 LOWER bit pins to ZERO
//* neverending loop */
while (1)
{
// generating WAVE on BIT0-BIT5 DAC outputs
// with values taken from PROGMEM WAVE definition
/*
// gives exact 27 kHz with 9,6MHz clock of ATTINY13
for(sequence=0; sequence<31; sequence++)
{
dacvalue = pgm_read_byte(waveshape + sequence) ;
OUTPUTPORT = dacvalue;
};
*/
// gives exact 25 kHz with 9,6MHz clock of ATTINY13
for(sequence=0; sequence<31; sequence++)
{
dacvalue = pgm_read_byte(waveshape + sequence) ;
OUTPUTPORT = dacvalue;
// now delay to achieve desired frequency
asm volatile (" nop \n" );
};
/*
// gives 23 kHz with 9,6MHz clock of ATTINY13
for(sequence=0; sequence<31; sequence++)
{
dacvalue = pgm_read_byte(waveshape + sequence) ;
OUTPUTPORT = dacvalue;
// now delay to achieve desired frequency
asm volatile (
" nop \n"
" nop \n" );
};
*/
}; // neverending loop
}; // end of MAIN