Hi everybody!!!
I'm new and i need some help!!!
Nice to meet you!!!
I'm trying to connect my Aduc836 (8051 architecture) with a 4d systems display by Serial TTL.
What i want to do for this moment it's simply send a char by the display and turn on one led on my boards.... the problem I have is that I can not read properly the character sending by the display.
Below the code on my MCU:
#include <reg52.h> sbit P3_4 = P3^4; sbit P3_5 = P3^5; bit flag = 0; idata unsigned char rx; void UART_intialization(void) { SCON = 0x50; // 8 bit, variable baud rate + REN = 1; TMOD &= ~0xF0; // timer1 bit set to 0 TMOD |= 0x20; // timer 1, autoreload TL1 = 252; // baud rate 9600 TH1 = 252; ES = 1; // interrupt serial enable EA = 1; // all interrupt souce enabled; TR1 = 1; // start timer1 } void int_Serial(void) interrupt 4 { if(RI != 0 ) { RI = 0; rx = SBUF; flag = 1; } } void main(void) { UART_initialization(); while(1) { if( flag ) { if( rx == 'a' ) P3_4 = 0; // if i read the correct value ( i send by display the char 'a') // i turn on one led else P3_5 = 0; // else if the value that i read it's wrong i turn on another led } flag = 0; } }
the code send by the display it's a simple instruction serout('a') , that works correctly.
Any advice?
Thank you Erik, but i know the bible!
I think that i have a baudrate problem between the two devices
1) did you understand the SBUF issue 2) make a device output a stream of 'U' (0x55) anda scope will show a square wave with a frequency of 1/2 the baudrete
Erik
Hi Erik!!!
I solved yesterday!!
The problem was due to the baud rate that was different by 9600..... i set in the wrong way the TH1 register with the timer1.......the timer1 works to 9600 baud always with 12.58 MHz frequency clock and not to 1.57 MHz.......for this reason i change the baud rate source and i use the timer2 in autoreload mode with 1.57 MHz and the problem was solved.