CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC Question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
slahiri
Guest







ADC Question
PostPosted: Thu Feb 20, 2003 4:53 pm     Reply with quote

I have a dum question, I do understand that I need to set up my ADC as a 10 bit value and I can do that. But my input is coming from the keypad, and say I enter 1.5v now the question is how do I know that one of the pin in porta is gving me a hex or binary equivalent of 1.5v. I know that I can do ouput_high(pindefine)but will this pin have the equivalent conversion. I am new with this compiler, I am learning as I go.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11934
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: ADC Question
PostPosted: Thu Feb 20, 2003 7:01 pm     Reply with quote

:=I have a dum question, I do understand that I need to set up my ADC as a 10 bit value and I can do that. But my input is coming from the keypad, and say I enter 1.5v now the question is how do I know that one of the pin in porta is gving me a hex or binary equivalent of 1.5v. I know that I can do ouput_high(pindefine)but will this pin have the equivalent conversion. I am new with this compiler, I am learning as I go.
-----------------------------------------------------------

Can you explain a little better ?

A keypad is a digital device. You don't need the ADC to
read data from the keypad. You just read the Port.
Your keypad driver function will return the proper
value, based on what key was pressed. See the CCS driver
file, called KBD.C for an example.
--------

I'm trying to determine what your question really is.
Is your question really this:
"If I press the keys 1 and 5 on the keypad, how do
I get the value of 15 into a variable ?"

------------
Also, I'm not sure how you enter "1.5" from a keypad
since most of them don't have a decimal point.

Example: 4x4 keypad from Grayhill:
<a href="http://embrace.grayhill.com/embrace/IMAGES/PDF/c-06-09.pdf" TARGET="_blank">http://embrace.grayhill.com/embrace/IMAGES/PDF/c-06-09.pdf</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11940
slahiri
Guest







Re: ADC Question
PostPosted: Fri Feb 21, 2003 6:08 am     Reply with quote

:=:=I have a dum question, I do understand that I need to set up my ADC as a 10 bit value and I can do that. But my input is coming from the keypad, and say I enter 1.5v now the question is how do I know that one of the pin in porta is gving me a hex or binary equivalent of 1.5v. I know that I can do ouput_high(pindefine)but will this pin have the equivalent conversion. I am new with this compiler, I am learning as I go.
:=-----------------------------------------------------------
:=
:=Can you explain a little better ?
:=
:=A keypad is a digital device. You don't need the ADC to
:=read data from the keypad. You just read the Port.
:=Your keypad driver function will return the proper
:=value, based on what key was pressed. See the CCS driver
:=file, called KBD.C for an example.
:=--------
:=
:=I'm trying to determine what your question really is.
:=Is your question really this:
:="If I press the keys 1 and 5 on the keypad, how do
:=I get the value of 15 into a variable ?"
:=
:=------------
:=Also, I'm not sure how you enter "1.5" from a keypad
:=since most of them don't have a decimal point.
:=
:=Example: 4x4 keypad from Grayhill:
:= <a href="http://embrace.grayhill.com/embrace/IMAGES/PDF/c-06-09.pdf" TARGET="_blank"> <a href="http://embrace.grayhill.com/embrace/IMAGES/PDF/c-06-09.pdf" TARGET="_blank">http://embrace.grayhill.com/embrace/IMAGES/PDF/c-06-09.pdf</a></a>



Sorry about that, after looking at the keypad I notice that there is no decimal point. What want to do is read a value from port b with the key pad and then display it in Portc.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11951
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: ADC Question
PostPosted: Fri Feb 21, 2003 1:16 pm     Reply with quote

:=Sorry about that, after looking at the keypad I notice that there is no decimal point. What want to do is read a value from port b with the key pad and then display it in Port c.
----------------------------------------------------------

The value that you get from the keypad, depends upon
the value that is returned by the keypad driver function.
If you look at the CCS driver, KBD.C, you'll see the
following section of code:

<PRE>
// Keypad layout:
char const KEYS[4][3] = {{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
</PRE>

Those numbers are arranged in a map, which corresponds
to the position of the keys on the keypad. For example,
if you press the "1" key, then the KDB.C driver will
return a value of '1', which is the ASCII value for 1.
Putting single quotes around the number causes the compiler
to make it be an ASCII value. (in hex notation, '1' = 0x31).

If you want different values to be returned by the
keypad, you could edit the table above, or do some
math or bit-wise operations on the value after you
get it from the kbd_getc() function.


You said that you wanted to output the value on Port C.
Did that mean you want to use the RS-232 serial port,
which uses two pins on Port C ? Or, did you mean that
you want to write the value directly to the port pins ?

If it's the 2nd case, then you can use the following code:

<PRE>
char value;

value = kbd_getc(); // Wait for a key from the keypad

output_c(value); // Write the key value to Port C
</PRE>

So if the value you're writing is 0x31, the "output_c(value)"
statement will write it to the bits of Port C, in the
following format:

Port C bits:
bit 0 = 1
bit 1 = 0
bit 2 = 0
bit 3 = 0
bit 4 = 1
bit 5 = 1
bit 6 = 0
bit 7 = 0
___________________________
This message was ported from CCS's old forum
Original Post ID: 11973
slahiri
Guest







Re: ADC Question
PostPosted: Fri Feb 21, 2003 1:39 pm     Reply with quote

:=:=Sorry about that, after looking at the keypad I notice that there is no decimal point. What want to do is read a value from port b with the key pad and then display it in Port c.
:=----------------------------------------------------------
:=
:=The value that you get from the keypad, depends upon
:=the value that is returned by the keypad driver function.
:=If you look at the CCS driver, KBD.C, you'll see the
:=following section of code:
:=
:=<PRE>
:=// Keypad layout:
:=char const KEYS[4][3] = {{'1','2','3'},
:= {'4','5','6'},
:= {'7','8','9'},
:= {'*','0','#'}};
:=</PRE>
:=
:=Those numbers are arranged in a map, which corresponds
:=to the position of the keys on the keypad. For example,
:=if you press the "1" key, then the KDB.C driver will
:=return a value of '1', which is the ASCII value for 1.
:=Putting single quotes around the number causes the compiler
:=to make it be an ASCII value. (in hex notation, '1' = 0x31).
:=
:=If you want different values to be returned by the
:=keypad, you could edit the table above, or do some
:=math or bit-wise operations on the value after you
:=get it from the kbd_getc() function.
:=
:=
:=You said that you wanted to output the value on Port C.
:=Did that mean you want to use the RS-232 serial port,
:=which uses two pins on Port C ? Or, did you mean that
:=you want to write the value directly to the port pins ?
:=
:=If it's the 2nd case, then you can use the following code:
:=
:=<PRE>
:=char value;
:=
:=value = kbd_getc(); // Wait for a key from the keypad
:=
:=output_c(value); // Write the key value to Port C
:=</PRE>
:=
:=So if the value you're writing is 0x31, the "output_c(value)"
:=statement will write it to the bits of Port C, in the
:=following format:
:=
:=Port C bits:
:=bit 0 = 1
:=bit 1 = 0
:=bit 2 = 0
:=bit 3 = 0
:=bit 4 = 1
:=bit 5 = 1
:=bit 6 = 0
:=bit 7 = 0

Thank you, I kind of thought in the same way, after I posted the note. a)I am not using RS232. b)I don't want ASCII. My value that I get from Keypad will be 8 bit int value, so can I still use value = kbd_getc().
___________________________
This message was ported from CCS's old forum
Original Post ID: 11974
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group