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.

to read from sbuf in 8051

Status
Not open for further replies.

fatima_just

Junior Member level 1
Joined
Sep 13, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,419
sbuf in 8051

please help me .

I use uvision Kiel software to program 8051 using C language like this :
unsigned char SerialRecvChar()
{
//initialization
TMOD = 0x20; // timer 1 (8 bit auto-reloed)
TH1 = 0xFD; //to obtain 9600 baud rate
TR1 = 1; //start timer
SCON = 0x50;
//IE= 0x90;
P1= 0x00;

unsigned char i;
while(!RI); //waits till a byte is recieved
RI = 0;
i = SBUF ; //must get SBUF value
return SBUF;
}


but when I run the code to show (i = Sbuf ) then (i) not get the value from SBUF )
 

sbuf register in 8051

simplest example (read & write from RS232 using Hyperterminal baud rate 1200) 8051

Get the value in main

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)
{




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


while (1)
{
your code



}//end of while
}//end of main
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top