Maverickmax
Advanced Member level 1
Hello
I am trying to transmit a simple character across another device such as AT89C51 via wire in order to identify the character and switch red_led on for a short of time and switch it off.
What I get - NOTHING!
I am using 12MHz as an oscillator and the baud rate is 9600. So any help would be appreicated.
Here is two codes such as transmitter and receiver
Transmitter
Receiver
Is the baud rate configuration correct?
Maverickmax
I am trying to transmit a simple character across another device such as AT89C51 via wire in order to identify the character and switch red_led on for a short of time and switch it off.
What I get - NOTHING!
I am using 12MHz as an oscillator and the baud rate is 9600. So any help would be appreicated.
Here is two codes such as transmitter and receiver
Transmitter
Code:
// header files
#include "main.h"
#include "port.h"
#include "delay_loop.h"
//Function Prototypes
void serial_init();
void send_serial(unsigned char *s);
void serial_init()
{
SCON=0x50; //Setup for 8-bit data
TMOD=0x20; //Setup timer 1 for auto-reload
TH1=0xF9; //Setup for 9600 Baud
TR1=1; //Turn on timer 1
TI=1; //Indicate ready to transmit
}
void send_serial(unsigned char *s)
{
while(*s !=0x00)
{
SBUF=*s;
while(! TI)
{
}
TI=0;
s++;
}
}
void main(void)
{
serial_init();
BLUE_LED=OFF;
Delay_Loop(100);
BLUE_LED=ON;
Delay_Loop(100);
BLUE_LED=OFF;
Delay_Loop(100);
BLUE_LED=ON;
Delay_Loop(50);
send_serial('5');
BLUE_LED=OFF;
}
Receiver
Code:
// header files
#include "main.h"
#include "port.h"
#include "delay_loop.h"
//Global variable
tByte received_data_G;
int received_flag_G;
//Function Prototypes
void serial_init();
void serial_init()
{
SCON=0x50; //Setup for 8-bit data
TMOD=0x20; //Setup timer 1 for auto-reload
TH1=0xF9; //Setup for 9600 Baud
TR1=1; //Turn on timer 1
TI=1; //Indicate ready to transmit
EA=1; //Enable Interrupts
ES=1; //Enable serial port interrupt
}
serial() interrupt 4
{
if(RI)
{
received_data_G=SBUF;
RI=0;
received_flag_G=1; //Set received flag
}
}
void main(void)
{
RED_LED=OFF;
Delay_Loop(100);
RED_LED=ON;
Delay_Loop(100);
RED_LED=OFF;
received_flag_G=0;
serial_init();
for(;;)
{
while(received_flag_G==0)
{
}
received_flag_G=0;
if (received_data_G==5)
{
RED_LED=ON;
Delay_Loop(50);
RED_LED=OFF;
}
}
}
Is the baud rate configuration correct?
Maverickmax