

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A c code snippet for an avr microcontroller that processes characters, converts small characters to capital, and transmits corresponding codes based on a defined map. The code includes functions for delay, special character processing, and character processing.
Typology: Exercises
1 / 3
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 <string.h>
#define DI_TIME 5 #define DAH_TIME 22 #define CODE_WIDTH_MAP 7 #define OFFSET_WIDTH 3
// Define here the global static variables // int code[]={0xA,0x44,0x54,0x23,0x1,0x14,0x33,0x4,0x2,0x3C, 0x2B,0x24,0x1A,0x12,0x3B,0x34,0x6C,0x13,0x3,0x9, 0xB,0xC,0x1B,0x4C,0x5C,0x64,0xFD,0x7D,0x3D,0x1D, 0xD,0x5,0x85,0xC5,0xE5,0xF5,0x66,0xAE,0x2C,0x19E, 0x1C6,0x1C,0x6D,0x16E,0x10E,0x95,0xAD,0x6E,0x25, 0x74,0xDD,0xF6,0x16E};
unsigned char spcl[17]={'?' , '.' , 'ä' , ',' , ':' , 'ü' , 'á' , '(' , '-' , '/' , ';' , '_' , 'é' , 'ö', 'ñ' , 39 , ')' }; int map[6]={1,2,4,8,16,32};
// Interrupt handler example for INT //
// It is recommended to use this coding style to // follow better the mixed C-assembly code in the // Program Memory window // void dly (int); void inprocess(int); void special(int,unsigned char);
// *********************************************************** // Main program // int main(void) { int i,j; unsigned char curr_value,text[]="á"; DDRB|=1; while(1) // Infinite loop; define here the { for(i=0;i<strlen(text);i++) { curr_value=text[i];
if((curr_value>='A'&&curr_value<='Z')||(curr_value>='a'&&curr_value <='z')) { curr_value&=0xDF; // To convert small characters into Capital j=curr_value-'A'; // To get the index of current character inprocess(j); } else if(curr_value==32) { dly(3DI_TIME); } else if(curr_value>='0'&&curr_value<='9') { j=curr_value-'0'+26; inprocess(j); } else { special(0,curr_value); } } dly(10DI_TIME); }
} void special(int curr,unsigned char tx) { if(curr>=16 || tx==spcl[curr]) { if(tx==spcl[curr]) { inprocess(curr+36); } } else if(tx>spcl[curr]) { special((2curr+2),tx); } else { special((2curr+1),tx); } } void inprocess(int jo) { int l,d,width,cod,last_bit; width=(code[jo])&(CODE_WIDTH_MAP); cod=code[jo]>>OFFSET_WIDTH; last_bit=width-1; for(l=last_bit;l>=0;l--) {