EmbDev.net

Forum: µC & Digital Electronics STK 500 Switches


von Frank (Guest)


Rate this post
useful
not useful
Hello,

I connected the swiches to Port C and Config PortC = Input.

The programm shall show me a binary and decimal number to detect which 
switch is pressed down.

Dim deci as integer
Dim binar as byte

'configuration of the display: I did not write it down here, because the 
display is working correctly.

do
upperline
lcd deci
lowerline
lcd binar
loop

If you see a mistake, I thank you for any help

von Peter D. (peda)


Rate this post
useful
not useful
Frank wrote:

> The programm shall show me a binary and decimal number to detect which
> switch is pressed down.

Then you schould read the input port inside your loop.


> Dim deci as integer
> Dim binar as byte

I'm sure, the name of a variable has no influence, how it was displayed.


Peter

von Frank (Guest)


Rate this post
useful
not useful
ok, but if I add "deci = portc" and "binar = portc" into the loop, the 
display shows only a "0" and does not change, when I press a switch.

von Alexander L. (lippi2000)


Rate this post
useful
not useful
Hi Frank,

your problem is verry simple. If you want to write a byte value to PORTC 
you have to configure the data direction (DDRC=0xFF) as output and write 
data to PORT register.

But if your PORT is configured as input (DDRC=0x00)the PORT register 
will enable/disable the internal pull up resistor. If you want to read 
in external values you have to read pin register (PINC).

Summary:
         1. data output
               DDRC = 0xFF, write data to PORTC

         2. data input
               DDRC = 0x00, PORTC = 0x00(pull up resistors disabled),
               read data from PINC

Your loop should be: "deci = PINC" and "binar = PINC"

Greetings Alexander

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.