#define OSCSPEED 8000000
#include <avr/io.h>
#include <util/delay.h>
void Initialize(void)
{
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
DDRA = 0XFF;
DDRB = 0xF0;
DDRC = 0xFF;
DDRD = 0x00;
}
void UARTInit(uint32_t Baud)
{
unsigned int BaudRate = OSCSPEED / (16 * Baud) - 1;
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH = (unsigned char) (BaudRate>>8);
UBRRL = (unsigned char) BaudRate;
}
unsigned char usart_receive( void )
{
unsigned char data;
while ((UCSRA & 0x80) == 0x00); // Wait for till the data arrives data
data=UDR; // Read the data from UDR, as soon as the data arrives
return data;
}
int main(void)
{
unsigned char ch=0x00,ch1=0x00;
unsigned int a,b,c,d,e,f,g,h,i;
unsigned char c1,c2,c3,c4;
Initialize();
UARTInit(800);
while(1)
{
ch = usart_receive();
if((ch & 0xF0) == 0x00)
{
ch1 = usart_receive();
a=ch;
b=ch1;
c = 256*a;
d=c+b;
i = d;
e = d%10;
c1 = func(e);
d = d/10;
f = d%10;
c2 = func(f);
d = d/10;
g = d%10;
c3 = func(g);
d = d/10;
h = d%10;
c4 = func(h);
PORTB = 0x80;
PORTA = c4;
_delay_ms(1);
PORTB = 0x40;
PORTA = c3;
_delay_ms(1);
PORTB = 0x20;
PORTA = c2;
_delay_ms(1);
PORTB = 0x10;
PORTA = c1;
_delay_ms(1);
}
else
{
PORTB = 0x80;
PORTA = 0xFC;
_delay_ms(1);
PORTB = 0x40;
PORTA = 0xFC;
_delay_ms(1);
PORTB = 0x20;
PORTA = 0xFC;
_delay_ms(1);
PORTB = 0x10;
PORTA = 0xFC;
_delay_ms(1);
}
}
}
func(unsigned int e)
{
unsigned char j;
switch(e)
{
case 0:
j = 0xFC;
break;
case 1:
j = 0x60;
break;
case 2:
j=0xDA;
break;
case 3:
j=0xF2;
break;
case 4:
j=0x66;
break;
case 5:
j=0xB6;
break;
case 6:
j=0xBE;
break;
case 7:
j=0xE0;
break;
case 8:
j=0xFE;
break;
case 9:
j=0xF6;
break;
default :
j=0xFC;
break;
}
return j;
}