synchrone
Newbie level 4
Hello
i have a mikrocontroller pic 16f628a and a ultrasonic sonsor HC-SR04
I'm working with the intern pulse 4MHz
pleas tell me why this code not working
i have a mikrocontroller pic 16f628a and a ultrasonic sonsor HC-SR04
I'm working with the intern pulse 4MHz
pleas tell me why this code not working
Code:
//Crystal 4MHz
//speed of sound 340m/s
//1 TMR0 cycle = (340/1000000)*256*0.5*100 = 4.352 in cm
#define TRIG PORTA.F0
#define ECHO PORTA.F1
double distance;
void main() {
TRISa.F0 = 1;
TRISa.F1 = 0;
TRISb=0;
OPTION_REG.T0CS = 0;
OPTION_REG.PSA = 0;
OPTION_REG.PS0 = 1;
OPTION_REG.PS1 = 1;
OPTION_REG.PS2 = 1;
while(1){
TRIG = 0;
delay_us(10);
TRIG = 1;
delay_us(10);
TRIG = 0;
while(ECHO==0);
TMR0=0;
while(ECHO==1);
distance = (double)TMR0 * 4.352;
Delay_ms(100);
}
if(distance < 6) portb=1; // if distance < 6 cm
else portb=0;
}
Last edited by a moderator: