


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



// Project: MORSE CODE GENERATION. // Module description: // ***********************************************************
#include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here
// Define here the global static variables // unsigned int code[56]={0x82,0x01,0x05,0xC1,0x40,0x04,0xC3,0x00,0x80,0x0E,0xC5,
0x02,0x83,0x81,0xC7,0x06,0x0B,0xC2,0xC0,0x41,0xC4,0x08,0xC6,0x09,0x0D,0x 3,
0x1F,0x1E,0x1C,0x18,0x10,0x00,0x01,0x03,0x07,0x0F,
0x35,0x12,0x1E,0x2D,0x2D,0x33,0x21,0x2A,0x09,0x0C, 33,34,39,40,41,44,45,46,47,63 };
// Interrupt handler example for INT // SIGNAL(SIG_INTERRUPT0) {
}
// It is recommended to use this coding style to // follow better the mixed C-assembly code in the // Program Memory window // void my_function(void) { // Put the open brace '{' here
asm("nop"); // Inline assembly example }
// *********************************************************** // Main program
int search(int); //This function takes the ASCII of input int search(int X) //character and check either it is valid { //input or not.In case of non valid input unsigned int i; //function returns "-1". unsigned int index; index=-1; if((X>=65)&&(X<=90)) //Check for "Capital Alphabets". { index=X-65; } else if((X>=97)&&(X<=127)) //Check for "Small Alphabets". { index=X-97;
else if((X>=48)&&(X<=57)) //Check for , -. / and digits (0-9). { // Comma, Hyphen, Full Stop and slash index=X-22; //have ASCII's continuous with digits. }
else { //Check for "Remaining Punctuation" and for(i=46;i<=55;i++) //"Special Characters". { if(X==code[i]) { index=i-10; } } } // The search function returns the Index //of the Input Character in "Array Length". return index; }
int length(int); int length(int index) { unsigned int W,len; #define BIT_MASK 0xC0;
W=code[index]& BIT_MASK; W=W>>6; if((index>=0)&&(index<=25)) { switch(W) { case 0x01: len=1; break; case 0x02: len=2; break; case 0x03: len=3; break; case 0x00: len=4; break; } }
else if((index>=26)&&(index<=35)) { len=5; }
else { switch(index) { case 44: len=5; break; default: len=6; break; }
codelength=length(index); for (x=0; x<codelength; x++) { D=code[index]&(1<<x); D=D>>x; PORTB=1; if(D==0x00) //Check for "Di". { delay(di); } else if(D==0x01) //Check for "Dah. { delay(3di); } PORTB = 0; delay(di); //Delay after every "di"and "Dah". } delay(2di); //Delay after every alphabet. } } } } }