EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / what is wrong with my code , i wanna save the pressed key from Keypad to an array

what is wrong with my code , i wanna save the pressed key from Keypad to an array

|

Microcontroller › PIC › what is wrong with my code , i wanna save the pressed key from Keypad to an array

  • This topic has 4 replies, 2 voices, and was last updated 11 years, 11 months ago by medo.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • May 5, 2014 at 5:37 pm #3072
    medo
    Participant

    Hi 

    im a newbie for microcontroller, 

    i wrote a simple code to save it to array using mickroc

    but the screen always show a wrong number , and protues

     

    //before this line , definin

    int i;

    int x;

    char fromuser[4];

     

     

    void main()

    {

    do{

    i=0;

    kb=keypad_key_press();

    fromuser=kb;

     

    i++;

    }while(kb!=4) // 4 is mean On/c button,

     

    for(x=0;x<4;x++)

    {

     

    lcd_chr(1,x+1,fromuser+48);

     

     

    }

     

    }

     

    Please i need a help to understand whats wrong 

    thanks

     

     

    May 6, 2014 at 3:41 am #11684
    SHAH DISHANT H.
    Participant

    Hi,

     

    Show us the routine of key detecting function…!!

     

    Nothing sees wrong with above code…!!

    May 6, 2014 at 8:10 am #11688
    medo
    Participant

    wysiwyg_imageupload:12301:

    May 6, 2014 at 8:17 am #11689
    medo
    Participant

    Dear Alex , 

    the keypad 4×4 

     

     

    count from 7 its Ascii value is 1 

    button 4 …ascii value 2

    button 1 …ascii value 3

    button on/c …ascii value 4

    button 8 …ascii value 5

    button 5…ascii value 6

    button 2 …ascii value 7

     

    button 0 …ascii value 8

     

    button 9 …ascii value 9

     

    button 6 …ascii value 10

     

    button 3 …ascii value 11

     

    button = …ascii value 12

     

    button % …ascii value 13

     

    button x…ascii value 14

     

    button – …ascii value 15

     

    button + …ascii value 16

     

    for show the number to screen i convert to ascii by adding 48 

    or using 

    inttostr function

     

     

    after i press 4 button , 

    then later the lcd show the number 4000

     

    i dont know whats up

     

    thanks for u help

     
     
     
     
     

     

    May 6, 2014 at 8:27 am #11690
    medo
    Participant

    char keypadPort at PORTd;

    // Start LCD module connections

    sbit LCD_RS at Rb0_bit;

    sbit LCD_EN at Rb1_bit;

    sbit LCD_D4 at Rb4_bit;

    sbit LCD_D5 at Rb5_bit;

    sbit LCD_D6 at Rb6_bit;

    sbit LCD_D7 at Rb7_bit;

    sbit LCD_RS_Direction at TRISb0_bit;

    sbit LCD_EN_Direction at TRISb1_bit;

    sbit LCD_D4_Direction at TRISb4_bit;

    sbit LCD_D5_Direction at TRISb5_bit;

    sbit LCD_D6_Direction at TRISb6_bit;

    sbit LCD_D7_Direction at TRISb7_bit;

    // End LCD module connections

    int x,i;

    char fromuser[4];

     int kb;

     void main()

     {

      adcon1=7;

      lcd_init();

      keypad_init();

     

      lcd_out(1,1,”welcome”);

      delay_ms(2000);

      lcd_cmd(1);

     

      do{

          i=0;

         

          kb=keypad_key_press();

          fromuser=kb;

          i++;

      }while(kb!=4);

      for(x=0;x<4;x++){lcd_chr(1,x+1,fromuser[x]+48);}

     }//end main

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • compile errors April 22, 2026
  • Quick Tip: Handling CH340 Driver Issues on Uno SMD Clones April 22, 2026
  • My Advanced Realistic Humanoid Robots Project April 22, 2026
  • Getting into an LED bulb April 21, 2026
  • understanding of resonance in time domain April 21, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise