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 CCS Technical Support

keypad response too slow
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

keypad response too slow
PostPosted: Sun Dec 21, 2014 8:34 am     Reply with quote

Hello,

In my project keypad response too slow. PIC response 3-4 seconds later after key press.

I am using modified lcd driver for 3 wire using 74hc595

Compiler version 4.124

what I have to do


Code:
#include <16F877A.h>
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
         

#use delay(clock=16000000)



int i;
int16 dat=0,value_1,value_2;

//define 74HC595 PINs
#define lcd_data   PIN_B5
#define clock      PIN_B7
#define Strobe     PIN_B6


#include "74HC595_flex_LCD420.c"
#include <Flex_KBD_4X4.C>
#include <2432.c>
////////////////////////////////////////////////////////////////////////////////
void main(){


   char k;

   lcd_init();
   kbd_init();
   printf(lcd_putc, "\f");   // Clear the LCD.
delay_ms(50);
/////////////////////////////////   
   lcd_gotoxy(4,1);
   printf(LCD_PUTC,"Nano Technologies");
   lcd_gotoxy(1,2);
   printf(LCD_PUTC,"74HC595_Serial_LCD");
   
   lcd_gotoxy(1,3);
   printf(lcd_putc,"3rd Line");

   lcd_gotoxy(5,4);
   printf(lcd_putc,"4th Line         ");
   
   
   delay_ms(50);
////////////////////////////////////////////////////////////////////////////////   
while(true){

   k=kbd_getc();
   if(k!=0)
     {
        lcd_gotoxy(2,1);
         printf(lcd_putc, "%c",k);
     }
   
   dat++;
   lcd_gotoxy(10,3);
   printf(LCD_PUTC,"%05ld   ",dat);
   
}
}



Lcd driver

Code:
// 20X4 LCD driver-- Shehab
// Flex_LCD420.c

//4094(Shift Register) 3wire Serial To Parallel
byte d0,d1,d2,d3,d4,d5,d6,d7;
/*
#IFNDEF lcd_data
#define lcd_data      PIN_A0
#define clock     PIN_A1
#define strobe    PIN_A2
#ENDIF
*/
//4094   Shift Register
void set_shift(int8 value)
{
int8 location=0,n=0;
location=128;
for(n=1;n<=8;n++){
    if ((value & location)>0) output_bit(lcd_data,1); else output_bit(lcd_data, 0);
      output_bit(clock,1);
      location=location / 2;
      output_bit(clock,0);
}
 output_bit(strobe,1);
 output_bit(strobe,0);
}

void f_output(byte value)
{
   set_shift(value);
}

void fatport()
{
int value;
value=0;
if (d0==1) value=value+1;
if (d1==1) value=value+2;
if (d2==1) value=value+4;
if (d3==1) value=value+8;
if (d4==1) value=value+16;
if (d5==1) value=value+32;
if (d6==1) value=value+64;
if (d7==1) value=value+128;
f_output(value);
}


void dg0(int value)
{
d0=value;
fatport();
}

void dg1(int value)
{
d1=value;
fatport();
}

void dg2(int value)
{
d2=value;
fatport();
}

void dg3(int value)
{
d3=value;
fatport();
}

void dg4(int value)
{
d4=value;
fatport();
}

void dg5(int value)
{
d5=value;
fatport();
}

void dg6(int value)
{
d6=value;
fatport();
}

void dg7(int value)
{
d7=value;
fatport();
}

void f_output_bit(byte pin,value)
{
   switch(pin)
   {
      case 1:dg0(value);
            break;
      case 2:dg1(value);
            break;
      case 3:dg2(value);
            break;
      case 4:dg3(value);
            break;
      case 5:dg4(value);
            break;
      case 6:dg5(value);
            break;
      case 7:dg6(value);
            break;
      case 8:dg7(value);
            break;           
   }
}


void f_output_high(byte pin)
{
   switch(pin)
   {
      case 1:dg0(1);
            break;
      case 2:dg1(1);
            break;
      case 3:dg2(1);
            break;
      case 4:dg3(1);
            break;
      case 5:dg4(1);
            break;
      case 6:dg5(1);
            break;
      case 7:dg6(1);
            break;
      case 8:dg7(1);
            break;           
   }
}


