Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Matrix keypad programming

Status
Not open for further replies.
He would change this
Code:
 char act_key[]  = {0,1,4,7,11,2,5,8,10,3,6,9,12} ;
use  ascii replace the numbers with the ascii '1', '2', to match key pad. '+' so on.
 
Yes.... key is a number 0 ~ 12... to see it you need to convert to ascii... ie add 48 to key..

LCD_Data(key+48);
He would change this
Code:
 char act_key[]  = {0,1,4,7,11,2,5,8,10,3,6,9,12} ;
use  ascii replace the numbers with the ascii '1', '2', to match key pad. '+' so on.

I tried this but it say invalid character constant
but when i try char act_key[] = {'5', '2','3','4','1','6','7','8','9'} ; it doesn't show error
 
Last edited:
The problem with what Ian said is your wanting - and + and = keys key+48 not going to work.

You need change the part I showed you char act_key[] = {0,1,4,7,11,2,5,8,10,3,6,9,12} ;
To some thing like this with the keys you want
char act_key[] ={ '1','2','3','4','5','6','7','8', '9','0','-','+', '='};
 
The problem with what Ian said is your wanting - and + and = keys key+48 not going to work.

You need change the part I showed you char act_key[] = {0,1,4,7,11,2,5,8,10,3,6,9,12} ;
To some thing like this with the keys you want
char act_key[] ={ '1','2','3','4','5','6','7','8', '9','0','-','+', '='};
correct, now the problem is that it show the key 5 without pressing any key (using keil) that mean's function return only one key that is 5
upload_2018-2-11_11-49-27.png
 
Well i looked at keil i don't like it I just tried SDCC It looks way better your problem is you don't no how to use printf .
And you just like me don't no enough about how to make a array

You probably be better off with a array of your keys in dec 0 to 9 then use pointer for + - * / =
Mike probably no the best way in C him and Ian

Your input is in ascii which should work if your keil handles C right I've ported a bunch of code from sdcc to xc8 on the pic . SO i would think keil would work with Mikes and Ian code I've used it on a pic with just port changes and the sbit problem but I found that xc8 can use sbit to set bits too.
 
The reason a key pad returns the number is so you can process it..

If you use ascii ( as described above ) before you process a key you have to drop the conversion..

other than that I do this
C:
if(key>9)
   {
    switch(key)
      {
       case  10: call do_ten ; break;
// etc..
 
The reason a key pad returns the number is so you can process it..

Code works well on the sdcc But I have worked on keil yet. I think I should not change the compiler for one program So, I want this code to work on keil. I am trying to figure out where the mistake is happening

I think I have to make changes in keypad function
C:
char keypad(void)
    {
       unsigned char keymask = 0xEF;
      
      char key = 0, row;
    
      char act_key[] ={'1','2','3','4','5','6','7','8', '9','0','-','+', '='};
    
       for(row = 0; row < 4; row++)  
        {
          KEYport = keymask;
        
          if(!C1) key = 1;
          if(!C2) key = 2;
          if(!C3) key = 3;
          if(!C4) key = 4;

          if(key)
            { 
              key = key +(row*4);
              return act_key[key];
            }

           keymask <<= 1;

          keymask ++;  
       }      
    return key;
    }
 
Code works well on the sdcc But I have worked on keil yet. I think I should not change the compiler for one program So, I want this code to work on keil. I am trying to figure out where the mistake is happening
What I don't get... You work with Proteus.... Proteus can integrate SDCC.. Then you can use the debug file to single step through the code... Why don't you just stick with SDCC... Its a better compiler but without the libraries..
 
What I don't get... You work with Proteus.... Proteus can integrate SDCC.. Then you can use the debug file to single step through the code... Why don't you just stick with SDCC... Its a better compiler but without the libraries..
if I use sdcc What files do I have to load to debug codes on Proteus?

I have these file
upload_2018-2-11_18-33-53.png
 
I see it all coming to together now
SDCC... Its a better compiler but without the libraries.

He needs to for get keil and learn C them libraries are nice but there a learning to and then you have problems when you need to make your own code.
That has been a big problem for me.
 
SDCC outputs these file

The omf and cdb are the debug files..

If you create the firmware in VSM make sure you uncheck "Embed files" then you will get the list I have shown..
I have installed sdcc
C:\Users\Parth\Desktop>sdcc -v
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.6.0 #9615 (MINGW64)
published under GNU General Public License (GPL)

how to configure sdcc for proteus

upload_2018-2-11_20-23-48.png
 
Proteus is the GUI.... All you need to do is install SDCC then let VSM search for compilers.. VSM is Proteus's inbuilt code editor..

If Proteus cannot find the SDCC installation, you can set it manually with the "System" dropdown menu and "Configure Compilers" Option box..
 
Proteus is the GUI.... All you need to do is install SDCC then let VSM search for compilers.. VSM is Proteus's inbuilt code editor..
..
I am just trying with led blink code. LED is blinking but how to debug code
C:
/* Main.c file generated by New Project wizard
 *
 * Created:   Sun Feb 11 2018
 * Processor: AT89C51
 * Compiler:  SDCC for 8051
 */

#include <mcs51reg.h>

#define LED_ON 1  /* LED ON */
#define LED_OFF 0 /* LED OFF */

/* LED connected to port P1 of pin 0 */
#define LED P1_0
 /* This is delay function */
void Delay (unsigned int n)
{
   unsigned int i;
  for  (i = 0; i <n; i++);
  {
  }
}
void main(void)
 {
   LED = LED_OFF; /* LED OFF */
   while (1)
   {
       LED = LED_ON; /* Turn ON LED */
       Delay(37000);  /* Wait 40 ms */
       LED = LED_OFF; /* turn off LED */
       Delay(18500);  /* wait 20ms */
   }
 }
please see attached screen shot
 

Attachments

  • blink led.jpg
    blink led.jpg
    120 KB · Views: 181
  • led 2.jpg
    led 2.jpg
    35.2 KB · Views: 176
What I do....
upload_2018-2-11_18-56-1.png
Press the second Icon... And the first line of code "LED = LED_OFF;" will be highlighted... then press F10 to step and F11 to step into..

If you do not see code, then you haven't unchecked the "Embed files" icon in project properties..

If you want floating debug windows ( So you can see the schematic ) close the VSM code window before running.. Then resize the code window and variable window to suit!!
 
Each time you press F10 the code will step through... The variable window shows every register and their contents.. As things are changed, you can see it the code behaves as it should... If you close the source code window and then press step ( second button ) all the code and variable windows can be moved about so you can see the code and the schematic whilst stepping through.
upload_2018-2-11_19-25-29.png
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top