Get the input from user and print on screen

Thread Starter

Parth786

Joined Jun 19, 2017
642
Hi all
This is program that takes input from user and than print on screen
C:
   #include <stdio.h>
  int main ()
{
        int a, b;
        /* get first number from user */
        printf("Enter your first number:");
        scanf("%d", &a);
        /* get second number from user */
        printf("Enter your second number:");
        scanf("%d", &b);
        return 0;
  }
Now If I want to do same thing in embedded c programming.

when user press button1, 1 is stored
when user press button2, 2 is stored

suppose I want to write embedded c program that take inputs from user (buttons) and than display on LCD screen.( 8051, LCD 16*2 button1 and button 2)
I am not asking for all program. I am just asking for below condition
how do we write embedded c program that take data from user input ?
how do we write embedded c program that display user input ?

Note: I have already asked in many time regarding calculator. but I am not asking here for calculator programming so please don't compare this thread with my other thread. here I am asking different information.
 

nsaspook

Joined Aug 27, 2009
13,315
There are about a thousand ways to read, store and display button presses.
Do a search for examples.

Some simple ways are as boolean values in an int variable or individual bits within a variable.
Using your C <stdio.h> program as a example you could store the button state as a 0 or 1 value in a integer variable for each button then you could use sprintf to create a formatted string for a display.

Sprintf example:
http://www.geeksforgeeks.org/sprintf-in-c/

Now this is not a very good example of small device embedded c programming because it uses a large c library function like stdio instead of direct register/memory manipulation.
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
There are about a thousand ways to read, store and display button presses.
I always being confused on read, store regarding embedded c programming
Read: read the input device
For example
Read : if (switch == closed)
Read the switch input : weather switch is close or open
Read sensor input : weather switch is active or not
Read the keypad input

Store : int closed =1;
store the value of switch at address
store the value of sensor at address
store the value of keypad at address

Some simple ways are as boolean values in an int variable or individual bits within a variable.
Now this is not a very good example of small device embedded c programming because it uses a large c library function like stdio instead of direct register/memory manipulation.
let me explain , suppose when we call on mobile we press buttons than numbers show on mobile screen. think like that we have 8051, LCD and 10 buttons. Now I am trying to write embedded c programming to display numbers on LCD screen.
first step: we need to read 10 buttons
second step : we have to store the value of buttons
third step : we have to display value of each buttons

Q1 how do we write embedded c program to read the input from device. what the basic logic of c programming we use?
Q2 how do we write embedded c program to store the input information. what the basic logic of c programming we use?

my main problem is that I don't understand when and where I need to use correct logic
 

philba

Joined Aug 17, 2017
959
lol. now be nice!

However, I have to agree. There is no substitute for study. Find some examples that do this. Learn from them. Then apply that to your problem. For what it's worth, there are about 10,000 examples of code out there that checks a button or switch and does something. Google gives me pages and pages of hits to "embedded c button code example". Now go forth and learnify.
 
Top