line following c language

Discussion in 'Programmer's Corner' started by dekwankib, Nov 30, 2013.

  1. dekwankib

    Thread Starter New Member

    Nov 30, 2013
    1
    0
    Code ( (Unknown Language)):
    1. //Title: LINE FOLLOWING COMPETIIION //
    2.  
    3. #include <18f4550.h>
    4. #fuses HS, NOWDT, NOLVP, NOPROTECT
    5. #device ADC =10
    6. #use delay (clock =20M)
    7.  
    8. #include <lcd.c>
    9.  
    10. //Configure LCD
    11.  
    12. #Define LCD_ENABLE_PIN PIN_D0
    13. #Define LCD_RS_PIN PIN_D1
    14. #Define LCD_RW_PIN PIN_D2
    15. #Define LCD_DATA4 PIN_D4
    16. #Define LCD_DATA5 PIN_D5
    17. #Define LCD_DATA6 PIN_D6
    18. #Define LCD_DATA7 PIN_D7
    19.  
    20. //Define IRSensor // BUTTON
    21.  
    22. #Define IR1_switch PIN_A0
    23. #Define IR2_switch PIN_A1
    24. #Define IR3_switch PIN_A2
    25.  
    26. // Define LED
    27.  
    28. #Define LED_1 PIN_B3
    29. #Define LED_2 PIN_B4
    30. #Define LED_3 PIN_B5
    31.  
    32. // Define MOTOR
    33.  
    34. #Define FWD_LEFT PIN_C4
    35. #Define RVS_LEFT PIN_C5
    36. #Define FWD_RIGHT PIN_C6
    37. #Define RVS_RIGHT PIN_C7
    38.  
    39. // Define PWM
    40.  
    41. #Define PWM1 PIN_C1
    42. #Define PWM2 PIN_C2
    43.  
    44. Void main()
    45. {
    46. Lcd_init();
    47.  
    48. //Configure Input Outpot Pin
    49.  
    50. set_tris_a(0x0f);
    51. output_a(0b11000111);
    52. set_tris_b(0x00);
    53. output_b(0b00111000);
    54. Set_tris_c(0x00);
    55. output_c(0x00);
    56.  
    57. //Configure PWM pin
    58.  
    59. setup_timer_2(T2_DIV_BY_4,254,1);//PWM OUTPUT CONFIGURATION
    60. setup_ccp1(ccp_pwm); //PWM 1 DUTY CYCLE CONFIGURATION
    61. setup_ccp2(ccp_pwm); //PWM 2 DUTY CYCLE CONFIGURATION
    62.  
    63. //Mention Title
    64.  
    65. printf (lcd_putc, "\fLINE FOLLOWER A+");
    66.  
    67.  
    68. while(true)
    69. {
    70. if(!input(PIN_A1)) // follow line
    71. {
    72. while(!input(PIN_A1))continue;
    73. // MOTOR1
    74. Output_low(PIN_C4);
    75. Output_high(PIN_C5);
    76. output_low(PIN_B3);
    77. output_high(PIN_B4);
    78. output_low(PIN_B5);
    79. set_PWM1_duty(100);
    80.  
    81. // MOTOR2
    82. Output_high(PIN_C6);
    83. Output_low(PIN_C7);
    84. printf(lcd_putc,"\fFOLLOW LINE");
    85. printf(lcd_putc,"\nFOLLOW LINE");
    86. set_PWM2_duty(100);
    87.  
    88. }
    89.  
    90. if(!input(PIN_A0)) // Turn Right
    91. {
    92. while(!input(PIN_A0))continue;
    93.  
    94. // MOTOR1
    95. Output_high(PIN_C4);
    96. Output_high(PIN_C5);
    97. output_high(PIN_B3);
    98. output_low(PIN_B4);
    99. output_low(PIN_B5);
    100. set_PWM1_duty(100);
    101.  
    102. // MOTOR2
    103. Output_high(PIN_C6);
    104. Output_low(PIN_C7);
    105. printf(lcd_putc,"\fON");
    106. printf(lcd_putc,"\nTURN RIGHT");
    107. set_PWM2_duty(100);
    108.  
    109. }
    110.  
    111.  
    112. if(!input(PIN_A2)) // Turn Left
    113.  
    114. {
    115. while(!input(PIN_A2))continue;
    116.  
    117. // MOTOR1
    118. Output_low(PIN_C4);
    119. Output_high(PIN_C5);
    120. output_low(PIN_B3);
    121. output_low(PIN_B4);
    122. output_high(PIN_B5);
    123. set_PWM1_duty(100);
    124.  
    125. // MOTOR2
    126. Output_low(PIN_C6);
    127. Output_low(PIN_C7);
    128. printf(lcd_putc,"\fTURN LEFT");
    129. printf(lcd_putc,"\nON");
    130. set_PWM2_duty(100);
    131.  
    132. }
    133.  
    134. }
    135. }
    help me check this
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    checking .... Check !!!
     
  3. WBahn

    Moderator

    Mar 31, 2012
    17,737
    4,789
    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?
     
  4. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    which compiler are you even using?!?! clearly mplab as its a microchip processor, but HTC or C18? or another?
     
Loading...