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.

Trouble with 8051 uart

Status
Not open for further replies.

adisas91

Newbie level 3
Newbie level 3
Joined
May 6, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,321
Guys,
Am new to this forum, Please help me with this bit of code I have written for syncmos sm59r16a3,
I am actually writing this code to receive a byte of data from pc, if the data's MSB is set to one it is written to port 1 or if it is 0 it is written to port 0.
The max 232 circuit has been purchased from a store, so there's no problem with it.
Now when I turn on my MC, it automatically turns port 0 and port 1 high, irrespective of whether or not its receiving any data from the pc.
Code:
#include<reg52.h>
unsigned char AA,BB,x;
void intiserial(void)
{
        TCON=0X00;
        TMOD=0X21; 
        SCON=0x50;
        TL1=0XFD;
        TH1=0XFD;
        TR1=1;
        ES=1;
}
void delay(unsigned int x)
{
  unsigned int i;
  for(i=0;i<=x;i++)
 { 
  TH0=0XFC;
  TL0=0X17;
  TR0=1;
  while(!(TF0==1));
  TR0=0;
  TF0=0;
  }
}

void MOTOR(void) interrupt 4
{
 EA=0;
 RI=0;
x=SBUF;
if(x&0x80)
BB=x;
else
AA=x;
delay(250);
 EA=1;// Enables interrupts
}
  void main()
  {

        intiserial();
        AA=0x00;
BB=0x00;

        EA=1;
 while(1)
 {
   P0=AA;
   P1=BB;
 }
         
}

Also am thinking of using 19200 baud rate, is it safe?
Also **broken link removed** is the link to syncmos datasheet for reference
 

You forgot to mention an important parameter.

What is your crystal/clock frequency?

BigDog
 

@adisas
1)if you have 25MHz clock then your baudrate is: 21701
2)make ports as outputs: push/pull

p.s.
try this code in Keil c debuger
 

adisas,


What compiler are you using ?
I guess the evaluation code inside MOTOR function, could have been written in a better way.

REMARKS :
1 ) Not a good idea to put a delay inside interrupt treatment function.
2 ) Put that delay, before and after core configuration routines.

+++
 
Last edited:

@bigdoggoru I am using a 11.0592 mhz crystal
@js I am actually using keil, but am confused as hell, I mean how do u give input in uart window in the simulation ? It doesn't allow me to type there like,
I have my cursor flashing in the uart window, but when I type character, doesn't appear there !! very frustrating. also, I was getting -5v on the pins.
@andre_teprom That delay thing was a typo, it was something I was trying earlier that I no longer need,I will put it after the initserial,since I will be sending data like once in every 2 seconds or so. I didnt had that delay call when I was testing though.
 

-when you start DEBUG go to PERIPHERALS and then Serial window (you will see baudrate)....
you have now: 9600 baudrate
If you want 19200 you must set SMOD1 to 1

-open serial window (View - Serial windows - UART1)
note: you must click inside window and type some character, then go to debug source windows in try step by step (F10 or F11)
 
I tried initializing RI,SBUF,P0,P1, AA,BB to 0 and it worked out, in keil. The characters still don't show in the window though, but the port value's reflect according to the input.
I will be trying this code with the MC in the evening, my friend has the circuit.

@js any reason you might think it might not work now ? I mean it works fine in keil ? I dont have net connectivity in our college lab, since we have summer vacation now.
 

as I say in topic #3
ports aren't configured as output!
see your datasheet and download keil c development tool at
http://www.keil.com/c51/devproc.asp
(free to 2k code)


ps
your datasheet:
**broken link removed**
see page 30
5. GPIO
PxM1.y PxM0.y Port output mode
0 0 Quasi-bidirectional (standard 8051 port outputs) (pull-up)
0 1 Push-pull
1 0 Input only (high-impedance)
1 1 Open drain
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top