This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

recive data from serial and use it for port

I need to write a program for a project that receive data from serial (RX pin) using HC06 module and then turn a led on according to the received information.
I'm using P89v51rd2 microcontroller.
Here is the code I write but something is wrong

#include <reg51.h>
#include <stdio.h>

sbit con1 = 0xa0;

void serial_init(void)             //Setup the serial port for 9600 baud at 11.0592MHz.
{
                SCON  = 0x50;         //* SCON: mode 1, 8-bit UART, enable rcvr
                TMOD  = 0x20;        //* TMOD: timer 1, mode 2, 8-bit reload
                TH1   = 0xFD;       //* TH1:  reload value for 9600 baud @ 11.0592MHz
                TL1   = 0xFD;
                TR1   = 1;         //* TR1:  timer 1 run
                TI    = 1;        //* TI:   set TI to send first char of UART
}


void receive()          //Function to receive serial data
{
                unsigned int digit;    //variable to hold the new character
                while(RI==0);         //Wait for Receive interrupt flag
                        {
                         digit=SBUF;
                         RI=0;                          //Clear eceive interrupt flag
                        }
                if (digit==1)
                        {
                         con1=0;
                        }
                else
                        {
                         con1=1;
                        }


void main()
{
                while(1)
                {
                serial_init();
                receive();
                }
}

where i'm wrong
please help me