Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

How to get data from a function which is related to an array? 8051 embedded c coding

KMS17

Newbie
Joined
Sep 15, 2020
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
4
C:
#include<reg51.h>

#include<string.h>

#include<math.h>

//Pin description

/*

P1.4 is RS

P1.6 is E

P2.4 to P2.7 are keypad row outputs

P2.0 to P2.3 & P1.0 to P1.1 are keypad column inputs

*/

extern void lcd_init(void);

extern void lcd_cmd(unsigned char);

extern void lcd_char(unsigned char);

extern void lcd_str(unsigned char *);

extern void store_font_cgram(void);

extern void lcd_display(unsigned char);

extern void delay_ms(unsigned int);

void delay_ms(unsigned int i)

{

    unsigned int  j,k;

    for(;i>0;i--)

    {

        for(j=122;j>0;j--);

        for(k=122;k>0;k--);

    }

}


sbit rs=P1^4;

sbit rw=P1^5;

sbit en=P1^6;


void lcd_init()

{

    lcd_cmd(0x30);

    delay_ms(10);

    lcd_cmd(0x30);

    delay_ms(10);

    lcd_cmd(0x30);

    delay_ms(5);

    lcd_cmd(0x38);

    lcd_cmd(0x10);

    lcd_cmd(0x01);


    lcd_cmd(0x0c);

    lcd_cmd(0x06);

  

    lcd_cmd(0x0f);

}

void lcd_display(unsigned char ch)

{

    P3=ch;

    rw=0;

    en=1;

    delay_ms(2);

    en=0;

}


void lcd_cmd(unsigned char ch)

{

    rs=0;

    lcd_display(ch);

  

}

void lcd_char(unsigned char ch)

{

    rs=1;

    lcd_display(ch);

}

void lcd_str(unsigned char *ch)

{

  

    while(*ch)

    {

        lcd_char(*ch++);

      

    }

}

void delay (unsigned int i)

{

unsigned int j;

for(;i>0;i--)

{

for(j=122;j>0;j--);

}

}


sbit R1=P2^4;

sbit R2=P2^5;

sbit R3=P2^6;

sbit R4=P2^7;

sbit C1=P2^0;

sbit C2=P2^1;

sbit C3=P2^2;

sbit C4=P2^3;

sbit C5=P1^0;

sbit C6=P1^1;


char keypad[4][6]={'o','7','8','9','x','/','p','4','5','6','-','c','%','1','2','3','b','y','r','0','.','=','+','z'};


void row_finder(int col) //Function for finding the row for column 1

{

R1=R2=R3=R4=1;

C1=C2=C3=C4=C5=C6=0;


if(R1==0)

lcd_char(keypad[0][col]);

if(R2==0)

lcd_char(keypad[1][col]);

if(R3==0)

lcd_char(keypad[2][col]);

if(R4==0)

lcd_char(keypad[3][col]);

}


void main()

{

lcd_init();

lcd_cmd(0x80);


while(1)

{

C1=C2=C3=C4=C5=C6=1;

R1=R2=R3=R4=0;

if(C1==0)

{

row_finder(0);

delay(500);

}

else if(C2==0)

{

row_finder(1);

delay(500);

}

else if(C3==0)

{

row_finder(2);

delay(500);

}


else if(C4==0)

{

row_finder(3);

delay(500);

}

else if(C5==0)

{

row_finder(4);

delay(500);

}

else if(C6==0)

{

row_finder(5);

delay(500);


}

}
             

}

Screenshot (3544).png

My doubt here is from the Row finder operation how can i get the values and place it in a switch command to make it work as a calculator?
 
Last edited by a moderator:

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,277
Helped
13,995
Reputation
28,243
Reaction score
12,645
Trophy points
1,393
Location
Bochum, Germany
Activity points
275,228
You would set a return value instead of calling lcd_char() inside the function.

The pin description is partly incorrect by the way. The ports connected to the keypad are switching direction during code execution by utilizing open drain operation of 8051 pins.
 
Last edited:

    KMS17

    points: 2
    Helpful Answer Positive Rating

KMS17

Newbie
Joined
Sep 15, 2020
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
4
The pin description is partly incorrect by the way. The ports connected to the keypad are switching direction during code execution by utilizing open drain operation of 8051 pins.
Can You please Point out the errors as I am new to this simulation, I am not able to understand it properly, Please!
 

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top