I am working on creating an ultrasonic range detector. I am currently testing the sensor to make sure that it is functioning properly. I have connected the echo pin and trigger pin to PC4 and PC5 respectively. When I run this code, ideally it would send 6 to my display. However, it is displaying 0. This leads me to believe that code is not properly interfacing with the sensor. Please help.
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
void DisplayIt(int i);
int main(void)
{
while(1)
{
DDRC = 0xFF;
int i = 0;
PORTC = 0b00000000;
_delay_us(2);
PORTC = 0b00100000;
_delay_us(10);
PORTC = 0x00;
DDRC = 0x00;
if (PINC == 0b00010000)
{
i = 6;
}
DisplayIt(i);
}
}
PINC
andPORTC
are the same register.PORTC = 0x00;
sets the contents of this register to 0 just before you read it.