/* * morse.c * * Created: 18/05/2021 15:47:14 * Author: yboujon1 */ #include "main.h" #include "morse.h" unsigned char morse_library[LETTRES][7]= { {'a',POINT,TRAIT,'\0'}, {'b',TRAIT,POINT,POINT,POINT,'\0'}, {'c',TRAIT,POINT,TRAIT,POINT,'\0'}, {'d',TRAIT,POINT,POINT,'\0'}, {'e',POINT,'\0'}, {'f',POINT,POINT,TRAIT,POINT,'\0'}, {'g',TRAIT,TRAIT,POINT,'\0'}, {'h',POINT,POINT,POINT,POINT,'\0'}, {'i',POINT,POINT,'\0'}, {'j',POINT,TRAIT,TRAIT,TRAIT,'\0'}, {'k',TRAIT,POINT,TRAIT,'\0'}, {'l',POINT,TRAIT,POINT,POINT,'\0'}, {'m',TRAIT,TRAIT,'\0'}, {'n',TRAIT,POINT,'\0'}, {'o',TRAIT,TRAIT,TRAIT,'\0'}, {'p',POINT,TRAIT,TRAIT,POINT,'\0'}, {'q',TRAIT,TRAIT,POINT,TRAIT,'\0'}, {'r',POINT,TRAIT,POINT,'\0'}, {'s',POINT,POINT,POINT,'\0'}, {'t',TRAIT,'\0'}, {'u',POINT,POINT,TRAIT,'\0'}, {'v',POINT,POINT,POINT,TRAIT,'\0'}, {'w',POINT,TRAIT,TRAIT,'\0'}, {'x',TRAIT,POINT,POINT,TRAIT,'\0'}, {'y',TRAIT,POINT,TRAIT,TRAIT,'\0'}, {'z',TRAIT,TRAIT,POINT,POINT,'\0'}, {'0',TRAIT,TRAIT,TRAIT,TRAIT,TRAIT,'\0'}, {'1',POINT,TRAIT,TRAIT,TRAIT,TRAIT,'\0'}, {'2',POINT,POINT,TRAIT,TRAIT,TRAIT,'\0'}, {'3',POINT,POINT,POINT,TRAIT,TRAIT,'\0'}, {'4',POINT,POINT,POINT,POINT,TRAIT,'\0'}, {'5',POINT,POINT,POINT,POINT,POINT,'\0'}, {'6',TRAIT,POINT,POINT,POINT,POINT,'\0'}, {'7',TRAIT,TRAIT,POINT,POINT,POINT,'\0'}, {'8',TRAIT,TRAIT,TRAIT,POINT,POINT,'\0'}, {'9',TRAIT,TRAIT,TRAIT,TRAIT,POINT,'\0'} }; void envoyer_signe_morse(unsigned char signe_morse) { switch(signe_morse){ case POINT: start_timer0(); start_timer1(ONEMS); wait_ocf1a_timer1(); stop_timer0(); wait_ocf1a_timer1(); break; case TRAIT: start_timer0(); start_timer1(3*ONEMS); wait_ocf1a_timer1(); stop_timer0(); start_timer1(ONEMS); wait_ocf1a_timer1(); break; case INTERLETTRE: start_timer1(2*ONEMS); wait_ocf1a_timer1(); break; case INTERMOT: start_timer1(10*ONEMS); wait_ocf1a_timer1(); break; case FIN: resume_timer1(); stop_timer1(); break; default: break; }; } void maj2min_convert(char *tab, int n) { int i; for(i=0; i<=n; i++) { if(tab[i]>=65 && tab[i]<=90) //si c'est une majuscule { tab[i]=tab[i]+32; //la met en minuscule } else { tab[i]=tab[i]; //sinon rien }; }; } void latin2morse(char *tab, int n) { int i=0; //varie la chaine de caractere int j=0; //varie la librarie do { switch(j) { case 0: lcd_char(tab,&i); maj2min_convert(tab,i); default: if(tab[i]==morse_library[j][0]) //verifie si le caractere correspond ? la librarie { library_checker(tab,&i,&j); //traduit dans la librairie et renvoie les deux variables pour continuer } else //si ce n'est pas dans la librarie { simple_terms(tab,&i,&j); //traduit directement les termes plus simples }; break; }; }while(i