#include <avr/io.h>
#include <util/delay.h>
//Ham gui du lieu
uint8_t TransmitByte(uint8_t chr)
{
while((UCSRA&(1<<UDRE)) == 0); //thoai vong lap : thanh ghi UDR trong
UDR=chr;
}
main()
{
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
/* f=8Hz, toc do baud=57600*/
UBRRH=0x00;
UBRRL=0x08;
DDRC=0x00;
PORTC=0xFF;
while(1)
{
if((PINC & _BV(PC4))==0)
{
_delay_ms(10);
if((PINC & _BV(PC4))==0)
{
TransmitByte('1');
while((PINC & _BV(PC4))==0);
}
}
if((PINC & _BV(PC5))==0)
{
_delay_ms(10);
if((PINC & _BV(PC5))==0)
{
TransmitByte('2');
while((PINC & _BV(PC5))==0);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
//Code thu
#include <avr/io.h>
#include <util/delay.h>
uint8_t ReceiveByte()
{
while((UCSRA&(1<<RXC)) == 0);
return UDR;
}
main()
{
uint8_t Ma_Lenh;
UCSRA=0x00;
UCSRB=0x18; //RXEN=TXEN=1
UCSRC=0x86; //URSEL=UCSZ1=UCSZ0=1
/* f=8MHz, toc do baud=9600 */
UBRRH=0x00;
UBRRL=0x08;
DDRC=0xFF;
while (1)
{
Ma_Lenh = ReceiveByte();
switch(Ma_Lenh)
{
case 'F': {PORTC|=(1<<PC4);}break;
case 'B': {PORTC&=~(1<<PC4);}break;
}
// Place your code here
}
}
//////////////////////////////////
Linktest TamBKSTAR