Hello guys, i m here to ask for help with the development of a code for a maze solver robot.
I have about 50 hours of microcontrolers and was given this project by the teacher. He gave me part of the code and wants me to fill in the gaps. I have no clue where or how to start, and would appreciate guide lines pointers or even basic code examples for a functional 6 sensors maze solver that i can guide myself from, and present to the teacher something that woks, even if its really really basic code,.
As programmers i think you guys can all agree that 50 hours is in no way enough to do something like this so i ask for a litle of understanding.
The main focus of my course is automation and industrial control not programming, i m counting on persuing a course on C (hopefully with strong bases) but for now i need to get pass this problem.
Bellow is the code i was given i relly hope someone can help, thanks in advance. some works are in portuguese sorry for that.
//-----------LCD-----------------------
sbit LCD_RS at RC7_bit;
sbit LCD_EN at RC6_bit;
sbit LCD_D4 at RB7_bit;
sbit LCD_D5 at RD6_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_RS_Direction at TRISC7_bit;
sbit LCD_EN_Direction at TRISC6_bit;
sbit LCD_D4_Direction at TRISB7_bit;
sbit LCD_D5_Direction at TRISD6_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD3_bit;
//-----------MOTORS--------------------
sbit MOTORL_B at RA6_bit;
sbit MOTORL_A at RA7_bit;
sbit MOTORR_A at RD0_bit;
sbit MOTORR_B at RD7_bit;
//-----------IR Receivers--------------
sbit RCL at RB0_bit;
sbit RCR at RD2_bit;
//-------------Debug Led---------------
sbit LED at RB6_bit;
sbit Button at RA1_bit;
int pow(int base, int expoente){
float resultado=1;
while(expoente!=0){
resultado=resultado*base;
–expoente;
}
return resultado;
}
void Init_Hardware(void){
TRISA=0x3F; //00111111
TRISB=0x1F; //00011111
TRISC=0x31; //00110001
TRISD=0x5C; //01011100
TRISE=0x03; //00000011
ANSELA=0x0F;
ANSELB=0x1E;
ANSELC=0x00;
ANSELD=0x00;
ANSELE=0x03;
//OSCCON=0x76;
//OSCTUNE=0xDF;
OSCCON=0b01110110;
OSCCON2.PLLRDY=0;
OSCTUNE.PLLEN=0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
PWM4_Init(980);
PWM5_Init(980);
PWM4_start();
PWM5_start();
}
void drive(int SpeedL, int SpeedR){
if(speedL>100) speedL=100;
if(speedR>100) speedR=100;
if(speedL>0){
MOTORL_B=1;
MOTORL_A=0;
}
else{
speedL=speedL*(-1);
MOTORL_B=0;
MOTORL_A=1;
}
if(speedR>0){
MOTORR_A=1;
MOTORR_B=0;
}
else{
speedR=speedR*(-1);
MOTORR_A=0;
MOTORR_B=1;
}
if(speedL==0){
MOTORL_B=0;
MOTORL_A=0;
PWM5_Set_Duty(0);
}
else PWM5_Set_Duty(speedL+155);
if(speedR==0){
MOTORR_A=1;
MOTORR_B=0;
PWM4_Set_Duty(0);
}
else PWM4_Set_Duty(speedR+155);
}
char keyboard(void){
int key_voltage;
key_voltage=ADC_read(1);
if(key_voltage>=900) return 0; // none
if(key_voltage>=600) return 3; // key3
if(key_voltage>=450) return 2; // key2
return 1; // key1
}
void automatic_start(void){
int contador=0;
do{
if((RCR&RCL)==1){
++contador;
Delay_ms(1);
}
else contador=0;
}while(contador<200);
}
void main(void) {
char ledStatus=0;
char flag=0;
Init_Hardware();
while(1){
MOTORL_B=0;
MOTORL_A=0;
MOTORR_B=0;
MOTORR_A=0;
PWM4_Set_Duty(190);
PWM5_Set_Duty(190);
}
}