void f_output_low(byte pin)
{
   switch(pin)
   {
      case 1:dg0(0);
            break;
      case 2:dg1(0);
            break;
      case 3:dg2(0);
            break;
      case 4:dg3(0);
            break;
      case 5:dg4(0);
            break;
      case 6:dg5(0);
            break;
      case 7:dg6(0);
            break;
      case 8:dg7(0);
            break;           
   }
}
// 20X4 LCD driver-- Shehab
// Flex_LCD420.c

#define LCD_DB4   5
#define LCD_DB5   6
#define LCD_DB6   7
#define LCD_DB7   8

#define LCD_E     4
#define LCD_RS    3

//#define LCD_RW   -->>GND


// If you want only a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.  Doing so will save one PIC
// pin, but at the cost of losing the ability to read from
// the LCD.  It also makes the write time a little longer
// because a static delay must be used, instead of polling
// the LCD's busy bit.  Normally a 6-pin interface is only
// used if you are running out of PIC pins, and you need
// to use as few as possible for the LCD.
//#define USE_RW_PIN   1     


// These are the line addresses for most 4x20 LCDs.
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54

// These are the line addresses for LCD's which use
// the Hitachi HD66712U controller chip.
/*
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x20
#define LCD_LINE_3_ADDRESS 0x40
#define LCD_LINE_4_ADDRESS 0x60
*/


//========================================

#define lcd_type 2   // 0=5x7, 1=5x10, 2=2 lines(or more)

int8 lcd_line;

int8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2),  // Set mode: 4-bit, 2+ lines, 5x8 dots
 0xc,                     // Display on
 1,                       // Clear display
 6                        // Increment cursor
 };
                             

//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note:  !! converts an integer expression
// to a boolean (1 or 0).
 f_output_bit(LCD_DB4, !!(nibble & 1));
 f_output_bit(LCD_DB5, !!(nibble & 2));
 f_output_bit(LCD_DB6, !!(nibble & 4));   
 f_output_bit(LCD_DB7, !!(nibble & 8));   

 delay_cycles(1);
 f_output_high(LCD_E);
 delay_us(2);
 f_output_low(LCD_E);
}

//-----------------------------------


// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
f_output_low(LCD_RS);


delay_us(60);

if(address)
   f_output_high(LCD_RS);
else
   f_output_low(LCD_RS);
     
 delay_cycles(1);






f_output_low(LCD_E);

lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------

void lcd_init(void)
{
int8 i;

lcd_line = 1;

f_output_low(LCD_RS);


f_output_low(LCD_E);

// Some LCDs require 15 ms minimum delay after
// power-up.  Others require 30 ms.  I'm going
// to set it to 35 ms, so it should work with
// all of them.
delay_ms(35);         

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    delay_ms(5);
   }

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING[i]);
   
   
   }

}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;


switch(y)
  {
   case 1:
     address = LCD_LINE_1_ADDRESS;
     break;

   case 2:
     address = LCD_LINE_2_ADDRESS;
     break;

   case 3:
     address = LCD_LINE_3_ADDRESS;
     break;

   case 4:
     address = LCD_LINE_4_ADDRESS;
     break;

   default:
     address = LCD_LINE_1_ADDRESS;
     break;
     
  }

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      lcd_line = 1;
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1, ++lcd_line);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}



keypad driver
Code:
///////////////////////////////////////////////////////////////////////////
////                             Flex_KBD_4X4.C                            ////
////                  Generic keypad scan driver                       ////
////                                                                   ////
////  kbd_init()   Must be called before any other function.           ////
////                                                                   ////
////  c = kbd_getc(c)  Will return a key value if pressed or /0 if not ////
////                   This function should be called frequently so as ////
////                   not to miss a key press.                        ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////



//Keypad connection:
#define row0 PIN_C4
#define row1 PIN_D3
#define row2 PIN_D2
#define row3 PIN_D4
#define col0 PIN_C7
#define col1 PIN_C6
#define col2 PIN_C5
#define col3 PIN_B3

// Keypad layout:
char const KEYS[4][4] =
{{'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'}};


#define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where
// n is the number of times you expect
// to call kbd_getc each second

void kbd_init()
{
//set_tris_b(0xF0);
//output_b(0xF0);
port_b_pullups(true);
}

