line follower using microcontroller pic16f877a

Discussion in 'Embedded Systems and Microcontrollers' started by qkiwa26, May 15, 2014.

  1. qkiwa26

    Thread Starter New Member

    May 15, 2014
    My instructor give us a project to build a line follower robot with the PIC 16F877A. And writing the source code using C programming.Can you help me guise. Im already done with my PCB LAYOUT..
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    And this PCB is...?

    What is your design? Approach? What do you need help with?
  3. enggricha


    May 17, 2014
    What do U need help with? the program, assuming you are done with the PCB.
  4. qkiwa26

    Thread Starter New Member

    May 15, 2014
    yes.. i need your help.. i used pic16f877a.. i need a code using C program.. i used also MPLAB IDE for that.
  5. qkiwa26

    Thread Starter New Member

    May 15, 2014
    my instructor gave us until wednesday for last submission :( yet until now.. i dont have a program..:(
  6. qkiwa26

    Thread Starter New Member

    May 15, 2014
    5 leds, 5 sensor !!
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    I calculate you have 5 days to complete this project, but that includes Wednesday so call it 4 to 4.5 days. You best get started as no one will write this code for you.

    We will help you with any questions you may have but we are not here to write your code for free.
  8. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    What have you done towards writing a program?

    Do you have a block diagram, showing what must be done? Then for each step, break it down into smaller pieces. For example, one block might be if robot not on line the action is to adjust direction. But which direction? A smaller piece. How to determine which direction? Another smaller piece.

    Once you understand what the robot needs to do, then you can start writing code.

    The first exercise I described should only take an hour or two. Leaving you plenty of time to write some code. Another day might be spent debugging or correcting the code. Which leaves you a day to make sure it's working and "pretty" it up.
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    That's all well and good, but even if we were to (we aren't) write the program for you, you haven't given enough information to allow someone to be able to.

    What do you expect to happen by saying
    Is that supposed to tell us how they are arranged? How they work? What their outputs are? How they are even connected to the robot?

    If you would like some help, take a few minutes and identify what you need help with, what information we need to know in order to provide said help, submit that information, and wait for a response.
  10. qkiwa26

    Thread Starter New Member

    May 15, 2014
    for now, my instructor gave us a UART as program. He changed it from C to UART.
  11. qkiwa26

    Thread Starter New Member

    May 15, 2014
    we have a 5 sensors, below of that sensors, it also have a 5 leds.. I need a program that will run to as LEFT,RIGHT and FORWARD.
  12. tshuck

    Well-Known Member

    Oct 18, 2012
    UART isn't a programming language,C is - how did your professor convert from one to another? :confused:

    ...Again, even if we were to write it for you (which, again, we won't), you have not given us enough information to even attempt to help you. Why don't you try making a table that lists all possible outputs from your sensors and their corresponding outputs: left, right, and forward, and any modifiers you may want to add to modify the strength of each output (e.g. hard right, slight left, etc.)?

    Last edited: Jun 2, 2014
    djsfantasi likes this.
  13. MaxHeadRoom


    Jul 18, 2013
    Maybe he meant for you to write UART in software, (bit-banging), rather than hardware?
  14. qkiwa26

    Thread Starter New Member

    May 15, 2014
    This is the code program of my classmate, can you guys clear this code..??
    and also use in UART.?

    Code ( (Unknown Language)):
    2. "#include <xc.h>
    5. #define FORWARD 0x09        
    6. #define RIGHT 0x08        
    7. #define LEFT 0x01        
    8. #define L_SENSOR 0x18        
    9. #define C_SENSOR 0x0E        
    10. #define R_SENSOR 0x03        
    11. #define Off    0x00        
    13. void turnLEFT();                
    14. void turnRIGHT();                
    15. void forward();                    
    16. void blank();                    
    18. void main()            
    19. {
    20. ADCON1 = 7;
    21. TRISD = 0x1F;
    22. TRISB = 0x00;
    23. PORTB = Off;
    24. while(1)
    25. {
    26. if((PORTD&L_SENSOR)==L_SENSOR)            
    27. {
    28. turnLEFT();            
    29. }
    30. else if((PORTD&R_SENSOR)==R_SENSOR)
    31. {
    32. turnRIGHT();            
    33. }
    34. else if((PORTD&C_SENSOR)==C_SENSOR)
    35. {
    36. forward();            
    37. }
    38. else
    39. {
    40. blank();            
    41. }    
    42. }
    43. }
    45. void blank()            
    46. {
    47. PORTB = FORWARD;                
    48. }
    50. void turnLEFT()            
    51. {
    52. PORTB = LEFT;
    53. }
    55. void forward()            
    56. {
    57. PORTB = FORWARD;
    58. }
    60. void turnRIGHT()        
    61. {
    62. PORTB = RIGHT;
    63. }
    65. void InitPWM(void)
    66. {
    67.     TRISC1 = 0;
    68.     TRISC2 = 0;
    69.     CCP1CON = 0x0C;
    70.     CCP2CON = 0x0C;    
    71.     PR2    = 0xFF;
    72.     T2CON    = 0x01;
    73.     T2CON |= 0x04;
    74. }
    76. void SetPWMDutyCycle(unsigned int DutyCycle)
    77. {
    78.     CCPR1L = DutyCycle>>2;
    79.     CCP1CON &= 0xCF;
    80.     CCP1CON |= (0x30&(DutyCycle<<4));
    81. }
    82. void SetPWMDutyCycle2(unsigned int DutyCycle)
    83. {
    84.     CCPR2L = DutyCycle>>2;
    85.     CCP2CON &= 0xCF;
    86.     CCP2CON |= (0x30&(DutyCycle<<4));
    87. }"
    Last edited by a moderator: Jun 4, 2014
  15. MrChips


    Oct 2, 2009
    What is UART?
  16. qkiwa26

    Thread Starter New Member

    May 15, 2014
    "A UART (Universal Asynchronous Receiver/Transmitter) is the microchip with programming that controls a computer's interface to its attached serial devices. Specifically, it provides the computer with the RS-232C Data Terminal Equipment ( DTE ) interface so that it can "talk" to and exchange data with modems and other serial devices. As part of this interface, the UART also:

    • Converts the bytes it receives from the computer along parallel circuits into a single serial bit stream for outbound transmission
    • On inbound transmission, converts the serial bit stream into the bytes that the computer handles
    • Adds a parity bit (if it's been selected) on outbound transmissions and checks the parity of incoming bytes (if selected) and discards the parity bit
    • Adds start and stop delineators on outbound and strips them from inbound transmissions
    • Handles interrupt s from the keyboard and mouse (which are serial devices with special port s)
    • May handle other kinds of interrupt and device management that require coordinating the computer's speed of operation with device speeds
    More advanced UARTs provide some amount of buffering of data so that the computer and serial devices data streams remain coordinated. The most recent UART, the 16550, has a 16-byte buffer that can get filled before the computer's processor needs to handle the data. The original UART was the 8250. If you purchase an internal modem today, it probably includes a 16550 UART (although you should ask when you buy it). According to modem manufacturer US Robotics, external modems do not include a UART. If you have an older computer, you may want to add an internal 16550 to get the most out of your external modem."
  17. tshuck

    Well-Known Member

    Oct 18, 2012
    The code is pretty clear. What are you not understanding?

    You don't "use" this code in the UART module in the PIC microcontroller. Please read the datasheet.

    So you are asking us to help you cheat?

    RTM (Read The Manual) to understand it and you might just be able to do this yourself...

    We don't need the definition of a UART, we need you to understand it and how that relates to your microcontroller, but it doesn't seem like you are interested in actually learning this material...
  18. BobTPH

    Active Member

    Jun 5, 2013
    One has to wonder how 5 sensors and 5 LEDs can make a robot move. Photon pressure?

    djsfantasi likes this.
  19. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    The last update from the OP indicates that today is the due date.
  20. BobTPH

    Active Member

    Jun 5, 2013
    My advice would be to drop the course.