|
|
View previous topic :: View next topic |
Author |
Message |
picker
Joined: 07 Sep 2003 Posts: 19 Location: South Africa
|
Keyb.C and 18F452!!! |
Posted: Fri Dec 05, 2003 6:43 am |
|
|
Has any one had any problems using the keyb.c and a 18F452. I get it to work, but it reacts very strangly. I press a button and nothing happens, I then press several and then suddenly a character is displayed. Then it works well for two or three characters (Shows the chars correctly on the LCD) and then nothing happens again when I press a key. I then press several keys and again it would display all the keys and the hook again.
I have had the same reaction on a 18F7820 and I though it was a silicon bug, but obviously its something in the software. I have checked the connections to the Pic and all seems fine. Also the mapping to the PIC is the same as in Keyb.c (I changed Keyb.c to suit the keyboard I am using.)
I have commented all the code of the Keyb.c which selects the port and the key mapping and replaced it with the following...
#byte kbd = 0xF83
#define set_tris_kbd(x) set_tris_d(x)
#define COL0 (1 << 2)
#define COL1 (1 << 1)
#define COL2 (1 << 0)
#define ROW0 (1 << 6)
#define ROW1 (1 << 5)
#define ROW2 (1 << 4)
#define ROW3 (1 << 3)
Here follows my code in the main program...
In header file ....
#include <18F452.h>
#device adc=8
#use delay(clock=4000000)
#use rs232(baud=9600,parity=n,xmit=PIN_C6,rcv=PIN_C7)
#fuses HS,NOWDT,WDT1,NOLVP
In C file ........
#device PIC18F452
#include "C:\Program Files\Picc\R50_keyboard\r50_key.h"
#include "c:\Program Files\Picc\R50_keyboard\LCD.C"
#include "c:\Program Files\Picc\R50_keyboard\kbd.C"
char k;
void main() {
output_high(PIN_E1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
lcd_init();
kbd_init();
lcd_putc("\fReady...\n");
while (TRUE)
{
delay_ms(10);
k=kbd_getc();
if(k!=0)
{
printf(lcd_putc,"\f");
printf(lcd_putc,"Char :%C",k);
}
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 05, 2003 11:04 am |
|
|
The file KBD.C has the following comment:
Quote: | // Make sure the port used has pull-up resistors (or the LCD) on
// the column pins |
I see that you're using Port D for the keypad. Port D doesn't have
built-in optional pull-ups (as Port B does). I suggest that you add
a 10K pullup resistor on COL0, COL1, and COL2. |
|
|
picker
Joined: 07 Sep 2003 Posts: 19 Location: South Africa
|
Pull-up resistors... |
Posted: Sun Dec 07, 2003 11:57 pm |
|
|
I thought I'd add this to the topic....
I did have resistors on the cols, but they were 5k resistors and as a last resort I tried 10k resistors and IT WORKED!!!!!!!!!!!!!!!!! Thanks to PCM Programmer!!!!
I realise if I read the datasheets of the PIC I would have noticed that the 5k resistors would be too low for the PIC to pull the output down to 0.
picker
|
|
|
|
|
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
|