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.

[51] Serial communication with 8052

Status
Not open for further replies.

tntsei

Newbie level 2
Newbie level 2
Joined
Feb 4, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
18
I everybody!!!

I'm new and my name it's Karim!!... Nice to meet you!!

I have a problem with my 8052 MCU and and I wanted to ask if you could give me some help!!!:-o

i Try to connect my 8052 MCU ( Aduc836 ) with one display touchscreen ( 4D systems uLCD 70 - DT) by serial TTL.

What i want to do for this moment it's always send a char ('a')when i push a button on the display and send thsi to my MCU....when the MCU receive the char, turn on one led, else if the the char receive it's wrong, turn on another led!!

The problem that i hacve it's that inside the SBUF register i have always in every case the value 0xFF and i can't understand why!!!!

Below the MCU code!!

Code:
#include <reg52.h>

sbit P3_4 = P3^4;
sbit P3_5 = P3^5;

void  RecDat(void)
{
    unsigned char dat;
    
    RI = 0;    // this is a flag set by hardware and cleared by software
    dat = SBUF;    // SBUF it's a 8 bit buffer that contains the 8 bit data received by uart
    P2 = 0xFF;     // i set ths port to this value to turn on the display

   if( dat == 'a' )
	 {
		P3_4 = 0; // turn on the correct led
		P3_5 = 1; // turn off the wrong led
	 } 
	 else 
	 {
		P3_4 = 1;    // turn off the correct led
		P3_5 = 0;    // turn on the wrong led
	 }
}

void InitSerial(void)   // Simply setting for UART and BaudRate MCU
{
    TMOD |= 0x20; // Timer 1 in mode 2 (auto reload)
    TL1 = 0xFD; // 9600 baud rate
    TH1 = 0xFD;
    SCON = 0x50; // Setup UART mode 2
    TR1 = 1; // Start Timer1 and UART
}

void main (void) {
        
    P2 = 0x00;
    
    InitSerial();

    while (1)
        {
        if (RI) { // if a receive the data by Serial RI it's setting by hardware to 1
            RecDat ();
        }
    }
}

if a modify the condition

Code:
if( dat == 'a')

with

Code:
if( dat == 0xFF )

The correct led it's turn on even though i send the value 'a'!!!!!
Any advice???? are quite distressed!!!
 

Hi...i solved!

The problem was due to the baud rate.....

the timer 1 works to 9600 always if the frequency clock it's 12.58MHz....in my case i work to 1.57MHz....

For this reason was necessary change the baud rate source witrh the timer2 that with 1.57MHz works correctly to 9600 (9830 real) baud/sec.

PS. my communication it's withour max232.....i implement a ttl serial communication
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top