Advertisement
chayanforyou

LCD Keypad Interface - PIC18F4550

Jul 19th, 2021
1,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.33 KB | None | 0 0
  1. /*******************************************************************************
  2. Program for, LCD Keypad Interfacing
  3. MCU: PIC18F4550; X-Tal: 8MHz(internal); Compiler: mikroC pro for PIC v7.6.0
  4. Date: 19-08-2021;
  5. *******************************************************************************/
  6.  
  7. sbit LCD_RS at LATB4_bit;
  8. sbit LCD_EN at LATB5_bit;
  9. sbit LCD_D4 at LATB0_bit;
  10. sbit LCD_D5 at LATB1_bit;
  11. sbit LCD_D6 at LATB2_bit;
  12. sbit LCD_D7 at LATB3_bit;
  13. sbit LCD_RS_Direction at TRISB4_bit;
  14. sbit LCD_EN_Direction at TRISB5_bit;
  15. sbit LCD_D4_Direction at TRISB0_bit;
  16. sbit LCD_D5_Direction at TRISB1_bit;
  17. sbit LCD_D6_Direction at TRISB2_bit;
  18. sbit LCD_D7_Direction at TRISB3_bit;
  19.  
  20. // global variables
  21. char keypadPort at PORTD; // required by 4x4 keypad library
  22. char text[17];
  23. char ascii_to_int( char);
  24.  
  25.  
  26. void main() {
  27.  
  28.   char pulsador = 0;
  29.   char valor;
  30.   TRISB = 0x00;
  31.   TRISC = 0x00;
  32.  
  33.   Keypad_Init();
  34.  
  35.   LCD_Init(); // Inicializamos la pantalla LCD
  36.   LCD_Cmd(_LCD_CLEAR); // Limpia la pantalla LCD
  37.   LCD_Cmd(_LCD_CURSOR_OFF); // Apaga el cursor en la pantalla
  38.   Delay_ms(500); // Retardo de 500 milisegundos
  39.  
  40.   do {
  41.     pulsador = Keypad_Key_Press();
  42.     valor = ascii_to_int(pulsador);
  43.     //ByteToStr(pulsador, text);
  44.     //Lcd_Out(1, 1, "ASCII:");
  45.     //Lcd_Out_Cp(text);
  46.     Lcd_Out(1, 1, "Key: ");
  47.     Lcd_Chr(1, 6, valor);
  48.   } while (1);
  49. }
  50.  
  51. char ascii_to_int(char pulsador) {
  52.   switch (pulsador) {
  53.     case 1: pulsador = 55; return pulsador; break;  // 7
  54.     case 2: pulsador = 56; return pulsador; break;  // 8
  55.     case 3: pulsador = 57; return pulsador; break;  // 9
  56.     case 4: pulsador = 47; return pulsador; break;  // /
  57.     case 5: pulsador = 52; return pulsador; break;  // 4
  58.     case 6: pulsador = 53; return pulsador; break;  // 5
  59.     case 7: pulsador = 54; return pulsador; break;  // 6
  60.     case 8: pulsador = 42; return pulsador; break;  // *
  61.     case 9: pulsador = 49; return pulsador; break;  // 1
  62.     case 10: pulsador = 50; return pulsador; break; // 2
  63.     case 11: pulsador = 51; return pulsador; break; // 3
  64.     case 12: pulsador = 45; return pulsador; break; // -
  65.     case 13: pulsador = 67; return pulsador; break; // c/on
  66.     case 14: pulsador = 48; return pulsador; break; // 0
  67.     case 15: pulsador = 61; return pulsador; break; // =
  68.     case 16: pulsador = 43; return pulsador; break; // +
  69.   }
  70. }
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement