Étape 3: Source Code
#include < 18F458.h >#device ADC = 8
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock=8000000)
#use rs232 (baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
#define GLCD_WIDTH 128
#define GLCD_E PIN_E0 / / activer
#define GLCD_DI PIN_B5
#define GLCD_CS1 PIN_A1 / / puce sélection 1
#define GLCD_CS2 PIN_B0
#define SERVO PIN_A3
#include < HDM64GS12.c >
#include < graphics.c >
#include < math.h >
Char [message] = "EndtaS RaDaR" ;
flotteur thêta = 0, ytheta ;
Sub main() {}
INT1 enbas ;
int mesafe ;
int car1, sayac, un ;
servopos d’Int16 ;
setup_adc_ports(RA0_ANALOG) ;
setup_adc(ADC_CLOCK_INTERNAL) ;
set_adc_channel(0) ;
enbas :
glcd_init(on) ;
glcd_fillScreen(OFF) ;
glcd_text57 (30, 0, message, 1, 1) ;
glcd_circle (26, 29, 37, 0, 1) ;
glcd_pixel (29, 37, ON) ;
thêta = 7.85 ;
servopos = 550 ;
printf("Scan_START\r\n") ;
while (true) {}
Mesafe = read_adc() ;
printf ("th: %f -> %u \r\n\n",theta, mesafe) ;
ytheta = theta ;
sayac = 1 ;
Si (enbas == TRUE) {}
sayac = 50 ;
}
pour (a = 0; a < sayac ; un ++) {}
output_high(servo) ;
delay_us(servopos) ;
output_low(servo) ;
delay_us (20000 - servopos) ;
}
Si (enbas == TRUE) {}
glcd_circle (29, 37, 25, 1, 0) ;
glcd_pixel (29, 37, ON) ;
printf("Scan_START\r\n") ;
delay_ms(300) ;
}
Si (ytheta > = 4.51) {}
ytheta-=. 02 ;
servopos += 12 ;
enbas = FALSE ;
}
else {}
glcd_circle (29, 37, 25, 1, 0) ;
ytheta = 7.85 ;
servopos = 550 ;
glcd_pixel (29, 37, ON) ;
enbas = TRUE ;
printf("Scan_COMPLETE\r\n") ;
}
glcd_pixel (28+(int)(car1*sin(-theta)+.5), 38-(int)(car1*cos(theta)+.5), OFF) ;
glcd_pixel (28+(int)(car1*sin(-theta-1)+.5), 38-(int)(car1*cos(theta-1)+.5), OFF) ;
thêta = ytheta ;
CAR1 = mesafe / 8 ;
glcd_pixel (28+(int)(car1*sin(-theta)+.5), 38-(int)(car1*cos(theta)+.5), ON) ;
delay_ms(10) ;
}
}