Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial port communication using rs232

Status
Not open for further replies.
hi akshay your sent txt file is not good. send it again. one more thing the problem u r facing may be due to high speed comunication. make a delay between bytes send and where do u save the recieved byte? that should b in RAM. and have to b transfered to next ram address.

Don't use SMS typing. Write the compete words [alexan_e]
 

His text file content are fine (I mean that the content can be viewed fine, I have no idea if the code is correct).
This in the content of the original poster attachment file:

Code:
#include<REG51.H>
#include<stdio.h>
#include<string.h>

unsigned char data_upper,data_lower,data_convert_lower,data_convert_upper;
void delay_1ms(unsigned int);

void lcdcmd(unsigned char);

void serial_init();		 //initialise rs232 communication with com1
void lcddata();
sbit enable = P3^6 ;
sbit rs = P3^7;
unsigned char data_sent;
unsigned char port_data;
//     enable equ P2^0;
void main()
{
    P0=0xFF;
    //  P2=0xFF;
    P1=0xFF;
    /*	  lcdcmd(0x38);
    //	  delay_1ms(5);
    	  lcdcmd(0x0F);
    //	  delay_1ms(2);
    	  lcdcmd(0x80);
    //	  delay_1ms(2);
    	   lcdcmd(0x06);	*/
    serial_init();		  //serial port initialiase

    while(1) {

        //   	P1=P2;

        port_data=~P2;		//read data from port2 and send to serial port
        data_lower = port_data & 0x0F;
        data_convert_lower = data_lower | 0x30; //convert to hex code 0x30 to 0x39 for digits
        data_sent = data_convert_lower;
        P1= data_sent;
        /*
          data_upper = port_data & 0xF0;
        data_upper = data_upper >> 4;
        data_convert_upper = data_upper | 0x30;
        data_convert_upper = data_convert_upper << 4;
        data_sent = data_convert_upper | data_convert_lower;
        */
        SBUF=~data_sent;	// send hex data to serial buffer
        //	delay();

        //     lcddata();
        // lcddata();
        while(TI==0);
        TI=0;

    }
}

void serial_init()
{
    TMOD = 0x20;		  // 0x20 for serial data transmit mode
    TH1=0xFD;			  // set baud rate to 9600
    SCON=0x50;
    TR1=1;
    TI=0;

}

void lcdcmd(unsigned char cmd)
{
    P0=cmd;
    rs=0;
    enable=1;
    delay_1ms(1);
    enable=0;
}

void lcddata()
{
    unsigned char var1;

    P0=data_sent;
    rs=1;
    enable=1;
    delay_1ms(5);
    enable=0;

}

void delay_1ms(unsigned int x)
{
    unsigned char i;
    for(i=0; i<=x; i++)
    {
        TMOD=0x01;
        TL0=0xAA;
        TH0=0xFF;
        TR0=1;
        while(TF0==0);
        TF0=0;
        TR0=0;
    }
}

Alex
 
Last edited:

All I did was to post the content of the text file that the original poster has attached, this is not my code, I have never used this mcu.

Alex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top