#define F_CPU 2000000UL //Define the MPU operating frequency
#include <avr/io.h> //Header file for AVR device specific I/O Definitions.
#include <avr/interrupt.h> //Header file for incorportaing interrupt handling faclity (not used here).
#include <util/delay.h> //Header file for incorporating delay routines.
#include "USART.h" //Defines C functions for accessing USART Module.
#define BIT(x) (1 << (x)) //Set a particular bit mask
#define CHECKBIT(x,b) (x&b) //Checks bit status
#define SETBIT(x,b) x|=b; //Sets the particular bit
#define CLEARBIT(x,b) x&=~b; //Sets the particular bit
#define TOGGLEBIT(x,b) x^=b; //Toggles the particular bit
void WaitMs(unsigned int ms);
unsigned char ch;
int main()
{
// Set MOSI and SCK output, all others input
DDRB = (1<<5)|(1<<3)|(1<<2);
// Enable SPI, Master, set clock rate fck/16, SPI MODE 1
SPCR = (1<<SPE)|(1<<SPIE);
uart_init(9600); //Initialise the USART Module with the given Baudrate
//Frame format.
//sei();//enable global interr
while(1) //Enter into a uncoditional while loop..
{
ch=uart_getc();
uart_putc(ch);
SPDR = ch; /* Start transmission by putting data in SPDR */
while(!(SPSR & (1<<SPIF)));/* Wait for transmission complete */
WaitMs(50);
}
return 0;
}
void WaitMs(unsigned int ms) //Generate a delay of ms milli second.
{
unsigned int i;
for(i=0;i<=ms/10;i++)
{
_delay_ms(10);
}
}