user4203: So I am working on this lab for my Embedded Systems class, but I can't seem to read anything but the first bit of PORTC.  What's even weirder is that if any of the pins go low the first bit will go to 0, while all the others stay at 0 no matter what.
Here is my code:
 /*
 * Lab_4A.c
 *
 *  Reads the value of one distance sensor
 *  and reports if light/dark to the LCD.
 *
 *  Created on: Sep 24, 2014
 *  Author: Austin R. Bartz
 *
 *  LCD Connections:
 *  E   - PB4 (Digital 12)
 *  RS  - PB5 (Digital 13)
 *  R/W - GND
 *  Data 4,5,6,7 - PD4,5,6,7 (Digital 4,5,6,7)
 *
 *  Sensor Connections:
 *  Sensor 8 - PC0 (Analog A0)
 *  Sensor 7 - PC1 (Analog A1)
 *  Sensor 6 - PC2 (Analog A2)
 *  Sensor 5 - PC3 (Analog A3)
 */

#include <avr/io.h>
#include <inttypes.h>
#include <MSOE/delay.c>
#include <MSOE/bit.c>
#include <MSOE/lcd.c>
#include <user/initPorts.c>
#include <user/readPorts.c>
#include <user/writePorts.c>

void printBinaryLCD(uint8_t);
uint8_t readSensors();

int main(void)
{
    lcd_init();
    lcd_clear();
    while(1)
    {
        uint8_t val = readSensors();
        printBinaryLCD(val);
    }
}

void printBinaryLCD(uint8_t val)
{
    lcd_home();
    uint8_t A = ((PINC & (1<<3)) == (1<<3));
    lcd_print_uint8(A);
    lcd_goto_xy(1,0);
    uint8_t B = ((PINC & (1<<2)) == (1<<2));
    lcd_print_uint8(B);
    lcd_goto_xy(2,0);
    uint8_t C = ((PINC & (1<<1)) == (1<<1));
    lcd_print_uint8(C);
    lcd_goto_xy(3,0);
    uint8_t D = ((PINC & (1<<0)) == (1<<0));
    lcd_print_uint8(D);
}

uint8_t readSensors()
{
    DDRC = 1;
    PORTC = 1;
    delay_us(10);
    DDRC = 0;
    PORTC = 0;
    delay_ms(1);
    return PINC;
}

Any help would be much appreciated!

user8033: DDRx is the Data-Direction-Register-x so this can be DDRC or DDRD or anything. One register has 8 bits, 1 bit for every pin.
Making a bit 1 will result in the pin being an output. Making it 0 will result in the pin being an input.
Let's say we want to make pin 4 and 5 of port C an output.
We simply do this in the setup:
       //76543210  Pin numbers.
       //IIOOIIII  Input/Output indicator
DDRC = 0b00110000;//Code that actually does it.

So this way we can read pin 4 & 5.
But if we want to read the complete port, I suggest setting every pin of the port to input. DDRC = 0b00000000;
Then we can read the port as simply as uint8_t portValueC = PORTC;
portValueC will now have a value that represents the port's values.
It'll be binary, but you read it as decimal.
So it'll be:
0 for no inputs.
1 for only pin 0
2 for pin 1
3 for pin 0 & 1
4 for pin 2
5 for pin 2 & 0
6 for pin 2 & 1

Well. it's binary.
Let's say (pin 7,5,3,1 high)(pin 6,4,2,0 low).
This will result into the decimal value of 170.
The binary value, however, will be easier to read 0b10101010
    //76543210
  //0b10101010 (Could be the value) (pin 7,5,3,1 high)(pin 6,4,2,0 low)
//^ is decimal: 170

You should add these macros to your project to make it easier to get single bits from this value:
#define bit_get(p,m) ((p) & (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))

This way, now you can do:
if(bit_get(PINC, BIT(3)))
{
 //Do only this if PORTC pin 3 is high
}

Read this first:
Info on the registers
Info on bit fiddling

user7508: Judging from your readSensors() function, these seem to be capacitive
sensors:

