[Sdcc-user] Help with conversion From: Tony Pinon - 2003-03-14 19:19:03 ```Hi all, I have a keypad hooked up to a 74C299 keypad encoder and would like to display the value pressed on my LCD display. I think I need to convert the binary coming in to the port to decimal. Can the sdcc compiler do that. ```
 Re: [Sdcc-user] Help with conversion From: Greg Hill - 2003-03-20 04:01:25 ```I'm new to sdcc myself, but I suspect that what you're looking for won't be built into any compiler. Probably what you'll have to use is a switch() to convert the value you read in into the value you need for the LCD: switch(inputvalue) { case 0x00: /* display a 0 */ ... break; case 0x01: /* display a 1 */ ... break; ... } If there is any pattern or sequence to the possible inputs, you could come up with a more clever way of doing this. For example, if you read in 0x00 for the 0 key, 0x01 for the 1 key, 0x02 for the 2 key, .. 0x09 for the 9 key, then it's easy. Most text-only LCDs use part of the ASCII standard, at least for the regular letters and numbers. Notice that in ASCII, a 0 is 0x30, a 1 is 0x31, ... . So to convert the keypad input of 0x00 into the ASCII value representing "0" for the LCD, just add 0x30 to it. This would work for all ten digits, and then you don't have to write a big switch() block. Greg Hill On Fri, 14 Mar 2003, Tony Pinon wrote: > Hi all, > I have a keypad hooked up to a 74C299 keypad encoder and would like to > display the value pressed on my LCD display. I think I need to convert the > binary coming in to the port to decimal. Can the sdcc compiler do that. > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Does your code think in ink? > You could win a Tablet PC. Get a free Tablet PC hat just for playing. > What are you waiting for? > http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en > _______________________________________________ > Sdcc-user mailing list > Sdcc-user@... > https://lists.sourceforge.net/lists/listinfo/sdcc-user > ```
 Re: [Sdcc-user] Help with conversion From: Gernot Fink - 2003-03-20 05:30:09 ```On Fri, 14 Mar 2003, you wrote: > Hi all, > I have a keypad hooked up to a 74C299 keypad encoder and would like to > display the value pressed on my LCD display. I think I need to convert the > binary coming in to the port to decimal. Can the sdcc compiler do that. > Sure. The simplest way is to calculate each Displaychar seperat: ch1=port%100+48; ch2=(port/10)%10+48; ch3=port%10+48; -- MFG Gernot ```
 Re: [Sdcc-user] Help with conversion From: Thorsten Godau - 2003-03-20 06:45:23 ```Hi, > Sure. The simplest way is to calculate each Displaychar seperat: > > ch1=port%100+48; > ch2=(port/10)%10+48; > ch3=port%10+48; shouldn´t it be: ch1=(port/100)+48; // Get the hundrets ch2=((port%100)/10)+48; // Discard hundrets and get the tens ch3=((port%100)%10)+48; // Discard hundrets, tens and get the ones ? Best regards, Thorsten -- ----------------------------------------------------- Dipl.-Ing.(FH) Thorsten Godau Voicemail/Fax +49(0)89/1488-206580 @Home mailto:thorsten.godau@... @Work mailto:thorsten.godau@... http://www.qsl.net/dl9sec http://webox.tz-mikroelektronik.de AX25: DL9SEC@...#BW.DEU.EU ----------------------------------------------------- ```
 Re: [Sdcc-user] Help with conversion From: Gernot Fink - 2003-03-20 14:29:06 ```On Thu, 20 Mar 2003, you wrote: > Hi, > > > Sure. The simplest way is to calculate each Displaychar seperat: > > > > ch1=port%100+48; 123/100= 1 > > ch2=(port/10)%10+48; 123/10=12,12%10=2 > > ch3=port%10+48; 123%10=3 > ch2=((port%100)/10)+48; // Discard hundrets and get the tens This is also ok > ch3=((port%100)%10)+48; // Discard hundrets, tens and get the ones 123%10=3 and 23%10=3 Why the additional step? -- MFG Gernot ```
 Re: [Sdcc-user] Help with conversion From: Thorsten Godau - 2003-03-21 06:42:31 ```Hi Gernot, you´re right ;-)) Best regards, Thorsten > On Thu, 20 Mar 2003, you wrote: > > Hi, > > > > > Sure. The simplest way is to calculate each Displaychar seperat: > > > > > > ch1=port%100+48; > 123/100= 1 > > > ch2=(port/10)%10+48; > 123/10=12,12%10=2 > > > ch3=port%10+48; > 123%10=3 > > > ch2=((port%100)/10)+48; // Discard hundrets and get the tens > This is also ok > > ch3=((port%100)%10)+48; // Discard hundrets, tens and get the ones > 123%10=3 > and 23%10=3 Why the additional step? > > -- > MFG Gernot > > > ------------------------------------------------------- > This SF.net email is sponsored by: Tablet PC. > Does your code think in ink? You could win a Tablet PC. > Get a free Tablet PC hat just for playing. What are you waiting for? > http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en > _______________________________________________ > Sdcc-user mailing list > Sdcc-user@... > https://lists.sourceforge.net/lists/listinfo/sdcc-user > -- ----------------------------------------------------- Dipl.-Ing.(FH) Thorsten Godau Voicemail/Fax +49(0)89/1488-206580 @Home mailto:thorsten.godau@... @Work mailto:thorsten.godau@... http://www.qsl.net/dl9sec http://webox.tz-mikroelektronik.de AX25: DL9SEC@...#BW.DEU.EU ----------------------------------------------------- ```
 Re: [Sdcc-user] Help with conversion From: Bodo Wenzel - 2003-03-21 12:29:45 ```> I have a keypad hooked up to a 74C299 keypad encoder and would like to > display the value pressed on my LCD display. I think I need to convert the > binary coming in to the port to decimal. Can the sdcc compiler do that. Why not simply use "sprintf()" and copy the buffer into the display? Hope that the libraries contain that function, although I don't know, stupid me. Bodo ```
 Re: [Sdcc-user] Help with conversion From: Dave McGuire - 2003-03-21 15:24:23 ```On Thursday, March 20, 2003, at 03:37 PM, Bodo Wenzel wrote: >> I have a keypad hooked up to a 74C299 keypad encoder and would like to >> display the value pressed on my LCD display. I think I need to >> convert the >> binary coming in to the port to decimal. Can the sdcc compiler do >> that. > Why not simply use "sprintf()" and copy the buffer into the display? > Hope > that the libraries contain that function, although I don't know, > stupid me. sprintf() is *huge*, both in terms of code and data size...it'd be an enormous waste of memory if all he needed to do was this one simple output conversion. -Dave -- Dave McGuire "I've grown hair again, just St. Petersburg, FL for the occasion." -Doc Shipley ```