We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]
Rating:
Author: Tiago Henrique
Last Updated: 2016-02-23
Package Version: 1.0.0.1
Category: Measurement
Downloaded: 2209 times
Followed by: 2 users
License: MIT license
Biblioteca para trabalhar com o sensor ultrassônico HC-SR04. Este sensor é utilizado para medir distâncias de até 4m e identificar a presença de objetos ou captar movimentos.
Do you want to subscribe in order to receive notifications regarding "HC-SR04 Library" changes.
Do you want to unsubscribe in order to stop receiving notifications regarding "HC-SR04 Library" changes.
Do you want to report abuse regarding "HC-SR04 Library".
DOWNLOAD LINK | RELATED COMPILER | CONTAINS |
---|---|---|
1392251670_hc_sr04_library_mikroc_pic.zip [797B] | mikroC PRO for PIC |
|
BLOG: http://microcontrolandos.blogspot.com.br
EXEMPLO
/*
HC-SR04 - Sensor Ultrassonico
MCU: PIC18F4550
CLOCK: HS + PLL, 48MHz
*/
#include "HC-SR04.h"
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
sbit HCSR04_Trigger at RD0_Bit;
sbit HCSR04_Echo at RD1_Bit;
sbit HCSR04_Trigger_Direction at TRISD0_Bit;
sbit HCSR04_Echo_Direction at TRISD1_Bit;
char text[8];
unsigned Distancia;
//factor = 1 / ( ( 4 * Prescaler ) / Clock )
const float factor = 1.5;
void main()
{
ADCON1 = 0x0F;
//0 - prescaler 1:1
//1 - prescaler 1:2
//2 - prescaler 1:4
//3 - prescaler 1:8
HCSR04_Init(3);
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1)
{
Distancia = HCSR04_Read();
WordToStrWithZeros( Distancia, text );
Lcd_Out( 1, 1, "Dist.: " )
Lcd_Out_CP( text );
Lcd_Out_CP( "mm" );
Delay_ms( 300 );
}
}