


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: // Author: // Module description: // ***********************************************************
#include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here #include <stdio.h> #include <string.h> #include <conio.h>
//////////////////////Global Variables//////////////////////// #define DELAYTIME 20 int tree_value[79]={100,66,140,105,59,59,39,94,132,85,5,103,154,180,188,190, 6,49,17,8,157,125,93,69,87,150,167,38,189,170,107,63,145,25,75,13,120,32, 137,187,50,160,186,113,81,57,44,125,93,69,87,150,167,38,189,170,107,63, 5,25,75,13,120,32,137,187,50,160,186,113,81,57,44,155,169,131,15,117,30}; struct tree { int num; struct tree *right, *left; }; struct tree *root;
///////////////////////Function Prototypes//////////////////// int index (int); void random_BST(void); void insert (struct tree **, struct tree ); void search (struct tree, int); void wait (int);
/////////////////////////Main/////////////////////////////// int main(void) { random_BST(); signed int exist; unsigned j,value; char text[50]; //cout<<"\n\tEnter the text to transmit the morse code...\n"; gets(text); unsigned int l=strlen(text); while(1) { for (j=0;j<l;j++) { exist=index(text[j]); if(exist!=-1) { value=tree_value[exist]; if(value==100) {(PORTB &=~(1<<PB5));
wait(7); // cout<<" "; } else { search(root,value); // cout<<" "; } } } }
}
/////////////////////Function definations/////////////////////
// Index //*********** int index(int character) { int ascii[79]={32,33,34,39,40,41,44,45,46,47,48,49,50,51,52,53,54,55,56,57, ,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,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113, 4,115,116,117,118,119,120,121,122,129,130,132,148,160,164};
int mid; for (mid=0;mid<79;mid++) { if(ascii[mid]==character) { return(mid); break; } } return-1; }
// Random_BST (Binary Search Tree) //************************************ void random_BST(void) { struct tree *current; root=NULL; int i; int BST_entries[59]={100,150,50,170,125,75,25,160,187,186,189,190,180,188, ,169,155,156,154,157,113,137,145,138,140,131,134,132,120,117,107,103,105, 87,93,96,94,81,85,63,69,67,66,57,60,59,38,44,49,41,39,32,30,13,15,17,7,8, 5};
for(i=0;i<59;i++) { current=new tree; current->left=NULL;