CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Clear LCD at the LCD end

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
xero
Guest







Clear LCD at the LCD end
PostPosted: Sun Sep 28, 2008 1:07 am     Reply with quote

Hi
I'm running keypad to LCD as code below;
Code:

#include <16f877a.h>
#use delay (clock = 40000000)
#fuses hs,noprotect,nowdt,nolvp

#BYTE PORTA=5
#BYTE PORTB=6
#BYTE PORTC=7

#include <flex_lcd.c>
#include <kbd44.c>

void main()
{
char n;
set_tris_a (0x0f);
set_tris_b (0);
set_tris_c (0);

lcd_init();
kbd_init();
lcd_putc("\fStart...\n");
delay_ms(500);
lcd_putc("\f");

while(TRUE)
{
   n=kbd_getc();
   if(n!=0)
      {
      if(n=='*')
         lcd_putc('\f');
      else
      lcd_putc(n);
      }
}
}

This program only clear after keypad * pushed.
How to make the program:
1. Move to next line when it reach the end of line 1 and,
2. Clear LCD when it reach the end of line 2 and reset back to (1, 1).
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Mon Sep 29, 2008 10:06 pm     Reply with quote

Hi xero,

Please read the entire flex_lcd.c driver. All functions are documented in it pretty well ( http://www.ccsinfo.com/forum/viewtopic.php?t=24661 ).

You will have to check for the number of characters you are sending to the LCD. If it exceeds 16 then either use lcd_gotoxy() or a simple \n to goto the next line.

A simple suggestion for implementation would be to have a global 'character counter' variable, and a 'line number' bit.

Implement this in the function lcd_putc(), just before the switch statement. Increment the counter each time this function is called. You could check that the value of the character counter remains below 16. If it is greater than 16, check the line number. Accordingly, inject either a \n or a \f character.

Rohit
xero
Guest







PostPosted: Tue Sep 30, 2008 1:44 am     Reply with quote

Thanks for reply. It's really helpful. But the problem is i dont know the right command to count until 16. If try using if (n>16) but nothing. What the right command for me to use?
TQ
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 30, 2008 2:50 am     Reply with quote

xero:

Declare n as a global int8 and linebit as a global int1 as below:
Code:
int8 n= 0;
int1 linebit = 0;


n is the counter that counts how many chars you have printed to the line; linebit is the flag that checks the current line number.

Then insert the following before the switch statement in the function lcd_putc() in flex_lcd.c
Code:
if ((n>0) && (linebit==0))
{
      lcd_gotoxy(1,2);
      n = 16;
      linebit=1;
}
if ((n>0) && (linebit==1))
{
      lcd_send_byte(0,1);
      delay_ms(2);
      n = 16;
      linebit=0;
}
n--;


I've used a '--' in the last line since with this the zero flag is checked int he STATUS register of the PIC, and hence it is much faster than using a '++'.

I'm at work and I don't have my PC with me so I can't verify the code functioning, though I think it should do the trick.

Rohit
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 30, 2008 3:36 am     Reply with quote

xero:

I think you've already used n for the keyboard input. Use a different variable name in the code I've given you. Of course, I don't need to tell you this, but just in case you're tearing your hair out wondering why the code isn't working :-P

Rohit
xero
Guest







PostPosted: Tue Sep 30, 2008 8:40 pm     Reply with quote

I have tried codes given but nothing appear on LCD. I already change the n to x as below;
Code:

void main()
{
char x;


set_tris_a (0x0f);
set_tris_b (0);
set_tris_c (0);

lcd_init();
kbd_init();

lcd_putc("\fStart...\n");
delay_ms(500);
lcd_putc("\f");

while(TRUE)
{
   x=kbd_getc();
   if(x!=0)
      {
      if(x=='*')
         lcd_putc('\f');
      else
      lcd_putc(x);
      }
     

     
}
}


and for flex_lcd the codes u given added;
Code:

void lcd_putc(char c)

{
int8 n= 0;
int1 linebit = 0;

if ((n>0) && (linebit==0))
{
      lcd_gotoxy(1,2);
      n = 16;
      linebit=1;
}
if ((n>0) && (linebit==1))
{
      lcd_send_byte(0,1);
      delay_ms(2);
      n = 16;
      linebit=0;
}
n--;

 switch(c)

Sorry if I miss something minor. I'm too new in this. Embarassed
Anyway I'm very thankful for all your help.
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 01, 2008 12:34 am     Reply with quote

xero:

A couple of questions, (and I should have probably asked you to do this earlier):
-Post a description your system circuit.
-Which pins are you using for the LCD
-Have you modified flex_lcd.c in any way?
-Have you got an LCD to work before modification/addition of the code I gave you?

xero wrote:
I have tried codes given but nothing appear on LCD.
Code:

void main()
{
.
.
.
set_tris_a (0x0f);
set_tris_b (0);
set_tris_c (0);
.
.
.



I think your error lies in this segment of code. flex_lcd requires the use of standard_io and not fast_io. The compiler itself handles setting of the pins as inputs or outputs in the standard mode. By using the statement set_tris you are preventing the compiler from using one of the pins (specifically the R/W pin) as an input-output pin. Therefore, you will have a blank LCD (unless you configure some other parameters in flex_lcd - lets leave this aside).

My suggestion to you is to read http://www.ccsinfo.com/forum/viewtopic.php?t=24661 . This is the page for the flex_lcd driver. By default the driver configures the LCD data pins on PORTD and the control pins on PORTA. The R/W pin is on PORTA. The LCD is configured as a 7 pin, 4bit mode LCD. Please make sure that you have connected the pins correctly. First try displaying something on the LCD without modifying the driver. Only after you have successfully got this working, then move onto the automatic line feed/line clearing.

Rohit
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 01, 2008 12:40 am     Reply with quote

xero:

Please define the int8 n and int1 linebit as global variables. They should be defined before the 'main' function, and not inside lcd_putc(). Defining them inside lcd_putc() makes them local variables, and they will lose their values every time the function exits.

Rohit
xero
Guest







PostPosted: Wed Oct 01, 2008 4:37 am     Reply with quote

I'm building a simple keypad to LCD.
LCD connect to port A and D (default connection for flex_lcd).
Keypad connection:
#define ROW0 PIN_C0
#define ROW1 PIN_C1
#define ROW2 PIN_C2
#define ROW3 PIN_C3
#define COL0 PIN_B0
#define COL1 PIN_B1
#define COL2 PIN_B2
#define COL3 PIN_B3


Quote:
First try displaying something on the LCD without modifying the driver. Only after you have successfully got this working, then move onto the automatic line feed/line clearing.


I have try original flex_lcd driver from link given and try sample coding and success.

After implement your codes into flex_lcd driver the LCD show only one character and overwrite at every time i push the button. Nothing happened after 16times the button pushed.



Quote:
int8 n= 0;
int1 linebit = 0;
void lcd_putc(char c)
{

if ((n>0) && (linebit==0))
{
lcd_gotoxy(1,2);
n = 16;
linebit=1;
}
if ((n>0) && (linebit==1))
{
lcd_send_byte(0,1);
delay_ms(2);
n = 16;
linebit=0;
}
n--;

switch(c)
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Thu Oct 02, 2008 1:18 am     Reply with quote

xero:

Sorry, couple of logical errors on my part. My bad. Embarassed Please use the following code for the function lcd_putc() in flex_lcd:
Code:
void lcd_putc(char c)
{
    if ((chars==0) && (linebit==0))      //add this code
   {
      lcd_gotoxy(1,2);
      chars = 16;
      linebit=1;
   }
   if ((chars==0) && (linebit==1))
   {
      lcd_send_byte(0,1);
      delay_ms(2);
      chars = 16;
      linebit=0;
   }                                     //upto here
   

switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1,2);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
   
   chars--;                             //add this also
}



Here is some sample code to help you:
Code:
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

int8 chars= 16;                       //global declaration
int1 linebit = 0;

#include "FlexLCD.c"

void main ()
{
   delay_ms(10);
   lcd_init();
   
   delay_ms(10);

   printf(lcd_putc,"\f");
   delay_ms(10);
   
   while (1)
   {
      lcd_putc("1");
      delay_ms(500);
      lcd_putc("2");
      delay_ms(500);
      lcd_putc("3");
      delay_ms(500);
   }
}


Do note that control characters "\f", "\n", "\b" count as characters as well, so sending them will cause the variable chars (which is the 'number of characters displayed' counter) to decrement.

Rohit
xero
Guest







PostPosted: Thu Oct 02, 2008 7:09 am     Reply with quote

Thanks a lot!!! your program working perfectly Very Happy Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group