Microcontroller › PIC › Input text in array with push button. › Hi SujitI don’t know how to
Hi Sujit
I don't know how to work with a PIC but I can surely help you with the logic behind this kind of code.
Lets make it simple by using if-else instructions to check which button has been pressed and then perform the respective task. The code would be somewhat like this:
first of all declare all variables to be used, like
integer variable (say int i=0,j=64;) //characters' ASCII value start from 65=90, check it out.
character string (say char arr[10]
if(button 1 pressed)
{
if(j==90) //char is 'Z'
{j=65} //char becomes 'A'
else
{j++;} //increment char
arr=j; //put char value in string's ith position
}
else if(button 2 pressed)
{
if(j==65 || j==64) //char is either 'A' or its ASCII value is 64
{j=90} //char becomes 'Z'
else
{j–;}
arr=j;
else if(button 3 pressed)
{
i++; //increment string's position
}
else if(button 4 pressed)
{
arr[i+1]=''; //close the string with a null character
i=0; //reset i's value to 0
//also here you should include a code which will store this string on eeprom of PIC
}
You can adjsut the string size according to your need and look out for some code that will help you to store string in eeprom. Try searching out at EGs search bar (top right corner).
You can also write a code to print this process on LCD, just add the LCDdisplay() lines just after if-else instructions.
This might hlep you. Good luck!!