Hello, I have a problem interfacing my microcontroller with an ultrasonic sensor. I want to create a system where the ultrasonic sensor is connected to a Zilog microcontroller, and the zilog with output the level of the distance detected by the microcontrollers using LEDS. For example, if the Ultrasonic sensor detects 5 inches, the the LED with light up as 00000101, where 1 signifies a lit led and 0 as unlit led. Here are the sensor and the microcontrollers that I have been using:
**broken link removed**
**broken link removed**
**broken link removed**
The one who sold us the sensor told us that in order to connect the sensor to microcontroller, we have to lift one foot of the R27 resistor and connect it to the Receive pin of the Sequencer. According to the guy there, the R27 resistor is used for serial communications.
and this is the program that I have made:
#include<ez8.h>
#include<sio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void delay(void) {
unsigned int y;
for (y=0; y<0xFFFF;y++);
}
void main(void) {
char x;
int m;
PCAF = 0x00;
PCOC = 0x00;
PCDD = 0x00;
PCHDE |= 0xFF;
init_uart(_UART0, _DEFFREQ, _DEFBAUD);
while(1) {
select_port(_UART0);
x = getch();
delay();
m = x;
PCOUT = m;
delay();
}
}
My problem with that program is that, whenever the sensor is pointed to any distance, the only LEDs that light are the one closer at MSB: 11100000 (where 1 - lit, 0 - unlit). I don't know what's wrong.
I tried to use an oscilloscope to view if the signal at the foot of the R27 resistor is right. The signal shows positive logic configuration, 1 - High, 0 - Low. I don't if it is directly compatible with the microcontroller, but the guy at the shop where I bought the sensor, I just have to connect it directly to the Receive pin.
I've also tried modifying the code in such a way that it'll look like this:
char ch;
ch = getch();
PCOUT = ch;
but the output is still the same. Can you help me here? thanks very much