hc sr04 pic code
#1

free jhljh iuhge oiurehfgrdnver f4ehlksrnfiouewfio4wrh4ou
Reply
#2
hc sr04 pic code

#include <16F877.h>
#device adc=8
#FUSES NOWDT, HS, NOPUT, PROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use delay(clock=20000000)


/************************************************************************************************
/ Used sonar - HC-SR04 & DYP ME007
/ If you are using DYP ME 007 or any other 5 pin sonar, Please note that not to take the
/ pin named 'out'. Take echo instead.
/ Pin configuration (5 pin)- VCC(+5) TRIG(Trigger pin) ECHO(Output pin) OUT(Not needed) GND (Ground)
/ Pin configuration (4 pin)- VCC(+5) TRIG(Trigger pin) ECHO(Output pin) GND (Ground)
/
/ Code by Bhanu Watawana
/ 0778111887
/ Uva Wellassa University - Sri Lanka
/ Mechatronics
*/////////////////////////////////////////////////////////////////////////////////////////////////



#define LCD_TYPE 2
#include <lcd.c>

int16 distance, time; // Defining variables


// Defining the pins

#define trig pin_B1 // Change as you wish, can use any pin in the MCU
#define echo pin_B0 // Change as you wish, can use any pin in the MCU

void main()
{
lcd_init(); // initiating the LCD

printf(LCD_PUTC, "\f Sonar test \n Code by Bhanu ");// for LCD & MCU restart troubleshooting

delay_ms(1000); // Boot-up delay, for troubleshooting

setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // initiating timer



while(true)
{

output_high(trig); // ping the sonar
delay_us(20); // sending 20us pulse
output_low(trig);

while(!input(ECHO)) // wait for high state of echo pin
{}

set_timer1(0); // setting timer zero

while(input(ECHO)) // Wait for high state of echo pin
{}

time=get_timer1(); // Getting the time

distance=time*0.028 + 1.093 ; // Calculating the distance


printf(LCD_PUTC, "\fTime :%Lu \nDistance = %Lu",time,distance); // Putting the time and
//distance to the LCD
delay_ms(1000);


}
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: code of codevision for avr sr04, how to interface hc sr04 with pic 16f877a, hc sr04 mikrobasic code, hc sr04 with pic microbasic code, hc sr04 ultrasonic sensor assembly code, hc sr04 c code, hc sr04 interface with 8051 using c code,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
Thumbs Up rupayan amar ujala in how to upload pic for cover page 1 599 18-06-2016, 11:42 AM
Last Post: dhanabhagya
  pic microcontroller based automatic phase selector 1 463 26-05-2016, 01:07 PM
Last Post: dhanabhagya
  interfacing of pic microcontroller with gas sensor mq6 1 681 23-05-2016, 12:01 PM
Last Post: dhanabhagya
Thumbs Up how to send pic for amar ujala cover page 2 605 23-05-2016, 11:33 AM
Last Post: dhanabhagya
  adc and dac interfacing in pic microcontroller ppt 1 802 20-05-2016, 03:14 PM
Last Post: dhanabhagya
  solar based home automation system using pic microcontroller ppt 1 587 13-05-2016, 10:26 AM
Last Post: dhanabhagya
  mobile phone jammer using pic microcontroller 1 667 07-05-2016, 11:33 AM
Last Post: dhanabhagya
  lcd and keypad interfacing code for pic 18f452 1 583 04-05-2016, 10:11 AM
Last Post: dhanabhagya
  prime number identifier code in lex code 1 894 29-04-2016, 11:54 AM
Last Post: dhanabhagya
  fighting robot using pic 16f877a 1 435 26-04-2016, 09:38 AM
Last Post: dhanabhagya

Forum Jump: