| Author |
Message |
bill_test36
Joined: 20 May 2003 Posts: 23
|
06 Sep 2003 4:45 8051 SERIAL MODE |
|
|
|
I USER 8051 SERIAL MODE transmission DATA but no success in mode 2 and mode 3 .
how to 8051 SERIAL MODE control???
|
|
| Back to top |
|
 |
silvio
Joined: 31 Dec 2001 Posts: 798 Helped: 90
|
06 Sep 2003 5:05 |
|
|
|
Hi bill_test36
Can you post your code here ?
|
|
| Back to top |
|
 |
lind
Joined: 11 Sep 2003 Posts: 8
|
12 Sep 2003 12:18 Re: 8051 SERIAL MODE |
|
|
|
Hello there,
Try this link:
http://www.8052.com/tutser.phtml
They have an easy to understand explanation on serial mode programming. I used to implement these modes without any problems.
Ask again if any questions.
|
|
| Back to top |
|
 |
mgajo
Joined: 15 May 2001 Posts: 346
|
12 Sep 2003 15:39 Re: 8051 SERIAL MODE |
|
|
|
Hi
;THIS WILL SEND 'OK' VIA SERIAL PORT ON 8051
SER_INIT:NOP ;9600 Q = 11.0592
MOV PCON,#10000000B ;80H
MOV TMOD,#00100010B ;22H
MOV TH1,#0FAH
MOV TL1,#0FAH
MOV SCON,#52H
SETB TR1
RET
------------------------------------
MOV A,#'O'
MOV R6,A
LCALL SEND
MOV A,#'K'
MOV R6,A
LCALL SEND
SJMP $ ; LOOP FOREVER
SEND:JNB SCON.1,SEND
CLR SCON.1
MOV SBUF,R6
RET
|
|
| Back to top |
|
 |
bill_test36
Joined: 20 May 2003 Posts: 23
|
14 Sep 2003 7:37 Re: 8051 SERIAL MODE |
|
|
|
| bill_test36 wrote: |
I USER 8051 SERIAL MODE transmission DATA but no success in mode 2 and mode 3 .
how to 8051 SERIAL MODE control???  |
#include "reg51.h"
char table[10]={0x01,0x4f,0x12,0x06, /* 0,1,2,3 */
0x4c,0x24,0x60,0x0f, /* 4,5,6,7 */
0x00,0x0c}; /* 8,9 */
int KeyData=0xff;
char InputBuffer=0xff;
char OutputBuffer=0xff;
main()
{
SP=0x60;
IE=0x92;
TMOD=0x01;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
TR0=1;
PCON&=0x7f;
SCON=0x90;
P1=table[0];
while(1)
{
KeyData=P3;
if(KeyData!=0xff)
{
if(KeyData==0x0a)
SBUF=OutputBuffer;
else if(KeyData==0x0b)
P1=table[InputBuffer];
else if(KeyData>=0 && KeyData<=9)
{
P1=table[KeyData];
OutputBuffer=KeyData;
}
}
}
}
void T0_int(void) interrupt 1 /* T0=2ms */
{
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
}
void SCON_int(void) interrupt 4
{
if(TI==1)
TI=0;
else
{
RI=0;
InputBuffer=SBUF;
}
}
|
|
| Back to top |
|
 |
Ilya
Joined: 26 Mar 2002 Posts: 19
|
14 Sep 2003 17:45 Re: 8051 SERIAL MODE |
|
|
|
How you check your program?
If use the terminal that remember
9 bit is no PARITY bit, is TB8
And you should SET or RESET it manually.
You use mode 2 and have BAUDrate 1/64 Fosc or 1/32 Fosc if SMOD=1.
if you use simulators, they correctly simulated not all.
Your program is not absolutely correctly written,
But to work basically can
Begin from a simplis echo
аlso do not use interruptions
I slightly modified, like should work.
But the stipulations about ninth bit and speed remain in force.
WBR, Ilya
#include "reg51.h"
char table[10]={0x01,0x4f,0x12,0x06, /* 0,1,2,3 */
0x4c,0x24,0x60,0x0f, /* 4,5,6,7 */
0x00,0x0c}; /* 8,9 */
int KeyData=0xff;
char InputBuffer=0xff;
char OutputBuffer=0xff;
main()
{
SP=0x60;
IE=0x92;
TMOD=0x01;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
TR0=1;
PCON&=0x7f;
SCON=0x90;
P1=table[0];
// this part mods
ES=0;
RI=0;
while(1)
{
if (RI){
RI=0;
KeyData=SBUF;
SBUF=KeyData;
while(!TI){};
TI=0;
}
}
}
void T0_int(void) interrupt 1 /* T0=2ms */
{
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
}
|
|
| Back to top |
|
 |
silvio
Joined: 31 Dec 2001 Posts: 798 Helped: 90
|
14 Sep 2003 22:11 Re: 8051 SERIAL MODE |
|
|
|
Hi bill_test36
Looking at your code I saw as follows:
On P1 attached a 7 segment LED display (char table[10])
On P3 some kind of keyboard
What probably you have in mind is:
When you send 0x0b on P3 via keyboard, on P1 is displayed last byte data sent from PC to 8051 (be aware that in order to be accurately displayed you must subtract 0x30, due to the ASCII char; you can even check if the data is bounded between "0" and "9")
When you send 0x00 up to 0x09, it's displayed on P1. After you type 0x0a, the previous digit it's sent from 8051 to PC (same as above, but you have to add 0x30 in order to see on PC the number and not control chars from 0x00 to 0x09)
Thus, you must check if the baud rate on PC match the one set on 8051 in mode 2 (fOSC / 32)
You can easily calculate because you know the XTAL frequency.
Bear in mind the 0x30 mentioned above.
Regards,
Silvio
|
|
| Back to top |
|
 |
senthilkumar
Joined: 24 Nov 2001 Posts: 630 Helped: 3 Location: india
|
20 Sep 2003 11:18 |
|
|
|
hai,
use keil simulator.
u can easily find mistake.
|
|
| Back to top |
|
 |