Skip to content

Commit

Permalink
Sender - final
Browse files Browse the repository at this point in the history
  • Loading branch information
kodieg committed Jan 17, 2012
1 parent e3b3764 commit 5f0b58d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 157 deletions.
4 changes: 2 additions & 2 deletions counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ void counterInit(void)
const uint8_t TIMER2_RUNNING_CTC = 1 << WGM21 | 1 << CS21;
TCCR2 = TIMER2_RUNNING_CTC;
OCR2 = 250;
// TIMSK |= (1 << OCIE2);
TIMSK |= (1 << OCIE2);

// Setup timer 0 in CTC mode (for C2 sound)
const uint8_t TIMER0_RUNNING_CTC = 1<<WGM01 | 1 << CS01;
TCCR0 = TIMER0_RUNNING_CTC;
OCR0 = 118;
TIMSK |= (1 << OCIE2 | 1 << OCIE0);
TIMSK |= (1 << OCIE0);
#else
const uint8_t TIMER0_RUNNING_CTC = 1 << WGM01 | 1 << CS01;
TCCR0 = TIMER0_RUNNING_CTC;
Expand Down
188 changes: 35 additions & 153 deletions sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* klawiatura.c
*
* Created: 2011-11-15 16:44:01
* Author: pn264889
* Author: kg262932
*/

#include "config.h"
Expand All @@ -13,50 +13,10 @@
#include <string.h>

#include "commons.h"
//#include "keyboard.h"
#include "lcd.h"
#include "mic.h"
#include "counter.h"
#include "morse.h"
//INT0_vect
/*
ISR(INT0_vect) {
//volatile uint16_t t;
//for (t = 0; t < 2000; ++t);
_delay_loop_2(2000);
int8_t key = readKeypad();
LD_PORT = ~key;
}
int main_keypad(void)
{
LD_DDR = 0xFF;
initKeypad();
// Przerwanie INT0 bedzie zglaszane przy zboczu opadajacym
uint8_t tmp = MCUCR;
CBI(tmp, ISC00);
SBI(tmp, ISC01);
MCUCR = tmp;
// Wlaczenie przerwania INT0
SBI(GICR, INT0);
// Wyzerowanie znacznikow przerwan
SBI(GIFR, INTF0);
// Waaczenie przerwan (ustawienie globalnego znacznikaprzerwan)
sei();
while(1) {
//_delay_ms(500);
}
}
*/

const uint16_t DITS_SCALER = 61;

volatile uint8_t turn_sound_off = 0;
volatile uint8_t sound_is_on = 0;
Expand All @@ -68,6 +28,23 @@ volatile uint8_t start = 0;
volatile uint8_t end = 0;
volatile uint8_t letter_pos = 0;

void soundOn() {
if (sound_is_on == 0) {
sound_is_on = 1;
TCCR0 = (1 << WGM01 | 1 << COM00 | 1 << CS01);
SBI(LD_DDR, 0);
}
}

void soundOff() {
if (sound_is_on) {
sound_is_on = 0;
turn_sound_off = 1;
CBI(LD_DDR, 0);
}
}


