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 COMMUNICATION FOR 8051

Status
Not open for further replies.

nautisandeep

Newbie level 5
Joined
Feb 25, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
pune
Activity points
1,340
HI!
I AM WORKING ON RFID IMMOBILIZER PROJECT FOR 2 WHEELER.I HAD A PROBLEM ON HOW TO STORE THE DATA IN SBUF.THR RFID TAG HAS UID OF 10 BYTES [80 BITS].NOW I NEED TO STORE THESE BITS IN SBUF of 89c51.PLEASE HELP ME IN SLOVING THE PROBLEM.ITS URGENT.

THNXS.


can send the reply to
nautisandeep@gmail.com
 

SBUF is only one byte, anything you put there gets sent serially right away. You need to sent each byte as a separate item, check busy flag in between bytes or use a few milliseconds delay between each byte. If you are using C the Printf may be better for you.

Added after 4 minutes:

Sorry, did you mean receive 10 bytes. If so an interrupt driven function writing to a software buffer is probably the way to go.
 
can u plz help me with the code

Added after 1 minutes:

the UID in the rfid tag is 10 bytes.....
 

Code:
; Program to receive bytes of data serially and save them in M(30), M(31), M(32) ..
; Serial port setup – 4800bps, 8-data, 1-stop ..

MOV	TMOD, #20h	; timer1, mode 2 (auto reload)
MOV	TH1, #-6	; 4800 baud
MOV	SCON, #50	; 8-bit, 1 stop
SETB	TR1		; Start Timer1
MOV	R1, #30h	; Memory location for storing data ..
Loop:
JNB	TI, Loop		; Wait for a char to come in
MOV	A, SBUF		; Save incoming byte in A
MOV	@R1, A		; Save A in memory location @R1
INC	R1		; Next memory location ..
; next line of code should test condition that indicates how many bytes of data is to be stored in the mcu’s memory ..
CLR	RI		; get ready to receive next byte
SJMP	Loop		; keep getting data

This section of code is just an example ..
I hope you know how fast the data is going to be transmitted, what crystal is used etc. etc .. then the code can be modified to include these parameters ..

IanP
:|
 

You need to be more specific about what you are trying to do and what language, Assembler, C, Basic etc. Good resource for code is 8052.com
 

i am doing c programming in keil s/w.here i am using 11mhz crystal,9600 baud rate

Added after 25 minutes:

i need to send the 10 bytes of data on to the UART & to the controller 89c51.this 10 bytes is the unique ID of my RFID tag.so that after sending the ID on to the controller it will turn on the relay so the ignition will turn on/off.right now i need to glow an LED instead of the ignition system of 2 wheeler bike.i am using 11 mhz crystal,9600 baud rate.

the ID is getting detected and i am able to display on to the PC. even i want to know whether i need to write any driver protocol for serial communication for 8051.i have code for windows.

thnxs in advance
 

Simple basic principle if you can afford to have the processor just hanging about waiting for data. Checkout Keils site for timed serial or interrupt driven. These are just some ideas and need to be incorporated into other code, and not really workable as is.


// In initialisation
#define BUFSIZE 10
volatile unsigned char fifo[BUFSIZE];
volatile unsigned rd=0, wr=0; // read and write positions

void main(void)
{
while (1)
{
fifo[wr] = _getkey(); // Gets Number from Serial Port
wr = (wr + 1) % BUFSIZE;
}
}


// general principle for reading. Needs to be in a loop
Num = (fifo[rd]); // Read Buffer
rd = (rd + 1) % BUFSIZE;


// This if for 300 baud, there is a calculator on Keils site for other baud rates
void serial_init (void) {
TMOD = 0x20; // Timer 1 mode 2: 8-Bit reload
TH1 = 0x98; // Reload value 300 baud
SCON = 0x52; // Mode 1: 8-bit UART, enable receiver TI remains set
TR1 = 1; // Timer 1 run
ES = 0; // Disable serial port interrupt
EA = 0; // Disable
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top