EmbDev.net

Forum: µC & Digital Electronics STK 500 Switches


Author: Frank (Guest)
Posted on:

Rate this post
0 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

Author: Peter Dannegger (peda)
Posted on:

Rate this post
0 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

Author: Frank (Guest)
Posted on:

Rate this post
0 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.

Author: Alexander Liebhold (lippi2000)
Posted on:

Rate this post
0 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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.