you charge them to Vcc (DDRC = 1; PORTC = 1;)
you wait until they are fully charged (delay_us(10);)
you tri-state the pin (DDRC = 0; PORTC = 0)
you wait for them to partially self-discharge (delay_ms(1);)
you read the pin (return PINC;)

If my assumption is correct, and if all of those sensors are similar,
then here is your first bug: you are only charging the sensor on PC0. If
you want to charge the four sensors, you need to set bits 0 to 3 of the
port to active high. Thus, the first two statements in readSensors()
should be:
DDRC = 0x0f;   // bits 0 to 3...
PORTC = 0x0f;  // ...set to active high

Your second bug is in printBinaryLCD(). The function name, and the way
you call it, implies it is meant to print on the LCD the value passed as
a parameter. Instead, it is completely ignoring its parameter, and
reading PORTC itself. This is bad because the reading of the
capacitive sensors is time sensitive, so you should let readSensors()
do the work. You should then change printBinaryLCD() so that it
examines val instead of PORTC:
void printBinaryLCD(uint8_t val)
{
    lcd_home();
    uint8_t A = (val & (1<<3)) != 0;
    ...etc...


4203: <p>So I am working on this lab for my Embedded Systems class, but I can't seem to read anything but the first bit of PORTC.  What's even weirder is that if any of the pins go low the first bit will go to 0, while all the others stay at 0 no matter what.</p>

<p>Here is my code:</p>

<pre><code> /*
 * Lab_4A.c
 *
 *  Reads the value of one distance sensor
 *  and reports if light/dark to the LCD.
 *
 *  Created on: Sep 24, 2014
 *  Author: Austin R. Bartz
 *
 *  LCD Connections:
 *  E   - PB4 (Digital 12)
 *  RS  - PB5 (Digital 13)
 *  R/W - GND
 *  Data 4,5,6,7 - PD4,5,6,7 (Digital 4,5,6,7)
 *
 *  Sensor Connections:
 *  Sensor 8 - PC0 (Analog A0)
 *  Sensor 7 - PC1 (Analog A1)
 *  Sensor 6 - PC2 (Analog A2)
 *  Sensor 5 - PC3 (Analog A3)
 */

#include &lt;avr/io.h&gt;
#include &lt;inttypes.h&gt;
#include &lt;MSOE/delay.c&gt;
#include &lt;MSOE/bit.c&gt;
#include &lt;MSOE/lcd.c&gt;
#include &lt;user/initPorts.c&gt;
#include &lt;user/readPorts.c&gt;
#include &lt;user/writePorts.c&gt;

void printBinaryLCD(uint8_t);
uint8_t readSensors();

int main(void)
{
    lcd_init();
    lcd_clear();
    while(1)
    {
        uint8_t val = readSensors();
        printBinaryLCD(val);
    }
}

void printBinaryLCD(uint8_t val)
{
    lcd_home();
    uint8_t A = ((PINC &amp; (1&lt;&lt;3)) == (1&lt;&lt;3));
    lcd_print_uint8(A);
    lcd_goto_xy(1,0);
    uint8_t B = ((PINC &amp; (1&lt;&lt;2)) == (1&lt;&lt;2));
    lcd_print_uint8(B);
    lcd_goto_xy(2,0);
    uint8_t C = ((PINC &amp; (1&lt;&lt;1)) == (1&lt;&lt;1));
    lcd_print_uint8(C);
    lcd_goto_xy(3,0);
    uint8_t D = ((PINC &amp; (1&lt;&lt;0)) == (1&lt;&lt;0));
    lcd_print_uint8(D);
}

uint8_t readSensors()
{
    DDRC = 1;
    PORTC = 1;
    delay_us(10);
    DDRC = 0;
    PORTC = 0;
    delay_ms(1);
    return PINC;
}
</code></pre>

<p>Any help would be much appreciated!</p>
 8033: <p><code>DDRx</code> is the Data-Direction-Register-x so this can be <code>DDRC</code> or <code>DDRD</code> or anything. One register has 8 bits, 1 bit for every pin.
Making a bit 1 will result in the pin being an output. Making it 0 will result in the pin being an input.</p>

<p>Let's say we want to make pin 4 and 5 of port C an output.
We simply do this in the setup:</p>

<pre><code>       //76543210  Pin numbers.
       //IIOOIIII  Input/Output indicator
DDRC = 0b00110000;//Code that actually does it.
</code></pre>

<p>So this way we can read pin 4 &amp; 5.
But if we want to read the complete port, I suggest setting every pin of the port to input. <code>DDRC = 0b00000000;</code></p>

<p>Then we can read the port as simply as <code>uint8_t portValueC = PORTC;</code></p>

<p>portValueC will now have a value that represents the port's values.
It'll be binary, but you read it as decimal.
So it'll be:</p>

<pre><code>0 for no inputs.
1 for only pin 0
2 for pin 1
3 for pin 0 &amp; 1
4 for pin 2
5 for pin 2 &amp; 0
6 for pin 2 &amp; 1
</code></pre>

<p>Well. it's binary.</p>

<p>Let's say (pin 7,5,3,1 high)(pin 6,4,2,0 low).</p>

<p>This will result into the decimal value of 170.</p>

<p>The binary value, however, will be easier to read <code>0b10101010</code></p>

<pre><code>    //76543210
  //0b10101010 (Could be the value) (pin 7,5,3,1 high)(pin 6,4,2,0 low)
//^ is decimal: 170
</code></pre>

<p>You should add these macros to your project to make it easier to get single bits from this value:</p>

<pre><code>#define bit_get(p,m) ((p) &amp; (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &amp;= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 &lt;&lt; (x))
</code></pre>

<p>This way, now you can do:</p>

<pre><code>if(bit_get(PINC, BIT(3)))
{
 //Do only this if PORTC pin 3 is high
}
</code></pre>

<p>Read this first:</p>

<p><a href="http://www.elecrom.com/2008/02/12/avr-tutorial-2-avr-input-output/" rel="nofollow">Info on the registers</a></p>

<p><a href="http://www.avrfreaks.net/forum/tut-c-bit-manipulation-aka-programming-101?name=PNphpBB2&amp;file=viewtopic&amp;t=37871" rel="nofollow">Info on bit fiddling</a></p>
 7508: <p>Judging from your <code>readSensors()</code> function, these seem to be capacitive
sensors:</p>

<ul>
<li>you charge them to Vcc (<code>DDRC = 1; PORTC = 1;</code>)</li>
<li>you wait until they are fully charged (<code>delay_us(10);</code>)</li>
<li>you tri-state the pin (<code>DDRC = 0; PORTC = 0</code>)</li>
<li>you wait for them to partially self-discharge (<code>delay_ms(1);</code>)</li>
<li>you read the pin (<code>return PINC;</code>)</li>
</ul>

<p>If my assumption is correct, and if <em>all</em> of those sensors are similar,
then here is your first bug: you are only charging the sensor on PC0. If
you want to charge the four sensors, you need to set bits 0 to 3 of the
port to active high. Thus, the first two statements in <code>readSensors()</code>
should be:</p>



<pre><code>DDRC = 0x0f;   // bits 0 to 3...
PORTC = 0x0f;  // ...set to active high
</code></pre>

<p>Your second bug is in <code>printBinaryLCD()</code>. The function name, and the way
you call it, implies it is meant to print on the LCD the value passed as
a parameter. Instead, it is completely ignoring its parameter, and
reading <code>PORTC</code> itself. This is bad because the reading of the
capacitive sensors is time sensitive, so you should let <code>readSensors()</code>
do the work. You should then change <code>printBinaryLCD()</code> so that it
examines <code>val</code> instead of <code>PORTC</code>:</p>

<pre><code>void printBinaryLCD(uint8_t val)
{
    lcd_home();
    uint8_t A = (val &amp; (1&lt;&lt;3)) != 0;
    ...etc...
</code></pre>
