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.
It isn't clear what you want. Are you trying to send two characters "?" then "f" as a command to start an LCD clearing routine or are you trying to send them directly to the LCD?
And why on Earth are you using a software UART when there is a hardware one inside the PIC? Using the hardware one makes the code MUCH easier to write and far more reliable, particularly as you are also using blocking delay routines.
If I understand, you just said that wrong, just sending 'f' or 'g' would print those character son the LCD rather than treat them as instructions. I think what you are trying to do is use the '?' to indicate the next character is an instruction.
Basically, just look for the '?' from your receive routine and when you find it, drop into a routine that again waits for a character, decodes it and performs the action you require. However, I have reservations about your timing routines and it might not work as you intended. With the software UART you are using, it is essential you are monitoring the input state at a constant rate or you will miss any character arriving. Consider that while in your delay routine, transmitting or while writing to the LCD, you are vulnerable to losing bits in the input stream. A much better way of doing it is to use the hardware UART and interrupts. The code will be smaller and can be doing something else while still receiving serial data. An interrupt will alert your program when all 8 bits of data have been received and is ready to use, you don't have to do any timing code or loops at all.
1. Add a new variable to the cblock, lets call it "CmdMode". We will make this = 1 if a '?' is received.
2. Call the rcv_RS232 routine to get a character from the serial input.
3. Compare it to '?' and if it matches, make CmdMode = 1. Hint: subtract or XOR the received value with '?' and check the Z flag in the STATUS register.
4. When you call rcv_RS232, check if CmdMode = 1 and the character is 'f', if both are true, call 'LCD_Clr' to clear the display then 'clrf CmdMode' so the next character works as normal.
I still think you will have problems. The RS232 routines are 'real-time', they will not wait for data to arrive so you must constantly call rcv_RS232 to make sure you don't miss anything. While in the delay routines or waiting for the LCD to go ready, the serial input will not be monitored. Think of the data arriving constantly on a conveyor belt, if you aren't there to off load it all the time things fall off the end and are lost. Using the USART interrupt is easy and will overcome this problem.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.