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

HELP with KBD

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



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

HELP with KBD
PostPosted: Tue Oct 02, 2007 1:15 pm     Reply with quote

Hey all.. I've been having some problems when using kbd.c and PIC16F876A with a LCD display on portB and the kbd on portC.

I have altered the LCD.C so that it'd be like this

#if defined(__PCH__)
#if defined use_portb_kbd
#byte kbd = 0xF81
#else
//#byte kbd = 0xF83
#byte lcd =0xF87
#endif
#else
#if defined use_portb_kbd
#byte kbd = 6 // on to port B (at address 6)
#else
//#byte kbd = 8 // on to port D (at address 8)
#byte kbd = 7 // on to port C (at address 7)
#endif
#endif

#if defined use_portb_kbd
#define set_tris_kbd(x) set_tris_b(x)
#else
//#define set_tris_kbd(x) set_tris_d(x)
#define set_tris_kbd(x) set_tris_c(x)
#endif


But it gets totally crazy when I put it to work.
I have got the example code in order to test, so it's just this:

Code:

#include <16F876.h>

#fuses RC, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP

#use delay(clock=4000000)   //Seta o Clock do PIC

#include "LCD.C"
#include "KBD.C"

#byte port_b=6
#byte port_c=7


void main() {
   char k;

   lcd_init();
   kbd_init();

   lcd_putc("\fReady...\n");

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


When I program the PIC and turn it on, it just keeps on printing tons of numbers and #'s randomly and sometimes even seems to reset itself, even with all configuration bits checked.
My keypad, as I could understand, follows the "black keypad" pattern so I even commented the other pattern on the code.

Does anybody knows how to solve this problem?[/code]


Last edited by rina_1220 on Tue Oct 02, 2007 2:07 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 02, 2007 1:35 pm     Reply with quote

You need to add external pull-up resistors on the Row pins of the keypad.
You can use 10K ohm resistors.
rina_1220



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

PostPosted: Tue Oct 02, 2007 1:44 pm     Reply with quote

I've tried that. It won't work Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 02, 2007 1:55 pm     Reply with quote

My advice is to use the Flex drivers from the CCS code library.
With these drivers, you can configure the driver just by changing
the #define statements for the pins at the start of the driver source file.

Flex LCD driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661

Flex Keypad driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=26333
You will still need to add a pull-up resistor (10K) to the keypad
on each of the Row pins.

If you still can't make it work after doing that, then post the
information on your keypad: Manufacturer, part number, and a link
to the data sheet.
rina_1220



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

PostPosted: Wed Oct 03, 2007 5:57 am     Reply with quote

I still get the same crazy thing happening.
The worst part of it is that I don't even know who the manufacturer of the keypad is. All I know is that i have something like this

pins: 7 6 5 4 3 2 1
and that they are related to rows and columns like this

pin #
1 -> row 3
2 -> row 2
3 -> row 1
4 -> row 0
5 -> col 0
6 -> col 1
7 -> col 2
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 03, 2007 10:39 am     Reply with quote

Quote:
I've been having some problems when using kbd.c and
PIC16F876A with a LCD display on portB and the kbd on portC.

#include <16F876.h>

I just noticed something. In your post, you say you're using 16F876A,
but in your code, the include file is 16F876.H. What's the reason for this ?
The .H file must be the correct one for the PIC. Also, the programmer
must be setup for the correct PIC. This is important.


Code:
#fuses RC, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP

#use delay(clock=4000000) 

In the code above, you're using RC oscillator mode. Do you have an
external resistor and capacitor connected to the OSC1 pin on the PIC ?
What are the values of those components ?
rina_1220



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 5:44 am     Reply with quote

Hey sorry...
That was an old version of the code. I've already changed the .H and checked the programmer. And so far I'm not using an RC oscillator anymore. I have now a 4MHz crystal on pins OSC1 and OSC2.
Still, the program is not working as i expected.
I am gonna check all the connections. I guess the keypad is not well connected and that could cause my problem.

Thank you for all your help

anyway, the code now just looks like this
Code:

#include <16F876A.h>

#fuses XT, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP

#use delay(clock=4000000)   

#include "LCD.C"
#include "KBD.C"

#byte port_b=6
#byte port_c=7

void main()
{
   char k;

   lcd_init();
   kbd_init();

   lcd_putc("\fReady...\n");

   while (1)
   {
      k=kbd_getc();
      if(k!=0)
         if(k=='*')
            lcd_putc('\f');
         else
            lcd_putc(k);
   }
}
rina_1220



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

PostPosted: Fri Oct 05, 2007 5:58 am     Reply with quote

well... I've checked all the connections and it was all right. Nothing helped anyway.
I have MPLAB 7.6 and PCWH compiler version 4.013
I do not know what else to do.
rina_1220



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

PostPosted: Tue Oct 09, 2007 7:55 am     Reply with quote

anyone?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 09, 2007 10:32 am     Reply with quote

Quote:
#include "LCD.C"
#include "KBD.C"

What drivers are these ? Are they the CCS drivers or the Flex drivers ?

What are the pin assignments (that you are currently using) for the
keypad and the LCD ?
rina_1220



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

PostPosted: Tue Oct 09, 2007 10:42 am     Reply with quote

These are the flex drivers.
But I get the same errors with the CCS ones.
my pin assignments are:

Code:
//Keypad connection:
#define col0 PIN_C0
#define col1 PIN_C1
#define col2 PIN_C2
#define row0 PIN_C4
#define row1 PIN_C5
#define row2 PIN_C6
#define row3 PIN_C7


and

Code:
//LCD connection
#define LCD_DB4   PIN_B4
#define LCD_DB5   PIN_B5
#define LCD_DB6   PIN_B6
#define LCD_DB7   PIN_B7
#define LCD_E     PIN_B0
#define LCD_RS    PIN_B1
#define LCD_RW    PIN_B2
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 09, 2007 11:17 am     Reply with quote

I tested this on a PicDem2-Plus board. I don't have a 16F876A, so I
used a 16F877A. I don't have vs. 4.013, so I used 4.014 which is the
nearest version that I do have. Also, I didn't use your pins, because
it would take me too long to solder in some pull-up resistors on the row
pins of the keypad on Port C. I used Port B instead, because then I
can turn on the built-in pullups in the PIC, with this line of code:
Code:
port_b_pullups(TRUE);


It worked. It displays "Ready..." and then it displays characters on
the LCD as I press the keys on the keypad.


Because I'm using pins B6 and B7 for the keypad, I made sure that
the ICD2 connector was unplugged from the board before I tried to
run the program. The ICD2 uses pins B6 and B7, which are used for
row2 and row3, below. That's why it needs to be unplugged.
Code:

// Keypad connections:
#define col0 PIN_B0
#define col1 PIN_B1
#define col2 PIN_B2
#define row0 PIN_B4
#define row1 PIN_B5
#define row2 PIN_B6
#define row3 PIN_B7


LCD connections. These are for the "original" PicDem2-Plus board.
(Not the new "Rohs" version).
Code:

#define LCD_DB4   PIN_D0
#define LCD_DB5   PIN_D1
#define LCD_DB6   PIN_D2
#define LCD_DB7   PIN_D3

#define LCD_E     PIN_A1
#define LCD_RS    PIN_A3
#define LCD_RW    PIN_A2

#define USE_LCD_RW   1     


Code:

#include <16F877A.h>
#fuses XT, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP
#use delay(clock=4000000)   

#include "Flex_LCD_pdp.C"
#include "Flex_KBD_pdp.C"

// These two lines below are not needed.   
#byte port_b=6
#byte port_c=7

void main()
{
   char k;

   lcd_init();
   kbd_init();

   port_b_pullups(TRUE);   // Needed for the keypad row pins


   lcd_putc("\fReady...\n");

   while (1)
   {
      k=kbd_getc();

      if(k != 0)
         if(k =='*')
            lcd_putc('\f');
         else
            lcd_putc(k);
         
   }
}
rina_1220



Joined: 02 Oct 2007
Posts: 20

View user's profile Send private message

PostPosted: Tue Oct 09, 2007 11:32 am     Reply with quote

Hey, Thank you!
I've made the changes according to what you said and its working now.
I still didn't understand why it didn't work in port c with external resistors, but now its working ok.

thank you very much! 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