Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Mikroc pro keypad library proteus error

Status
Not open for further replies.

khatus

Newbie
Joined
Oct 7, 2017
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
40
khatus post_id=311224 time=1626793245 user_id=48839 said:
Hello guys I am trying to read value through key pad4*4.
This code works. But I am receiving the following error while simulating in proteus.
Code:
/*******************************************************************************
Program for, LCD Keypad Interfacing
MCU: PIC18F4550; X-Tal: 8MHz(internal); Compiler: mikroC pro for PIC v7.6.0
Date: 19-08-2021;
*******************************************************************************/

sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

// global variables
char keypadPort at PORTD; // required by 4x4 keypad library
char text[17];
char ascii_to_int( char);


void main() {

  char pulsador = 0;
  char valor;
  ADCON1=0b1111;
  TRISB = 0x00;
  TRISC = 0x00;

  Keypad_Init();

  LCD_Init(); // Inicializamos la pantalla LCD
  LCD_Cmd(_LCD_CLEAR); // Limpia la pantalla LCD
  LCD_Cmd(_LCD_CURSOR_OFF); // Apaga el cursor en la pantalla
  Delay_ms(500); // Retardo de 500 milisegundos

  do {
    pulsador = Keypad_Key_Press();
    valor = ascii_to_int(pulsador);
    //ByteToStr(pulsador, text);
    //Lcd_Out(1, 1, "ASCII:");
    //Lcd_Out_Cp(text);
    Lcd_Out(1, 1, "Key: ");
    Lcd_Chr(1, 6, valor);
  } while (1);
}

char ascii_to_int(char pulsador) {
  switch (pulsador) {
    case 1: pulsador = 55; return pulsador; break;  // 7
    case 2: pulsador = 56; return pulsador; break;  // 8
    case 3: pulsador = 57; return pulsador; break;  // 9
    case 4: pulsador = 47; return pulsador; break;  // /
    case 5: pulsador = 52; return pulsador; break;  // 4
    case 6: pulsador = 53; return pulsador; break;  // 5
    case 7: pulsador = 54; return pulsador; break;  // 6
    case 8: pulsador = 42; return pulsador; break;  // *
    case 9: pulsador = 49; return pulsador; break;  // 1
    case 10: pulsador = 50; return pulsador; break; // 2
    case 11: pulsador = 51; return pulsador; break; // 3
    case 12: pulsador = 45; return pulsador; break; // -
    case 13: pulsador = 67; return pulsador; break; // c/on
    case 14: pulsador = 48; return pulsador; break; // 0
    case 15: pulsador = 61; return pulsador; break; // =
    case 16: pulsador = 43; return pulsador; break; // +
  }
}



Here is my schematic in proteus
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,021
Helped
4,894
Reputation
9,808
Reaction score
4,695
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
127,643
You have a strange programming structure, why not change:
Code:
    case 1: pulsador = 55; return pulsador; break;  // 7
to
Code:
    case 1: return '7';  break;  // 7
or better still, use a short lookup table.

However, the timing of the errors suggests your loop is running continuously, regardless of whether a key is actually pressed so you are passing values to the LCD faster than it can process them. You need to look at the keypad routine and maybe check for a default value if no key is pressed or for it to wait until one is pressed.

I strongly advise against returning the same variable 'pulsador' from a routine as you pass to it. It isn't technically incorrect but will cause confusion in the future. You change the value in the switch statement while it is running which again isn't good practice.

Brian.
 

khatus

Newbie
Joined
Oct 7, 2017
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
40
Thanks problem solved. I have write the code for 8Mhz oscillator and simulate it in proteus in 20Mhz🥴🥴
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top