STK 500 Switches

Guest #831693
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
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
Guest
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.
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

Reply

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.