Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem in processing data recieved through UART and display on GLCD

Hello. I'm sending data using UART from one end to recieve at the other end, process it and display on GLCD. I'm recieving the data right. But I'm confused how to display it on GLCD. I'm using MicroC for PIC compiler. Using its inbuilt libraries.
Setup: PIC16F877 ----> HC-12 -----> HC-12---> PIC16F877---> GLCD and some LEDs
Here are some snippets of the transmitter and reciever code.
Transmitter side:
if(display_time == 1)
{
UARt1_Write_Text(",");
if(Temp_flag == 0) UART1_Write('i');
else UART1_Write('m');
UART1_Write(TEMP_PERC); //Analogue value between 0-100
UART1_Write(')');
}

Reciever side:
char txt[16];

if (UART1_Data_Ready() == 1)
{
check1 = UART1_Read();
if(check1 == 'i')
{
RECEPT_LED = 1;
UART1_Read_Text(txt,")",1); // reads text until ')' is found
i_LED = 1;
m_LED = 0;
RECEPT_LED = 0;
}
.
.
if(m_LED == 1)
{
Glcd_Set_Font(Font_Glcd_Character8x7, 8, 7, 32);
Glcd_Write_text(Ltrim(txt), 45, 2, 1); // if I print "txt" a bracket is printed like this "]"
Glcd_Write_Text("%", 70, 2, 1);
}
Displayed "]" represents "93" is recieved which is correct, but I want to print 93 not "]".

Recieved "txt" via UART is a string (I guess) still do I need to convert it to string or is there problem in method of printing the value. Bit slow understanding LCDs and strings and the libraries.
 
Without understanding all the details of your code, the issue is between the character "9", which is ASCII code 57, and the value 9 – string vs numeric value. Both ends must agree on what's being sent and received.
 
Without understanding all the details of your code, the issue is between the character "9", which is ASCII code 57, and the value 9 – string vs numeric value. Both ends must agree on what's being sent and received.
Aim is to send a value between 0 to 100. But for now I am sending 93 so as to test the reciever and display first.
 
Aim is to send a value between 0 to 100. But for now I am sending 93 so as to test the reciever and display first.
As you've already been told, you MUST keep track of using strings or numeric variables - I would strongly suggest you stick to strings. You've got to convert numbers to strings somewhere, and doing so before you send it over the UART makes much more sense (RS232 uses various numeric values for control characters, such as CR and LF).
 
I don't disagree with the distinctions being made.

Here's something to consider:
My current project is done mostly in BCD, and I don't use packing as RAM is not limiting. Thus, I send, read, and calculate in BCD*, e.g., dec. 9 (BCD) = 0x39 = dec. 57 ASCII. It's easy to convert back and forth. ASCII control characters don't interfere, and 0 (zero) can be used as a terminator -- another advantage of using strings. That eliminates most of the complicated converting from binary to characters.

*My calculations in BCD are limited to additions and subtractions at that point in the code. Seven BCD (6 digits and a sign) are used. A decimal is set separately. The only part where I do a BIN2BCD is when converting a BCD value in mm to BCD inches.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top