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

Lock Door System

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

Joined: 22 Feb 2018
Posts: 10

View user's profile Send private message

Lock Door System
PostPosted: Fri Mar 02, 2018 4:45 pm     Reply with quote

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 ?

#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_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()
 tus = "";
 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; }
 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; }
 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; }
 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; }

 return tus;

void main ( )
 printf(lcd_putc,"\fLock Door");
  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;
gelen = keypad_oku();
if (basildi==1) {

   if (sifre[sec] != gelen)
   if (sifre[sec] == gelen)
      if (sec>3) {
      if (yanlis==0) {
      printf(lcd_putc,"\fRight Key");
      printf(lcd_putc,"\fEnter key");
      else {
      printf(lcd_putc,"\fWrong Key");
      printf(lcd_putc,"\fEnter key");



Joined: 01 Jul 2010
Posts: 6550
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 02, 2018 7:23 pm     Reply with quote

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.

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