ISR(TIMER0_COMP_vect) {
if (turn_sound_off && !(PINB & (1 << PB3))) {
TCCR0 = (1 << WGM01 | 1 << CS01);
Expand All @@ -81,18 +58,22 @@ ISR(TIMER2_OVF_vect) {}

ISR(TIMER2_COMP_vect) {
if (sound_counter == 0 && silence_counter == 0) {
//sound_off();
if (start != end) {
char letter = buffer[start];
const char* morseCode = getMorseString(letter);
if (morseCode) {
uint8_t len = strlen(morseCode);
if (letter == ' ') {
silence_counter = _wordSpaceRepeat;
start++;
return;
}
const char* morse_code = getMorseString(letter);
if (morse_code) {
uint8_t len = strlen(morse_code);
if (letter_pos >= len) {
start++;
letter_pos = 0;
silence_counter = _charSpaceRepeat; // between letters
} else {
const char code = morseCode[letter_pos];
const char code = morse_code[letter_pos];
if (code == '.') {
sound_counter = _ditRepeat; // dit
}
Expand All @@ -109,139 +90,40 @@ ISR(TIMER2_COMP_vect) {
}
}
if (sound_counter > 0) {
sound_on();
soundOn();
--sound_counter;
} else if (silence_counter > 0) {
sound_off();
soundOff();
--silence_counter;
}
}

void sound_on() {
if (sound_is_on == 0) {
sound_is_on = 1;
TCCR0 = (1 << WGM01 | 1 << COM00 | 1 << CS01);
SBI(LD_DDR, 0);
}
}

void sound_off() {
if (sound_is_on) {
sound_is_on = 0;
turn_sound_off = 1;
CBI(LD_DDR, 0);
//TCCR0 = (1 << WGM01 | 1 << CS01);
}
}

ISR(USART_RXC_vect) {
uint8_t b = UDR;
buffer[end] = b;
++end;
// lcdInt(b);
buffer[end++] = UDR;
}

ISR(USART_TXC_vect) {}
ISR(USART_UDRE_vect) {}

int WorkMode = 0;

int main(void)
{
LD_DDR = 0xFF;
SWITCH_DDR = 0x00;
SWITCH_PORT = 0xFF;


UBRRH = 0x00;
UBRRL = 0x33;
UCSRA = 0x40;
UCSRB = 0x98;
UCSRC = 0x86;
UBRRH = 0x00;
UBRRL = 0x33;

morseInit();
lcdInit();
counterInit();

const uint8_t MIN_TRESHOLD = 127;
uint8_t previous = 128;
uint8_t counter = 0;
volatile uint16_t timer = 1001;


strcpy(buffer, "KODIE SOS");
strcpy(buffer, "WITAJ SWIECIE");
end = strlen(buffer);

while(1)
{}
{


WorkMode = ~SWITCH_PIN;
if (timer > 100) {
// cli();
lcdClear();
lcdString(buffer);
lcdString(" ");
lcdInt(start);
lcdString(" ");
lcdInt(sound_counter);
lcdString(" ");
lcdInt(silence_counter);
// sei();
timer = 0;
}
timer++;

if (previous != CHECK(WorkMode, BEEP_MODE)) {
counter = 0;
previous = CHECK(WorkMode, BEEP_MODE);
} else {
counter++;
}

if (counter > MIN_TRESHOLD) {
counter = MIN_TRESHOLD;
if (previous == 1 && !sound_is_on) {
sound_on();
//lcdInt(0);
} else if (previous == 0 && sound_is_on) {
sound_off();
//lcdInt(1);
}
}

_delay_us(100);
//lcdInt(TCCR0);
//_delay_ms(100);
}
/*
lcdString("Hello world!\0");
_delay_ms(20);
uint16_t maxVal=0;
uint16_t minVal=0xFFFF;
for(uint16_t i = 0; 1; ++i)
{
const uint16_t micVal = micRead();
if (micVal > maxVal)
maxVal = micVal;
if (micVal < minVal)
minVal = micVal;
if (i % 2048 == 0)
{
lcdClear();
//lcdInt(micRead());
//_delay_ms(10);
lcdInt(minVal);
lcdString(" | ");
lcdInt(maxVal);
maxVal = 0;
minVal = 0xFFFF;
}
}
*/
while(1) {}
}


Expand Down
5 changes: 3 additions & 2 deletions vmlab_klawiatura.prj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

; Micro + software running
; ------------------------------------------------------------
.MICRO "ATmega16"
.MICRO "ATmega32"
.TOOLCHAIN "GCC"
.GCCPATH "C:\Program Files\WinAVR-20100110"
.GCCMAKE AUTO
.TARGET "vmlab_klawiatura.hex"
.SOURCE "mic.c" "main.c" "lcd.c" "counter.c"
.SOURCE "mic.c" "sender.c" "lcd.c" "counter.c" "morse.c"

.TRACE ; Activate micro trace

Expand Down Expand Up @@ -65,3 +65,4 @@ Vmic PA7 VSS SLIDER_1(0 2.56) ;x: Panel sliders 1 - 3
K0 PC0 GND
K6 PC6 GND
K7 PC7 GND

0 comments on commit 5f0b58d

Please sign in to comment.