arunbharathi.arasu
Full Member level 2
![Full Member level 2](/styles/images/ranks/elevel2.gif)
- Joined
- Feb 28, 2013
- Messages
- 134
- Helped
- 7
- Reputation
- 14
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Chennai, Tamil Nadu, India
- Activity points
- 2,151
Hi friends,
I tried ultrasonic coding. But I cannot receive data from ultrasonic.
I am using PIC18F4550 controller.
Here is code:
please tell me if any error / correction.
I tried ultrasonic coding. But I cannot receive data from ultrasonic.
I am using PIC18F4550 controller.
Here is code:
Code:
#include<stdio.h>
#include <string.h>
#include"uart.h"
#define _XTAL_FREQ 20000000
#define trigger RD2
#define echo RD3
void port_init()
{
TRISA1=0;
TRISD3=0XFF; //echo
TRISD2=0X00; //trigger
T1CON = 0x80;
TMR1IF = 0;
TMR1=0;
}
void delay(unsigned int de)
{
unsigned int maxde,minde;
for(maxde=0;maxde<de;maxde++)
for(minde=0;minde<453;minde++);
}
void Delay10Us()
{
int dCnt;
for(dCnt=0;dCnt<3;dCnt++);
}
void trigger_US()
{
trigger=1;
__delay_us(10);
trigger=0;
__delay_us(10);
while(echo == 0);
TMR1=0;
TMR1ON=1;
while(echo == 1 && !TMR1IF);
Time=TMR1;
TMR1ON=0;
Distance = ((float)Time/117.00);
}
void main()
{
port_init();
port1_init();
UART_init();
while(1)
{
RA1=1; //led on
delay(2000);
RA1=0; // led off
delay(2000);
trans_string("\n test"); // test uart
trigger_US();
sprintf(Total_distance,"%.03f",Distance);
trans_string(Total_distance);
}
}
please tell me if any error / correction.