Last active
August 29, 2015 13:56
-
-
Save slintak/9235669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main (void) | |
{ | |
// DDRG nemuzes predefinovat, to uz existuje | |
//DDRG |= _BV(PG1); //LED9 pro blik | |
//DDRG |= _BV(PG0); //LED10 pro SOS | |
BLIK |= _BV(PG1); //LED9 pro blik | |
SOS |= _BV(PG0); //LED10 pro SOS | |
uint8_t pole[] = { 1,0,1,0,1,0,0,1,1,1,0,1,1,1,0,1,1,1,0,0,1,0,1,0,1 }; | |
DDRG |= SOS; | |
uint8_t i = 0; | |
while (1) { | |
morse(pole[i]); | |
i++; | |
// Osetrit preteceni. | |
//_delay_ms(200); | |
} | |
} | |
void morse (uint8_t i) | |
{ | |
if (i) { //roznuti | |
PORTG |= SOS; | |
} else { //zhasnuti | |
PORTG &= ~SOS; | |
} | |
} | |
///////////////////////////////////////////////// | |
uint8_t delka_pole = ...; | |
while(1) { | |
for(uint8_t i = 0; i < delka_pole; i++) { | |
morse(pole[i]); | |
} | |
} | |
///////////////////////////////////////////////// | |
uint8_t i = 0; | |
while(1) { | |
morse(pole[i]); | |
i++; | |
if(i >= delka_pole) { | |
i = 0; | |
} | |
} | |
///////////////////////////////////////////////// | |
#include <stdint.h> | |
#include <avr/io.h> | |
#define MORSE_TECKA '.' | |
#define MORSE_CARKA '-' | |
#define MORSE_TIME_TECKA 300 | |
#define MORSE_TIME_CARKA 1000 | |
#define MORSE_DDR DDRG | |
#define MORSE_PORT PORTG | |
#define MORSE_PIN PG1 | |
#define MORSE_S "..." | |
#define MORSE_O "---" | |
void morse(uint8_t *znak) { | |
while(znak != '\0') { | |
case(znak) { | |
case MORSE_TECKA: | |
MORSE_PORT |= _BV(MORSE_PIN); | |
_delay_ms(MORSE_TIME_TECKA); | |
break; | |
case MORSE_CARKA: | |
MORSE_PORT &= ~_BV(MORSE_PIN); | |
_delay_ms(MORSE_TIME_CARKA); | |
break; | |
default: | |
// Nemelo by nastat, muzes ohlasit chybu. | |
} | |
znak++; | |
} | |
} | |
void main(void) { | |
// Pin jako vystupni | |
MORSE_DDR |= _BV(MORSE_PIN); | |
// Nase zprava | |
char zprava[] = MORSE_S MORSE_O MORSE_S; | |
while(1) { | |
morse(zprava); | |
_delay_ms(3000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment