View previous topic :: View next topic |
Author |
Message |
Rinner
Joined: 30 Nov 2016 Posts: 1 Location: peron
|
Help with this program |
Posted: Wed Nov 30, 2016 5:12 pm |
|
|
Code: |
#include <12F675.h>
#Fuses Intro_io,nowdt,noprotect,nomclr
#use delay (clock=400000)
#define trig pin_b1
#define echo input (pin_b6)
int16 mide_distancia()
{
int16 centimetros=0; //De 2 a 500cm
output_high(trig);
delay_ms(30);
output_low(trig);
delay_ms(30);
while (echo==0);
while (echo==1);
{
centimetros ++;
delay_ms(60);
}
return (centimetros);
void main (void)
{
{
distancia=mide.distancia();
if(distancia <100)
}
{
output_high(pin_b5);
delay_ms(1000);
output_low(pin_b5);
delay_ms(500);
}
else
output_low(pib_b5);
} //Fin del while
}// fin del voin main (void)
|
This have 11 errors and i cant resolve them _________________ peron |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Nov 30, 2016 5:40 pm |
|
|
re:
#use delay (clock=400000)
invalid clock option ?
400KHz probably isn't correct
I 'think' it should be 4000000 or 4M. Four Megahertz ?
When posting a program use the 'code' button, 5th option in the 'Message body' line under the Subject line....
That will really help !!
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 30, 2016 6:12 pm |
|
|
It's clear that you copied that program from here:
http://www.forosdeelectronica.com/f26/sensor-distancia-hc-sr04-78308/
It's also clear that you hand typed it, and made many mistakes in typing.
You also left off braces. Just copy and paste code. Don't hand type it.
It looks like they got the code from here:
http://campos-inventronica.blogspot.com/2012/04/como-usar-sensor-ultrasonico-hc-sr04.html
The page above has many more explanations of how the code works
(in Spanish).
Also, the 12F675 doesn't have a Port B. You can't use pins such as
PIN_B6. It only has Port A. You can only use:
Quote: | PIN_A0
PIN_A1
PIN_A2
PIN_A3
PIN_A4
PIN_A5 |
Finally, attention to detail is important in writing programs. You have
mis-spelled words:
Quote: | Intro_io
output_low(pib_b5); |
|
|
|
|