code that is running on ATMEGA88 successfully on AVR STUDIO4
#include <avr/io.h>
#include <avr/iom88.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define ATMEGA_88
//To go in DEBUG Mode, comment the following line
//#define RELEASE
//#ifndef RELEASE
#define DEBUG
//#endif
//static int bPacketReady = 0;//Setting false as default
int iRecieveBuffer [10];
int iOutputBuffer [10];
int i, j, k, l;
const int iLEDCodes [10] = { 0x03, 0x9F, 0x25, 0x0D, 0x99, 0x49, 0x41, 0x1F, 0x01, 0x09 };
const int iMUXCodes [6] = { 0b010000,0b001000,0b000100,0b000100,0b000001,0b000010 };
int a=0;
//Function Declaration
void Delay ( int iDelay );
void DisplaySegments ( int iDisplayData [10] );
int main ( void )
{
//Setting up General purpose Configuration
PRR = PRR & 0b11111101; //Enable USART0
SREG = 0x80; //Enabling All Interupts
//Setting up USART Configuration
UCSR0B = 0x00; //Disable Transmit n Recieve while setting baud rate
UCSR0A = 0x02; //U2X = 1
UCSR0C = 0x06; //Transmit 8-bit Data
UBRR0L = 0x67; //
UBRR0H = 0x00; //Baud Rate
UCSR0B = 0xF8; //Transmit Enable, Recieve Enable
//Port Direction Registers
DDRB = 0xFF;
DDRC = 0xFF;
i = 0;
j = 0;
k = 0;
l = 0;
while ( 1 )
{
//Code Body here
if ( a == 1 )
{
//Uncomment the following block when in DEBUG Mode
#ifdef DEBUG
for( j = 0; j < 9; j++ )
{
while (!(UCSR0A & 0x20));
UDR0 = iRecieveBuffer[j];
iOutputBuffer [j] = iRecieveBuffer [j];
}
#endif
a = 0;
}
/* if ( k == 0 ) //Chacking sign of the Packet
{
if ( iOutputBuffer
{
PORTC = 0x01;
PORTB = 0xFD;
}
k++; l++;
continue;
}
if ( k == 3 )
l++;
iOutputBuffer [l] &= 0x0F;
PORTB = 0xFF;
PORTC = iMUXCodes [k++];
if ( k == 3 )
PORTB = iLEDCodes [iOutputBuffer[l++]] & 0xFE;
else
PORTB = iLEDCodes [iOutputBuffer[l++]];
//delay
for ( j = 0; j < 50; j++ );
if ( k == 6 ) k = 0;
if ( l == 7 ) l = 0;
*/
DisplaySegments ( iOutputBuffer );
}
return 1;
}
void DisplaySegments ( int iDisplayData [10] )
{
int iter_i;
for ( iter_i = 0; iter_i < 7; iter_i++ )
{
if (iter_i==0)
{
if ( iDisplayData [iter_i] == '-' )
{
PORTC = iMUXCodes [iter_i] ;
PORTB = 0xFD;
Delay(100);
}
else
{
PORTC = iMUXCodes [iter_i] ;
PORTB = 0xFF;
Delay(100);
}
}
if (( iter_i != 0 ) && ( iter_i != 3 ) )
{
iDisplayData [iter_i] &= 0x0F;
if ( iter_i == 2 )
{
PORTC = iMUXCodes [iter_i] ;
PORTB = ( iLEDCodes [ iDisplayData [iter_i] ] & 0xFE );
Delay(100);
}
else
{
PORTC = iMUXCodes [iter_i];
PORTB = iLEDCodes [ iDisplayData [iter_i] ];
Delay(100);
}
}
}
PORTC=0x00;
}
void Delay ( int iDelay )
{
unsigned int iter_l;
for ( iter_l = iDelay; iter_l > 0; iter_l-- );
}
ISR ( USART_TX_vect )
{
//USART Transmission complete routine
}
ISR ( USART_RX_vect )
{
//USART Reception complete routine
#ifdef DEBUG
iRecieveBuffer [i++] = UDR0;
#endif
#ifdef RELEASE
iOutputBuffer [i++] = UDR0;
#endif
if( i == 9 )
{
a = 1;
i = 0;
}
}
ISR ( USART_UDRE_vect )
{
}
Code that is running successfully on ATMEGA48
#include <avr/io.h>
#include <avr/iom48.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define ATMEGA_48
//To go in DEBUG Mode, comment the following line
//#define RELEASE
//#ifndef RELEASE
#define DEBUG
//#endif
//static int bPacketReady = 0;//Setting false as default
int iRecieveBuffer [10];
int iOutputBuffer [10];
int i, j, k, l;
int *b;
const int iLEDCodes [10] = { 0x03, 0x9F, 0x25, 0x0D, 0x99, 0x49, 0x41, 0x1F, 0x01, 0x09 };
const int iMUXCodes [6] = { 0b010000,0b001000,0b000100,0b000100,0b000001,0b000010 };
int a=0;
//Function Declaration
void Delay ( int iDelay );
void DisplaySegments ( int iDisplayData [10] );
int main ( void )
{
//Setting up General purpose Configuration
PRR = PRR & 0b11111101; //Enable USART0
SREG = 0x80; //Enabling All Interupts
//Setting up USART Configuration
UCSR0B = 0x00; //Disable Transmit n Recieve while setting baud rate
UCSR0A = 0x02; //U2X = 1
UCSR0C = 0x06; //Transmit 8-bit Data
UBRR0L = 0x67; //
UBRR0H = 0x00; //Baud Rate
UCSR0B = 0xF8; //Transmit Enable, Recieve Enable
//Port Direction Registers
DDRB = 0xFF;
DDRC = 0xFF;
b=&a;
i = 0;
j = 0;
k = 0;
l = 0;
while ( 1 )
{
//Code Body here
if ( *b == 1 )
{
//Uncomment the following block when in DEBUG Mode
#ifdef DEBUG
for( j = 0; j < 9; j++ )
{
while (!(UCSR0A & 0x20));
UDR0 = iRecieveBuffer[j];
iOutputBuffer [j] = iRecieveBuffer [j];
}
#endif
a = 0;
}
/* if ( k == 0 ) //Chacking sign of the Packet
{
if ( iOutputBuffer
{
PORTC = 0x01;
PORTB = 0xFD;
}
k++; l++;
continue;
}
if ( k == 3 )
l++;
iOutputBuffer [l] &= 0x0F;
PORTB = 0xFF;
PORTC = iMUXCodes [k++];
if ( k == 3 )
PORTB = iLEDCodes [iOutputBuffer[l++]] & 0xFE;
else
PORTB = iLEDCodes [iOutputBuffer[l++]];
//delay
for ( j = 0; j < 50; j++ );
if ( k == 6 ) k = 0;
if ( l == 7 ) l = 0;
*/
DisplaySegments ( iOutputBuffer );
}
return 1;
}
void DisplaySegments ( int iDisplayData [10] )
{
int iter_i;
for ( iter_i = 0; iter_i < 7; iter_i++ )
{
if (iter_i==0)
{
if ( iDisplayData [iter_i] == '-' )
{
PORTC = iMUXCodes [iter_i] ;
PORTB = 0xFD;
Delay(100);
}
else
{
PORTC = iMUXCodes [iter_i] ;
PORTB = 0xFF;
Delay(100);
}
}
if (( iter_i != 0 ) && ( iter_i != 3 ) )
{
iDisplayData [iter_i] &= 0x0F;
if ( iter_i == 2 )
{
PORTC = iMUXCodes [iter_i] ;
PORTB = ( iLEDCodes [ iDisplayData [iter_i] ] & 0xFE );
Delay(100);
}
else
{
PORTC = iMUXCodes [iter_i];
PORTB = iLEDCodes [ iDisplayData [iter_i] ];
Delay(100);
}
}
}
PORTC=0x00;
}
void Delay ( int iDelay )
{
unsigned int iter_l;
for ( iter_l = iDelay; iter_l > 0; iter_l-- );
}
ISR ( USART_TX_vect )
{
//USART Transmission complete routine
}
ISR ( USART_RX_vect )
{
//USART Reception complete routine
#ifdef DEBUG
iRecieveBuffer [i++] = UDR0;
#endif
#ifdef RELEASE
iOutputBuffer [i++] = UDR0;
#endif
if( i == 9 )
{
*b = 1;
i = 0;
}
}
ISR ( USART_UDRE_vect )
{
}