Docsity

Morse Code Generation: An AVR Microcontroller Project, Exercises of Microprocessors

Toggle sidebar
bg1
// ***********************************************************
// 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
//
int My_global;
// Interrupt handler example for INT0
//
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
//
char code[218]={0,1,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,
0,1,1,1,1,0,1,0,1,0,0,1,1,1,0,1,1,1,0,1,1,0,1,1,0,1,0,1,0,0,0,0,1,0,0,
1,0,0,0,1,0,1,1,1,0,0,1,1,0,1,1,1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,1,0,1,0,
1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,1,1,1,0,0,1,1,1,0,0,0,1,1,0,0,0,0,1,0,0,
0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,0,0,1,1,1,1,0,0,0,1,1,0,0,0,1,1,1,1,0,
1,0,1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0,
1,0,0,1,1,0,1,1,1,1,1,0,0,0,1,1}; //"Array which contains the "Morse
Code"
//of valid inputs. 0="di"and 1="dah".
int length[65]={0,2,6,10,13,14,18,21,25,27,31,34,38,40,42,45,49,53,56,
59,60,63,67,70,74,78,82,88,94,100,105,110,115,120,125,130,135,140,145,
150,155,161,167,173,179,185,191,195,200,205,210,214,218,63,39,33,40,41,
34,132,160,130,164,148,129}; //This Array contains the starting index of
//morse codes of all the valid inputs.
//The last "12" values are ASCII's of
//non-continuous valid inputs.
int search(int); //This function takes the ASCII of input
character
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".
docsity.com
pf3

Partial preview of the text

Download Morse Code Generation: An AVR Microcontroller Project and more Exercises Microprocessors in PDF only on Docsity!

// 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 // int My_global;

// 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 // char code[218]={0,1,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0, 0,1,1,1,1,0,1,0,1,0,0,1,1,1,0,1,1,1,0,1,1,0,1,1,0,1,0,1,0,0,0,0,1,0,0, 1,0,0,0,1,0,1,1,1,0,0,1,1,0,1,1,1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,1,0,1,0, 1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,1,1,1,0,0,1,1,1,0,0,0,1,1,0,0,0,0,1,0,0, 0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,0,0,1,1,1,1,0,0,0,1,1,0,0,0,1,1,1,1,0, 1,0,1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0, 1,0,0,1,1,0,1,1,1,1,1,0,0,0,1,1}; //"Array which contains the "Morse Code" //of valid inputs. 0="di"and 1="dah".

int length[65]={0,2,6,10,13,14,18,21,25,27,31,34,38,40,42,45,49,53,56, 59,60,63,67,70,74,78,82,88,94,100,105,110,115,120,125,130,135,140,145, 150,155,161,167,173,179,185,191,195,200,205,210,214,218,63,39,33,40,41, 34,132,160,130,164,148,129}; //This Array contains the starting index of //morse codes of all the valid inputs. //The last "12" values are ASCII's of //non-continuous valid inputs.

int search(int); //This function takes the ASCII of input character 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>=44)&&(X<=57)) //Check for ", -. / and digits (0-9). { // Comma, Hyphen, Full Stop and slash index=X-18; //have ASCII's continuous with digits. }

else { //Check for "Remaining Punctuation" and for(i=53;i<=65;i++) //"Special Characters". { if(X==length[i]) { index=i-13; } } } // The search function returns the Index //of the Input Character in "Array Length". return index; }

void delay(int); //Delay Function. void delay(int x) { unsigned int y; unsigned int i;

for(y=0; y<x; y++) { for(i=0; i<38; i++); } }

int main(void) //Main Function. { unsigned int di=1; unsigned int x; unsigned int y; unsigned int X; unsigned int index; unsigned int L; unsigned int check=0;