short int ALL_ROWS (void)
{
if(input (row0) & input (row1) & input (row2) & input (row3))
   return (0);
else
   return (1);
}



char kbd_getc()
{
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;

byte kchar;
byte row;

kchar='\0';

if(++kbd_call_count>KBD_DEBOUNCE_FACTOR)
  {
   switch (col)
     {
      case 0:
        output_low(col0);
        output_high(col1);
        output_high(col2);
        output_high(col3);
        break;
   
      case 1:
        output_high(col0);
        output_low(col1);
        output_high(col2);
        output_high(col3);
        break;

      case 2:
        output_high(col0);
        output_high(col1);
        output_low(col2);
        output_high(col3);
        break;

      case 3:
        output_high(col0);
        output_high(col1);
        output_high(col2);
        output_low(col3);
        break;
      }

   if(kbd_down)
     {
      if(!ALL_ROWS())
        {
         kbd_down=false;
         kchar=last_key;
         last_key='\0';
        }
     }
   else
     {
      if(ALL_ROWS())
        {
         if(!input (row0))
            row=0;
         else if(!input (row1))
            row=1;
         else if(!input (row2))
            row=2;
         else if(!input (row3))
            row=3;

         last_key =KEYS[row][col];
         kbd_down = true;
        }
      else
        {
         ++col;
         if(col==4)
            col=0;
        }
     }
   kbd_call_count=0;
  }
return(kchar);
}
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 8:54 am     Reply with quote

Well I suspect it's NOT the KPD driver, rather your 'interesting' LCD interface.

You've got a real mess of code,rather hard to read, that seems to try to use the CCS LCD 4 bit driver that someone's 'hacked to death to try to run with a 595.

seriously it would be a LOT easier to start from scratch and write a proper 595 -> LCD driver.

or cheat and use google to locate a working chunk of code..


jay
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Sun Dec 21, 2014 12:53 pm     Reply with quote

Quote:
Well I suspect it's NOT the KPD driver, rather your 'interesting' LCD interface.

of course I'm interested in this LCD interfaces because this uses only 3 wire interfaces.
But I am also interested to use a keypad with this LCD.

Quote:
seriously it would be a LOT easier to start from scratch and write a proper 595 -> LCD driver.


Have you any proper 595 driver or any that is 3 wire interface..... please share
Quote:
cheat and use google to locate a working chunk of code..


I already test it in my hardware, lcd is working fine .Then I want to add a keypad to this project , it works but response too slow.
That is why I come here

Please advice .......................
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 3:38 pm     Reply with quote

Can you post code which is complete and compilable so that we can copy and paste to test?

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 8:20 pm     Reply with quote

What happens if you make a program with the keypad code only, and
have it turn on an LED when you press a key. Do you see any delay ?
I doubt that you will. But try it.

Also, run a blinking LED test to make sure your PIC is really running
at the speed you think it is. Example:
Code:

while(TRUE)
  {
   output_high(PIN_B0); // Led On
   delay_ms(500);
   output_low(PIN_B0);  // Led Off
   delay_ms(500);
  }
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 22, 2014 12:52 am     Reply with quote

Mike Walne wrote:
Can you post code which is complete and compilable so that we can copy and paste to test?


Alread I did it in my post. Both of keypad and lcd driver are in my post.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 22, 2014 5:30 am     Reply with quote

Quote:
What happens if you make a program with the keypad code only, and
have it turn on an LED when you press a key


No problem, keypad response fine. Led is light up on key press and off after programmed delay time.

I found something may conflict.

