AD76XYZ
Junior Member level 1
Hi,
I am newbie just completed the embedded course in which I learned 8051 and PIC. And for coding C language and learned Keil and CCS C.
My English is very average and hence please don't get irritate with my English. Some times I am not able to express what is in my mind.
Now I am doing project on code lock. Following is the details.
PIC16F886
4X3 Matrix Keypad
Three LEDs to show status like OPEN, CLOSED and LOCKED etc.
Buzzer
Solenoid
In this project I am not using LCD module. Very simple project. My hardware is ready on breadboard and now I want to just code in C for the same.
I will do coding in part, after successfully completing one part will move to another.
I am using PIC16F886 and will code in CCS C compiler. I am using CCS C Version 4.105. For testing purpose I have edited sample file and it ran successfully. And for sake of testing I used LCD 16X2 otherwise I am not using LCD in project.
I used driver for LCD and matrix keypad which come with CCS C. This LCD16X2.C which I used in code is nothing but LCD.C driver which comes with CCS C, I rename it to LCD16X2.C for sake of understanding for me. And KBD4X3.C driver I got from CCS C forum.
Following is the program which ran successfully.
The above code ran and shows on LCD what ever I press on keypad. Now second part. I want to store what ever coming from keypad to digit[] array so I will compare it with fixed password array. For this I I coded on function and tested but not working.
This function.
Please tell me where the mistake.
Another thing I do not understand is if(k!=0) in first program. Why is this and what is the function of this.
I am newbie just completed the embedded course in which I learned 8051 and PIC. And for coding C language and learned Keil and CCS C.
My English is very average and hence please don't get irritate with my English. Some times I am not able to express what is in my mind.
Now I am doing project on code lock. Following is the details.
PIC16F886
4X3 Matrix Keypad
Three LEDs to show status like OPEN, CLOSED and LOCKED etc.
Buzzer
Solenoid
In this project I am not using LCD module. Very simple project. My hardware is ready on breadboard and now I want to just code in C for the same.
I will do coding in part, after successfully completing one part will move to another.
I am using PIC16F886 and will code in CCS C compiler. I am using CCS C Version 4.105. For testing purpose I have edited sample file and it ran successfully. And for sake of testing I used LCD 16X2 otherwise I am not using LCD in project.
I used driver for LCD and matrix keypad which come with CCS C. This LCD16X2.C which I used in code is nothing but LCD.C driver which comes with CCS C, I rename it to LCD16X2.C for sake of understanding for me. And KBD4X3.C driver I got from CCS C forum.
Following is the program which ran successfully.
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
unsigned char pw_digit[4]={1,2,3,4}; // Fixed password
char digit[4]={0,0,0,0}; //Password entered by keypad will save in this array
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);
lcd_init();
kbd_init();
lcd_putc("\fTest1\n");
lcd_putc("Test2");
delay_ms(2000);
lcd_putc("\fTest3\n");
lcd_putc("Test4");
delay_ms(2000);
lcd_putc("\fEnter Password..\n");
while(1)
{
k=kbd_getc();
if(k!=0)
if(k=='*')
lcd_putc('\f');
else
lcd_putc(k);
}
The above code ran and shows on LCD what ever I press on keypad. Now second part. I want to store what ever coming from keypad to digit[] array so I will compare it with fixed password array. For this I I coded on function and tested but not working.
This function.
Code:
void keyarray()
{
char k=0;
for(i=0;i<4;i++)
{
k=kbd_getc();
if(k!=0)
{
digit[i]=k;
}
}
}
Please tell me where the mistake.
Another thing I do not understand is if(k!=0) in first program. Why is this and what is the function of this.