Pic18f452 Keypad Problem......

General discussion on mikroC.
Post Reply
Author
Message
Trainspotting
Posts: 8
Joined: 19 Mar 2010 11:55

Pic18f452 Keypad Problem......

#1 Post by Trainspotting » 01 May 2010 18:24

Hi I'm a student who need design a keypad program for my final year Project.
I used the sample code to test the whether the keypad is working or not.

Code: Select all

unsigned short kp, cnt;
char txt[5];

void main() {
  cnt = 0;
  Keypad_Init(&PORTB);
  Lcd_Init(&PORTC);         // Initialize LCD on PORTC
  Lcd_Custom_Config(&PORTC,7,6,5,4,&PORTC,2,0,3);  // Initialize LCD on PORTB
  Lcd_Cmd(LCD_CLEAR);       // Clear display
  Lcd_Cmd(LCD_CURSOR_OFF);  // Cursor off
  ADCON1 = 0x0F;
  Lcd_Out(1, 1, "Key  :");
  Lcd_Out(2, 1, "Times:");

  do {
    kp = 0;

    //--- Wait for key to be pressed
    do
      //--- un-comment one of the keypad reading functions
      kp = Keypad_Released();
      //kp = Keypad_Read();
    while (!kp);

    cnt++;

    //--- prepare value for output
    if (kp > 10)
      kp += 54;
    else
      kp += 47;

    //--- print it on LCD
    Lcd_Chr(1, 10, kp);
    WordToStr(cnt, txt);
    Lcd_Out(2, 10, txt);

  } while (1);
}//~!
Image
It works in the simulation shows above but doesn't work in the real circuit.The Key and Times are complete random, when i keypressed the counting times can went up to several hundred and key was random... What should i do with it.

basicbasic111
Posts: 127
Joined: 26 Jan 2010 17:01

Re: Pic18f452 Keypad Problem......

#2 Post by basicbasic111 » 06 May 2010 19:01

hi

did you try to pull down 1 2 3 4 of ur keypad
in your real circuit?

Post Reply

Return to “mikroC General”