when I use this code Keypad response fine...
Code:
while(true){

   k=kbd_getc();
   if(k!=0)
     {
        output_high (pin_D7);
        lcd_gotoxy(1,1);
        printf(lcd_putc, "%c",k);
         delay_ms(500);
   output_low(PIN_D7);  // Led Off
 
     }
   



but when I use this code Keypad response too slow ( about 4-5 second later)

Code:
while(true){

   k=kbd_getc();
   if(k!=0)
     {
        output_high (pin_D7);
        lcd_gotoxy(1,1);
        printf(lcd_putc, "%c",k);
         delay_ms(500);
   output_low(PIN_D7);  // Led Off
 
     }
 
   dat++;
   lcd_gotoxy(10,3);
   printf(LCD_PUTC,"%05ld   ",dat);
 
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 4:54 pm     Reply with quote

freedom wrote:
Mike Walne wrote:
Can you post code which is complete and compilable so that we can copy and paste to test?


Alread I did it in my post. Both of keypad and lcd driver are in my post.

Your code is NEITHER complete nor compilable.

From your post, I created the files 74HC595_flex_LCD420.c and Flex_KBD_4X4.C
Your main code would not then compile.
Amongst others, I got several ***Errors 12 complaining about

Undefined identifier f_output_bit
Undefined identifier f_output_high
Undefined identifier f_output_low

At this stage I can no longer help you.
I'm not fond of guessing games.
I don't intend trying to work out what's missing.
You're the one with the problem, make it easier for us to help.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 5:15 pm     Reply with quote

Your original code at the start of this thread did not have delay_ms(500) in it.

Can you post the actual code that you are testing ? Complete and compilable.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 5:46 pm     Reply with quote

Your code is somewhat of a mess.

You've got this heading
Code:
// 20X4 LCD driver-- Shehab
// Flex_LCD420.c
in there TWICE, so I missed a whole chunk of code when copying.
I can now compile without errors.
As PCM p says, show us CLEARLY what code you're testing and tell us EXACTLY what you're seeing, then we can help you.

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 5:49 pm     Reply with quote

hmmm...

re -read this post again....

from the OP..

//4094(Shift Register) 3wire Serial To Parallel


hmmm....
no wonder it doesn't work if a 74595 is in the hardware mix.....


code snippets appear to be a 'hodgepodge' of 'this and that' NONE of which will ever work....
and as I pointed out there IS working CCS C compiler code for a 595 driven LCD out in 'cyberspace'.

sigh.....

Jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 6:01 pm     Reply with quote

Assuming you've still got some spare pins, you SHOULD be able wire in some diagnostic LEDs to tell you precisely where the major delays are.
It's not rocket science.

Mike
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 23, 2014 12:03 am     Reply with quote

here is my full project with driver, schemetic , programme file
Remmeber to comment "#include <2432.c>" this line( I forget to do this)

http://www.4shared.com/zip/Z53PLnYkba/project_4x20_LCD_with_3_wire_8.html
or
http://www.datafilehost.com/d/6d7ed5f2

Code:
//!   dat++;
//!   lcd_gotoxy(10,3);
//!   printf(LCD_PUTC,"%05ld   ",dat);

if i enable the above code, keypad response too slow
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 23, 2014 2:37 am     Reply with quote

temtronic wrote:
hmmm...

re -read this post again....

from the OP..

//4094(Shift Register) 3wire Serial To Parallel


hmmm....
no wonder it doesn't work if a 74595 is in the hardware mix.....


code snippets appear to be a 'hodgepodge' of 'this and that' NONE of which will ever work....
and as I pointed out there IS working CCS C compiler code for a 595 driven LCD out in 'cyberspace'.

sigh.....

Jay


I tested both of 74595 and 4094 . Both are working fine with the driver "74HC595_flex_LCD420.c".
Just circuit and connection are slightly changed, here is my full project with driver, schemetic , programme file

http://www.4shared.com/zip/iaoB9y-ace/4094_and_74595_LCD_with_3_wire.html

Actually I got this idea and other info from here
http://320volt.com/ccs-c-74hc595-cd4094-128x64-4x20-lcd-kullanimi/
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Dec 23, 2014 3:31 am     Reply with quote

No. You're making this very hard.
I tried to download from one of your links and got this message
Quote:
Malicious Web Site Blocked

You attempted to access:
http://livedirsetsoftware.org/dfnc?q=project%204x20%20LCD%20with%203%20wire%20877A.zip

This is a known malicious web site. It is recommended that you do NOT visit this site. The detailed report explains the security risks on this site.

For your protection, this web site has been blocked. Visit Symantec to learn more about phishing and internet security.
I'm intrigued as to what your problem is and would like to help, but am not going to risk dealing with dangerous sites.

Like I said in my previous post you SHOULD be able to put LED indicators either side of each section of code to determine where the problem is.
With the delay you're complaining about, it ought to stick out like a sore thumb.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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