chào anh, chị. Xin giúp đỡ e về cái mạch đo khoảng cách LCD+SRF05+PIC16F877A. e làm mô phỏng chạy nhưng khi làm mạch thật lại không hiển thị được ạ!clk 8Mhz
code
#include <main.h>
#define lcd_rs_pin pin_d2
#define lcd_rw_pin pin_e1
#define lcd_enable_pin pin_d3
#define LCD_DATA4 pin_d4
#define LCD_DATA5 pin_d5
#define LCD_DATA6 pin_d6
#define LCD_DATA7 pin_d7
#include <lcd.c>
#define trigger pin_b0
#define echo pin_b4
void main()
{
float k_cach;
int16 dem=0;
output_float(echo);
output_drive(trigger)
lcd_init();
while(TRUE)
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
output_high(trigger);
delay_ms(12);
output_low(trigger);
while(!input(echo));
set_timer1(0);
while(input(echo)==1);
setup_timer_1(T1_DISABLED);
dem=get_timer1();
delay_ms(50);
if(dem>=30000)
{
lcd_gotoxy(1,1);
lcd_putc("Khong Co Vat Can");
lcd_putc('\f');
dem=0;
}
else
{
k_cach=dem/58;
lcd_gotoxy(1,1);
printf(lcd_putc,"k_cach: %.1f cm",k_cach);
}
delay_ms(50);
}
}
code
#include <main.h>
#define lcd_rs_pin pin_d2
#define lcd_rw_pin pin_e1
#define lcd_enable_pin pin_d3
#define LCD_DATA4 pin_d4
#define LCD_DATA5 pin_d5
#define LCD_DATA6 pin_d6
#define LCD_DATA7 pin_d7
#include <lcd.c>
#define trigger pin_b0
#define echo pin_b4
void main()
{
float k_cach;
int16 dem=0;
output_float(echo);
output_drive(trigger)
lcd_init();
while(TRUE)
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
output_high(trigger);
delay_ms(12);
output_low(trigger);
while(!input(echo));
set_timer1(0);
while(input(echo)==1);
setup_timer_1(T1_DISABLED);
dem=get_timer1();
delay_ms(50);
if(dem>=30000)
{
lcd_gotoxy(1,1);
lcd_putc("Khong Co Vat Can");
lcd_putc('\f');
dem=0;
}
else
{
k_cach=dem/58;
lcd_gotoxy(1,1);
printf(lcd_putc,"k_cach: %.1f cm",k_cach);
}
delay_ms(50);
}
}
Comment