View previous topic :: View next topic |
Author |
Message |
ercarlitosg
Joined: 08 Sep 2014 Posts: 20
|
Problem with wrapping lcd_putc |
Posted: Wed Jul 29, 2015 4:51 am |
|
|
Hello,
I am using now a PIC16F877A and the flex_lcd driver. I am using the lcd to display a text when received one of the 14 commands that I receive from the serial port. Parsing and receiving the code isn't a problem, it works prefect.
The problem is displaying the text in the LCD. In the 14 commands I have to run some functions (disable keyboard and serial input, show the text, delay 3 seconds, reset serial input variables and display another text). Copying and pasting this into every command section is a monstrous task!!.
So I decided to make a wrapper to the run these functions. Here it is
Code: |
void muestra_mensaje(char data) {
disable_input();
/* Limpia pantalla */
lcd_putc("\f");
lcd_putc(data);
send_ok();
} |
The problem is in lcd_putc(data);. It doesn't display the message.
Thanks for your answers |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 29, 2015 7:47 am |
|
|
Show us how you call the function. Post some code, including variable
declarations and initializations, that calls muestra_mensaje().
My suspicion is that you think 'char data' is a pointer and that somehow
lcd_putc() will work with a string pointer inside muestra_mensaje(). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Jul 29, 2015 8:07 am |
|
|
As written, it'll only display one character. The single character 'data'.
I'd guess he actually wants to pass it a char array (string):
Code: |
void muestra_mensaje(char * data)
{
disable_input();
/* Limpia pantalla */
printf(lcd_putc,"\f%s",data);
send_ok();
}
|
|
|
|
ercarlitosg
Joined: 08 Sep 2014 Posts: 20
|
|
Posted: Sat Aug 22, 2015 4:59 am |
|
|
Thanks for your answers.
Here is some examples of how I call that function:
Code: |
muestra_mensaje("HI");
muestra_mensaje("\nHI");
|
So that code doesn't work if I don't want to clear the screen.
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 22, 2015 1:45 pm |
|
|
Quote: | So that code doesn't work if I don't want to clear the screen. |
But you can edit Ttelmah's code and remove the \f from the printf
so it becomes this:
Code: |
printf(lcd_putc,"%s",data); |
Also, you need to add the line shown in bold below, or it won't compile.
With the added #device statement, it displays this in MPLAB vs. 8.92 simulator:
Test program:
Quote: |
#include <18F4620.h>
#device PASS_STRINGS=IN_RAM
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
void lcd_putc(char c)
{
putc(c);
}
void muestra_mensaje(char * data)
{
// disable_input();
printf(lcd_putc,"\f%s",data);
// send_ok();
}
//===================================
void main()
{
muestra_mensaje("HI");
while(TRUE);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Aug 22, 2015 1:57 pm |
|
|
Yes. I only added the \f, because he had it in his original code..... |
|
|
ercarlitosg
Joined: 08 Sep 2014 Posts: 20
|
|
Posted: Thu Aug 27, 2015 11:58 am |
|
|
Sorry for my bad response. I don't know why I put that.
I refer that the code didn't worked with a constant string, but with the last response of PCM programmer It worked.
Many thanks for your help and sorry for my expression. |
|
|
|