عندي مشكله بهاد الكود وحاولت فيه بس مش عم يقيس المسافه ! الشاشه شغاله وتعرض عادي تردد الكرستاله 4mhz الرجاء المساعده بمعرفه المشكله المجس رقم HC-SR04 وشكراااا
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RA5_bit;
sbit LCD_D5 at RA4_bit;
sbit LCD_D6 at RA3_bit;
sbit LCD_D7 at RA2_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISA5_bit;
sbit LCD_D5_Direction at TRISA4_bit;
sbit LCD_D6_Direction at TRISA3_bit;
sbit LCD_D7_Direction at TRISA2_bit;
#define TRIG portc.f0
#define TRIG_dir trisc.f0
#define ECHO portc.f1
#define ECHO_dir trisc.f1
#define input 1
#define output 0
#define high 1
#define low 0
#define on 1
#define off 0
double distance;
int x=0;
char txt[7];
char rtxt;
unsigned int H=0;
void main()
{
INTCON.GIE=0;
ADCON0.ADON=0;
DACCON0.DACEN=0;
CM1CON0.C1ON=0;
CM1CON0.C2ON=0;
ANSELA=0x00;
T1CON=0x00 ;
T1GCON.TMR1GE=on;
TRIG_dir=output;
ECHO_dir=input ;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
trisb=0x00;
while(1)
{
TMR1H = 0;
TMR1L = 0 ;
TRIG=high;
delay_us(10);
TRIG=low;
while( ECHO == low );
T1CON.f0=on;
while( ECHO == low );
T1CON.f0=off;
H= (TMR1L | (TMR1H<<8));
distance= H/58.82; //((TMR1L | (TMR1H<<8))/2)* 0.034029; H=H*2^8 ;
Lcd_Out(1,1,"distance = ");
IntToStr(distance,txt);
rtxt=Ltrim(txt);
Lcd_out_Cp(rtxt);
lcd_out_cp("cm" );
}
}