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 support@ccsinfo.com

problem with keypad 4*4

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



Joined: 30 May 2010
Posts: 5

View user's profile Send private message

problem with keypad 4*4
PostPosted: Tue Jun 15, 2010 10:45 am     Reply with quote

I have to connect a keypad and LCD with pic 16F877. The simulation of my program is done in ISIS and it works correctly.
But when I do it in reality the LCD works but the keypad no. The pic doesn't wait until I enter a number with keypad. It run as if the keys are always pressed. But if I press reset and from the beginning I press a key in the keypad, the program run normally and then the pic waits until I have to press a key. It makes me crazy because it's running in the invert way. This is my code:
Code:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <lcd1.c>
#include<clavier16T.c>

#define Bouton1 PIN_E0       //declaration de bouton 1
#define Bouton2 PIN_E1
#include <math.h>
#include <stdio.h>

char code[5];  //le code deja enregistrer dans eeprom de pic debut de l adresse 0
char code1[5];//le code taper et enregistrer dans eeprom de pic debut de l adresse0x70
char value ;
char str[20];
int32 position1;
byte position01,position02,position03,position04,position05,position06,position07,position08,sens,sens1;
int32 x;
char position[20];

void main()
{
float k;

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
  port_b_pullups(true);
   write_eeprom(1,0x30); write_eeprom(2,0x30); write_eeprom(3,0x30); write_eeprom(4,0x30); write_eeprom(5,0x30);
    code[0]=read_eeprom(1);
    code[1]=read_eeprom(2);
    code[2]=read_eeprom(3);
    code[3]=read_eeprom(4);
    code[4]=read_eeprom(5);
   lcd_init();
   kbd_init();
   lcd_gotoxy(1,1);
   lcd_putc("\fbienvenue a valeo...\n");
   delay_ms(1000);
start:;
   lcd_putc("\fentrez code");
   delay_ms(1000);
   lcd_putc("\f");
   kbd_init();
   
  do{
   value=kbd_getc();
   }while(value==0);
   lcd_gotoxy(1,1);
    lcd_putc(0X2A);

   write_eeprom(0X70,value);

   //2d chif of cod
   do
   {
   value=kbd_getc();
   }while(value==0);
    lcd_gotoxy(2,1);
  lcd_putc(0X2A);
   write_eeprom(0X71,value);
   //third chif of cod
     do
   {
   value=kbd_getc();
   }while(value==0);
    lcd_gotoxy(3,1);
   lcd_putc(0X2A);
   write_eeprom(0X72,value);
   //fourth chif of code
        do
   {
   value=kbd_getc();
   }while(value==0);
    lcd_gotoxy(4,1);
  lcd_putc(0X2A);
   write_eeprom(0X73,value);

   //5 chif of code
        do
   {
   value=kbd_getc();
   }while(value==0);
    lcd_gotoxy(5,1);
  lcd_putc(0X2A);
   write_eeprom(0X74,value);
   //copie de code1 dans le RAM
    code1[0]=read_eeprom(0X70);
    code1[1]=read_eeprom(0X71);
    code1[2]=read_eeprom(0X72);
    code1[3]=read_eeprom(0X73);
    code1[4]=read_eeprom(0X74);
   // attend de touche de confirmation qui est le *
    lcd_putc('\f');
   lcd_putc("confirmez par '*'");
   test:;

   value=kbd_getc();

   if (value!=0X2A){goto test;}
   // verification de code
   if (code1[0]!=code[0]){lcd_putc('\f'); lcd_putc("code faux");delay_ms(2000);goto start;}
   if (code1[1]!=code[1]){lcd_putc('\f'); lcd_putc("code faux");delay_ms(2000);goto start;}
   if (code1[2]!=code[2]){lcd_putc('\f'); lcd_putc("code faux");delay_ms(2000);goto start;}
   if (code1[3]!=code[3]){lcd_putc('\f'); lcd_putc("code faux");delay_ms(2000);goto start;}
   if (code1[4]!=code[4]){lcd_putc('\f'); lcd_putc("code faux\f");delay_ms(2000);goto start;}

   if (code1[0]=code[0]){lcd_putc('\f'); lcd_putc("code juste");delay_ms(300);  lcd_putc('\f');}
   if (code1[1]=code[1]){lcd_putc('\f'); lcd_putc("code juste");delay_ms(300);  lcd_putc('\f');}
   if (code1[2]=code[2]){lcd_putc('\f'); lcd_putc("code juste");delay_ms(300);  lcd_putc('\f');}
   if (code1[3]=code[3]){lcd_putc('\f'); lcd_putc("code juste");delay_ms(300);  lcd_putc('\f');}
   if (code1[4]=code[4]){lcd_putc('\f'); lcd_putc("code juste");delay_ms(300);  lcd_putc('\f');}
  delay_ms(1000);
   lcd_putc("entrer position");
// lcd_gotoxy(1,2);
 //x=input(PIN_C0);
  //rintf(str, "%09lu",x);
 //rintf(lcd_putc,"%d",x);
// (input(bouton1) ==0 || input(bouton2)==0)
//
position:;
position01=input(PIN_C0);
position02=input(PIN_C3);
position03=input(PIN_C4);
position04=input(PIN_C5);
position05=input(PIN_C6);
position06=input(PIN_C7);
position07=input(PIN_A0);
position08=input(PIN_A1);
position1=(position01*1+position02*2+position03*4+position04*8+position05*16+position06*32+position07*64+position08*128);
//position1= position1*32;
lcd_gotoxy(1,2);

do
{
if (input(Bouton1) ==0) {printf(lcd_putc,"+%u",position1);output_high(PIN_C1);goto position;}
if (input(Bouton2) ==0) {printf(lcd_putc,"-%u",position1);output_high(PIN_C2);goto position;}
}while(input(Bouton1==0)&& input(Bouton2==0));

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 15, 2010 11:19 am     Reply with quote

Remove about 90% of your code, and just work on the keypad problem.
Get the keypad working reliably, then put back in the rest of your code.
wael_007



Joined: 30 May 2010
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 15, 2010 11:28 am     Reply with quote

i did it with a just the lcd and keypad parts of my code
but it doesn t work
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 15, 2010 11:39 am     Reply with quote

Try using the keypad and lcd drivers in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=40369
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