|
|
View previous topic :: View next topic |
Author |
Message |
AD76XYZ
Joined: 18 Jun 2012 Posts: 19
|
Only zeros on LCD! |
Posted: Tue Jul 03, 2012 12:53 am |
|
|
CCS C Ver. 4.105
PIC16F886
4X3 Matrix Keypad
LCD 16X2
I have written a code for code lock project. In this I am taking key value using k=kbd_getc() and giving the key value to function input_digit(). In this function LCD will show the number pressed on keypad and also save the value in array digit[].
When I use following code and switched on LCD is working fine but after showing strings it shows sequence of zero only and fills the line. So what is the wrong with my code.
Code: |
#include <main.h>
#include <lcd16x2.c>
#include <KBD4X3.c>
#use delay(clock=4000000)
//#define OPEN_LED RC3
//#define CLOSE_LED RC4
//#define LOCK_LED RC5
//#define BUZZER RC6
//#define SOLENOID RC7
// Function declaration
void input_digit(char k);
unsigned char check = 0;
unsigned char pw_digit[4]={1,2,3,4}; // Fixed password
unsigned char digit[4]={0,0,0,0};
int i;
char a;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_4MHZ);
char k;
lcd_init();
kbd_init();
lcd_putc("\fText1\n");
lcd_putc("Text2");
delay_ms(3000);
lcd_putc("\fText3\n");
lcd_putc("Text4");
delay_ms(3000);
lcd_putc("\fEnter Password..\n");
while(1)
{
k=kbd_getc();
if(k!=0)
lcd_putc('\n');
else
input_digit(k);
}
}
//Function defination
void input_digit(char a)
{
switch(a)
{
case 1:{
lcd_putc("1");
delay_ms(100);
digit[i]=1;
break;
}
case 2:{
lcd_putc("2");
delay_ms(100);
digit[i]=2;
break;
}
case 3:{
lcd_putc("3");
delay_ms(100);
digit[i]=3;
break;
}
case 4:{
lcd_putc("4");
delay_ms(100);
digit[i]=4;
break;
}
case 5:{
lcd_putc("5");
delay_ms(100);
digit[i]=5;
break;
}
case 6:{
lcd_putc("6");
delay_ms(100);
digit[i]=6;
break;
}
case 7:{
lcd_putc("7");
delay_ms(100);
digit[i]=7;
break;
}
case 8:{
lcd_putc("8");
delay_ms(100);
digit[i]=8;
break;
}
case 9:{
lcd_putc("9");
delay_ms(100);
digit[i]=9;
break;
}
case 0:{
lcd_putc("0");
delay_ms(100);
digit[i]=0;
break;
}
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Tue Jul 03, 2012 1:14 am |
|
|
Where does KBD4X3.c come from?. Is it the CCS KBD.C, or the flex driver, or something else?.
We have no hope of helping without knowing what this does.
The obvious thing is that most drivers like this, return _text_ characters, so return '0', rather than the number 0.
Best Wishes |
|
|
AD76XYZ
Joined: 18 Jun 2012 Posts: 19
|
Same |
Posted: Tue Jul 03, 2012 1:24 am |
|
|
The file LCD16X2.C is same LCD.C, I changed the name according my project work. And this KBD4X3.C is the one which I got from this forum. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Jul 03, 2012 3:03 am |
|
|
You're trying to confuse us all, AGAIN.
You've lifted both the LCD and the KBD drivers from the CCS list.
Why not simply use the CCS example EX_LCDKB.C? It echoes characters from the keypad to the LCD.
The fragment of code you're having trouble with is very similar.
Work on the KISS principal.
Your definition "input_digit(char a)" uses the same code fragment TEN times over. It's a prime candidate for simplification. As it stands, it's error prone and difficult to maintain.
Mike
Last edited by Mike Walne on Tue Jul 03, 2012 7:19 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Tue Jul 03, 2012 3:51 am |
|
|
The only references to KBD4X3.c 'on this forum', are from _you_. There is no code with this name posted here. It sounds as if you have renamed one of the standard drivers (possibly), but what one.
Possibly the flex driver?.
It is also not plain from this, whether the keyboard is wired correctly at all. Are you using PORTB. If so, do you have the pull-ups enabled?. If not, do you have pull up resistors on the input pins?.
Earlier comment applies to all the drivers that have ever appeared here, in that they return text characters '0' for example, not the number 0....
Best Wishes |
|
|
AD76XYZ
Joined: 18 Jun 2012 Posts: 19
|
Thanks Ttelmah |
Posted: Tue Jul 03, 2012 4:19 am |
|
|
Thanks Ttelmah for reply and helping for zero. I did not understand what you mean by not a number 0 but a text character zero '0', what is the difference.
Can you please tell me so how it should be handled in my code.
Please help.
I am learning embedded and this is my first full project so please help me. I may dont know basic thing this may irritate you but atleast give some hints or link etc.
And also my english is not very good. Some times I am not able to say what ever in my mind.
I have just rename the original LCD.C file to LCD16X2.C for my convenience |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Jul 03, 2012 5:09 am |
|
|
helpful hint of the day
numbers vs. characters
data to the computer can be represented many different ways, the most common are DECIMAL and HEX.Data in decimal are base10 ( 0,1,2...9) while hex data are 0,1,2,...9,a,b,c,d,e,f).
the Number '0' ( zero) is represented by the decimal value '0', or hex value '0x00'.
the Character '0' (zero) is represented by the decimal value '48', or hex value '30'.
Put in simple terms, computers do math operations( +,-,adc data,etc)with 'numbers' while they will display 'characters' to an LCD,terminal,etc.
One example.
If you send the CHARACTER 7 to a terminal you will see the 7 appear on the screen however if you send the NUMBER 7 to a terminal, then the bell will ding.
I suggest you download an ASCII table( www.LookupTables.com).It's a very handy reference,fits on one page,easy to see what decimal values are in hex or characters.
This is all basic stuff,should have been taught in 'computers101',entire books are written but hopefully this is enough for you.
hth
jay |
|
|
AD76XYZ
Joined: 18 Jun 2012 Posts: 19
|
Thanks temtronic |
Posted: Tue Jul 03, 2012 5:17 am |
|
|
Thanks temtronic for nice explanation of the two types of number representation. And that link also very helpful and good. |
|
|
|
|
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
|