|
|
View previous topic :: View next topic |
Author |
Message |
carllw
Joined: 22 Feb 2018 Posts: 10
|
Lock Door System |
Posted: Fri Mar 02, 2018 4:45 pm |
|
|
Hi, I want to do lock door system. I used 16f877a and 4*3 keypad. It work on proteus well but I created circuit on board and i wrote ccs c code for project.
When i enter the key it says key is wrong even if i enter right key. I tried 10 times but it says right key 2 or 3 times. For example i push a number but it doesn't take it sometimes, sometimes take after pushed number etc. I think delays were problem but i didn't find problem. Should I push number fastly or slowly? I don't understand problem. Can anyone help me ?
Thanks.
Code: | #include <16F877A.h>
#FUSES NOWDT
#FUSES NOBROWNOUT
#FUSES NOLVP
#use delay(crystal=4000000)
#define LCD_RS_PIN PIN_B7
#define LCD_RW_PIN PIN_B6
#define LCD_ENABLE_PIN PIN_B5
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B3
#define LCD_DATA6 PIN_B2
#define LCD_DATA7 PIN_B1
#include "lcd.c"
#define sut1 pin_d0
#define sut2 pin_d1
#define sut3 pin_d2
#define sut4 pin_d3
#define sat1 pin_d4
#define sat2 pin_d5
#define sat3 pin_d6
#define sat4 pin_d7
#define ROLE pin_c0
char tus=0;
int basildi;
int sifre[4];
char keypad_oku()
{
output_d(0x00);
tus = "";
output_high(sat1);
if (input(sut1))
{ delay_ms(500); tus=1;basildi=1; }
if (input(sut2))
{ delay_ms(500); tus=2;basildi=1; }
if (input(sut3))
{ delay_ms(500); tus=3;basildi=1; }
if (input(sut4))
{ delay_ms(500); tus=0xA;basildi=1; }
output_low(sat1);
output_high(sat2);
if (input(sut1))
{ delay_ms(500); tus=4;basildi=1;}
if (input(sut2))
{ delay_ms(500); tus=5;basildi=1; }
if (input(sut3))
{ delay_ms(500); tus=6;basildi=1; }
if (input(sut4))
{ delay_ms(500); tus=0xB;basildi=1; }
output_low(sat2);
output_high(sat3);
if (input(sut1))
{ delay_ms(500); tus=7;basildi=1; }
if (input(sut2))
{ delay_ms(500); tus=8;basildi=1; }
if (input(sut3))
{ delay_ms(500); tus=9;basildi=1; }
if (input(sut4))
{delay_ms(500); tus=0x0C;basildi=1; }
output_low(sat3);
output_high(sat4);
if (input(sut1))
{ delay_ms(500); tus=0xE;basildi=1; }
if (input(sut2))
{ delay_ms(500); tus=0;basildi=1; }
if (input(sut3))
{ delay_ms(500); tus=0xF;basildi=1; }
if (input(sut4))
{delay_ms(500); tus=0xD;basildi=1; }
output_low(sat4);
return tus;
}
void main ( )
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
set_tris_d(0x0F);
lcd_init();
printf(lcd_putc,"\fLock Door");
printf(lcd_putc,"\nV1.0");
delay_ms(1500);
printf(lcd_putc,"\fEnter Key");
// Our system's Key
sifre[0] = 1;
sifre[1] = 9;
sifre[2] = 8;
sifre[3] = 7;
int sec=0;
int yanlis = 0;
int gelen;
while(1)
{
gelen = keypad_oku();
if (basildi==1) {
basildi=0;
lcd_gotoxy(7+sec,2);
printf(lcd_putc,"*");
if (sifre[sec] != gelen)
{
yanlis=1;
sec++;
}
if (sifre[sec] == gelen)
{
sec++;
}
if (sec>3) {
if (yanlis==0) {
printf(lcd_putc,"\fRight Key");
Output_high(ROLE);
delay_ms(2000);
Output_low(ROLE);
printf(lcd_putc,"\fEnter key");
}
else {
printf(lcd_putc,"\fWrong Key");
lcd_gotoxy(15,2);
delay_ms(1500);
yanlis=0;
printf(lcd_putc,"\fEnter key");
}
sec=0;
}
}
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Mar 02, 2018 7:23 pm |
|
|
You need to look at the CCS example keypad program as well as the 'flex_kbd' program, maybe google 'scanning keypad algorithm'.
You need to understand that the keypad is a collection of mechnical switches and each switch requires 'debounce'. If you have access to an oscilloscope, connect it to a switch and observe the waveform when you press and release the button. You will NOT see nice square edged 0-1-0 transitions. That's why you need to add 'debounce'. A term used to describe the action to 'clean up' or change that noisey 0-1-0 transition into a clean, fast 'square wave'.
Debounce can be done with hardware (typically selected values of Rs and Cs, chips), software (calculated time delays, timed loops) or a combination of both.
I do suggest, if you intend to pursue electronics as a hobby, especially PICs or 'microcomputers', that you purchase an oscilloscope. Even a 20MHz, 2 channel, CRT type will be of great benefit to you.
Jay |
|
|
|
|
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
|