line following c language

Thread Starter

dekwankib

Joined Nov 30, 2013
1
Rich (BB code):
//Title: LINE FOLLOWING COMPETIIION //

#include <18f4550.h>
#fuses HS, NOWDT, NOLVP, NOPROTECT
#device ADC =10
#use delay (clock =20M)

#include <lcd.c>

//Configure LCD

#Define LCD_ENABLE_PIN PIN_D0
#Define LCD_RS_PIN PIN_D1
#Define LCD_RW_PIN PIN_D2
#Define LCD_DATA4 PIN_D4
#Define LCD_DATA5 PIN_D5
#Define LCD_DATA6 PIN_D6
#Define LCD_DATA7 PIN_D7

//Define IRSensor // BUTTON 

#Define IR1_switch PIN_A0
#Define IR2_switch PIN_A1
#Define IR3_switch PIN_A2

// Define LED

#Define LED_1 PIN_B3
#Define LED_2 PIN_B4
#Define LED_3 PIN_B5

// Define MOTOR

#Define FWD_LEFT PIN_C4
#Define RVS_LEFT PIN_C5
#Define FWD_RIGHT PIN_C6
#Define RVS_RIGHT PIN_C7

// Define PWM

#Define PWM1 PIN_C1
#Define PWM2 PIN_C2

Void main()
{
Lcd_init();

//Configure Input Outpot Pin

set_tris_a(0x0f);
output_a(0b11000111);
set_tris_b(0x00);
output_b(0b00111000);
Set_tris_c(0x00);
output_c(0x00);

//Configure PWM pin

setup_timer_2(T2_DIV_BY_4,254,1);//PWM OUTPUT CONFIGURATION
setup_ccp1(ccp_pwm); //PWM 1 DUTY CYCLE CONFIGURATION
setup_ccp2(ccp_pwm); //PWM 2 DUTY CYCLE CONFIGURATION

//Mention Title

printf (lcd_putc, "\fLINE FOLLOWER A+");


while(true)
{ 
if(!input(PIN_A1)) // follow line 
{
while(!input(PIN_A1))continue; 
// MOTOR1
Output_low(PIN_C4);
Output_high(PIN_C5); 
output_low(PIN_B3);
output_high(PIN_B4);
output_low(PIN_B5);
set_PWM1_duty(100); 

// MOTOR2
Output_high(PIN_C6);
Output_low(PIN_C7);
printf(lcd_putc,"\fFOLLOW LINE");
printf(lcd_putc,"\nFOLLOW LINE"); 
set_PWM2_duty(100); 

}

if(!input(PIN_A0)) // Turn Right
{
while(!input(PIN_A0))continue;

// MOTOR1
Output_high(PIN_C4);
Output_high(PIN_C5); 
output_high(PIN_B3);
output_low(PIN_B4);
output_low(PIN_B5);
set_PWM1_duty(100); 

// MOTOR2
Output_high(PIN_C6);
Output_low(PIN_C7);
printf(lcd_putc,"\fON");
printf(lcd_putc,"\nTURN RIGHT"); 
set_PWM2_duty(100);

}


if(!input(PIN_A2)) // Turn Left

{
while(!input(PIN_A2))continue;

// MOTOR1
Output_low(PIN_C4);
Output_high(PIN_C5); 
output_low(PIN_B3);
output_low(PIN_B4);
output_high(PIN_B5);
set_PWM1_duty(100); 

// MOTOR2
Output_low(PIN_C6);
Output_low(PIN_C7);
printf(lcd_putc,"\fTURN LEFT");
printf(lcd_putc,"\nON"); 
set_PWM2_duty(100); 

} 

}
}
help me check this
 

WBahn

Joined Mar 31, 2012
29,932
help me check this
Seriously?

If I were to send you some code and not give hardly any hint regarding what it was supposed to do and whether or not is was misbehaving and then ask you to check it for me, would you really have any idea how to go about checking it?
 
Top