Author Topic: Mikroc pro keypad library proteus error  (Read 399 times)

0 Members and 1 Guest are viewing this topic.

Offline khatusTopic starter

  • Regular Contributor
  • *
  • Posts: 146
  • Country: gl
Mikroc pro keypad library proteus error
« on: July 21, 2021, 08:10:00 am »
Quote from: khatus post_id=311224 time=1626793245 user_id=48839
This code works. But I am receiving the following error while simulating in proteus.
Code: [Select]
/*******************************************************************************
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


 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: Mikroc pro keypad library proteus error
« Reply #1 on: July 22, 2021, 11:35:55 am »
With the Hitachi protocol LCDs you are supposed to check the busy flag before doing any writes.
That should be done in your LCD library.
Maybe your library doesn't do that correctly, maybe your simulator doesn't handle the busy flag correctly.
Why don't you just try it with real hardware?

I don't like your ascii_to_int()
First of all, it's really int_to_ascii or even scancode_to_keycode.
You don't need a break if you have return.
You don't need to set pulsador just to return it, return 55.
You shouldn't use ASCII numeric values when a char is clearer, return '7'.
A lookup table is shorter, more efficient and clearer:
Code: [Select]
const char keys[16]={'7', 8', '9', '/', '4', '5', '6', '*', '1', '2', '3', '-', 'C', '0', '=', '+'};
Edit: I forgot 7.
« Last Edit: July 22, 2021, 05:57:56 pm by Renate »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf