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.

RS232 interface in C code

Status
Not open for further replies.

cafukarfoo

Full Member level 3
Joined
Jul 25, 2007
Messages
170
Helped
8
Reputation
16
Reaction score
5
Trophy points
1,298
Activity points
2,510
rs232 interface program in c

Hello,

Can anyone share example of a RS232 interface code in C programming
language?

Thanks.
 

c code for rs232

Here is an example for 8051
Code:
/* RS232 SIMPLE TRIAL */

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


/*Function to initialize RS232 serial port*/
void serial_init()
{
	SCON=0X50;		//Setup for 8-bit data
	TMOD=0X20;		//Setup Timer 1 for auto-reload
	TH1=0XFD;		//Setup for 9600 baud
	TR1=1;			//Turn on Timer 1
	T1=1;			//Indicate Ready to Transmit
}

/*This func display a null-terminated string on the rs232 port*/

void send_serial(unsigned char*s)
{
 while(*s!=0x0)
 {
  SBUF=*s;
  while(!T1)
  {  }
  T1=0;
  s++;
  }
}

/*Start of main program*/

main()
{
 unsigned char crlf[]={0x0D,0x0A,0x0};
 serial_init();
 for (;;)
 {
  send_serial("Another test");
  send_serial(crlf);
 }
}


Also try this
https://www.keil.com/download/docs/200.asp
 
rs232 c code

Thanks huzaifahm.

Anyone have one that work with FPGA?

Thanks.
 

rs232 code in c

char getCharacter (void)
{
char chr; // variable to hold the new character
while (RI != 1) {;}
chr = SBUF;
RI = 0;
return(chr);
}
void send (char a)
{
SBUF = a;
while (TI != 1);
TI=0;
}

void main (void){
char chr;
int i=0,j=0,count=0,inc=47;//inc=47
int index=0;
P1=0X00;
P2=0X00;

SCON = 0x50; // mode 1, 8-bit uart, enable receiver
TMOD = 0x20; // timer 1, mode 2, 8-bit reload
TH1 = 0XE6; // 1200
TL1 = 0XE6;
TR1 = 1;
TI = 0;
SBUF =0;

while(1){


your code

}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top