line follower using microcontroller pic16f877a

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

  1. qkiwa26

    qkiwa26 Thread Starter New Member

    Joined:
    May 15, 2014
    Messages:
    10
    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

    tshuck E-book Developer

    Joined:
    Oct 18, 2012
    Messages:
    3,048
    Location:
    Long Beach, CA
    And this PCB is...?

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

    enggricha Member

    Joined:
    May 17, 2014
    Messages:
    54
    Location:
    Chennai, India
    What do U need help with? the program, assuming you are done with the PCB.
  4. qkiwa26

    qkiwa26 Thread Starter New Member

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

    qkiwa26 Thread Starter New Member

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

    qkiwa26 Thread Starter New Member

    Joined:
    May 15, 2014
    Messages:
    10
    5 leds, 5 sensor !!
  7. ErnieM

    ErnieM AAC Fanatic!

    Joined:
    Apr 24, 2011
    Messages:
    5,357
    Location:
    Lon Guyland, Noo Yawk
    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

    djsfantasi Well-Known Member

    Joined:
    Apr 11, 2010
    Messages:
    1,058
    Location:
    Northeast US
    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

    tshuck E-book Developer

    Joined:
    Oct 18, 2012
    Messages:
    3,048
    Location:
    Long Beach, CA
    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

    qkiwa26 Thread Starter New Member

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

    qkiwa26 Thread Starter New Member

    Joined:
    May 15, 2014
    Messages:
    10
    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

    tshuck E-book Developer

    Joined:
    Oct 18, 2012
    Messages:
    3,048
    Location:
    Long Beach, CA
    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.)?

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

    MaxHeadRoom Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    4,049
    Location:
    Canada
    Maybe he meant for you to write UART in software, (bit-banging), rather than hardware?
    Max.
  14. qkiwa26

    qkiwa26 Thread Starter New Member

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

    Code:
    "#include <xc.h>
    __CONFIG (FOSC_HS & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_OFF & PROTECT);
    
    #define FORWARD 0x09        
    #define RIGHT 0x08        
    #define LEFT 0x01        
    #define L_SENSOR 0x18        
    #define C_SENSOR 0x0E        
    #define R_SENSOR 0x03        
    #define Off    0x00        
    
    void turnLEFT();                
    void turnRIGHT();                
    void forward();                    
    void blank();                    
    
    void main()            
    {
    ADCON1 = 7;
    TRISD = 0x1F;
    TRISB = 0x00;
    PORTB = Off;
    while(1)
    {
    if((PORTD&L_SENSOR)==L_SENSOR)            
    {
    turnLEFT();            
    }
    else if((PORTD&R_SENSOR)==R_SENSOR)
    {
    turnRIGHT();            
    }
    else if((PORTD&C_SENSOR)==C_SENSOR)
    {
    forward();            
    }
    else
    {
    blank();            
    }    
    }
    }
    
    void blank()            
    {
    PORTB = FORWARD;                
    }
    
    void turnLEFT()            
    {
    PORTB = LEFT;
    }
    
    void forward()            
    {
    PORTB = FORWARD;
    }
    
    void turnRIGHT()        
    {
    PORTB = RIGHT;
    }
    
    void InitPWM(void)
    {
        TRISC1 = 0;
        TRISC2 = 0;
        CCP1CON = 0x0C;
        CCP2CON = 0x0C;    
        PR2    = 0xFF;
        T2CON    = 0x01;
        T2CON |= 0x04;
    }
    
    void SetPWMDutyCycle(unsigned int DutyCycle)
    {
        CCPR1L = DutyCycle>>2;
        CCP1CON &= 0xCF;
        CCP1CON |= (0x30&(DutyCycle<<4));
    }
    void SetPWMDutyCycle2(unsigned int DutyCycle)
    {
        CCPR2L = DutyCycle>>2;
        CCP2CON &= 0xCF;
        CCP2CON |= (0x30&(DutyCycle<<4));
    }"
    
    Last edited by a moderator: Jun 4, 2014
  15. MrChips

    MrChips Moderator Staff Member

    Joined:
    Oct 2, 2009
    Messages:
    9,318
    What is UART?
  16. qkiwa26

    qkiwa26 Thread Starter New Member

    Joined:
    May 15, 2014
    Messages:
    10
    "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

    tshuck E-book Developer

    Joined:
    Oct 18, 2012
    Messages:
    3,048
    Location:
    Long Beach, CA
    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

    BobTPH Member

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

    Bob
    djsfantasi likes this.
  19. djsfantasi

    djsfantasi Well-Known Member

    Joined:
    Apr 11, 2010
    Messages:
    1,058
    Location:
    Northeast US
    The last update from the OP indicates that today is the due date.
  20. BobTPH

    BobTPH Member

    Joined:
    Jun 5, 2013
    Messages:
    475
    My advice would be to drop the course.

    Bob
Similar Threads: line follower
Forum Title Date
Embedded Systems and Microcontrollers Line Follower Robot using 8051 Jun 17, 2012
Embedded Systems and Microcontrollers PID in line follower robo Jul 23, 2010
Embedded Systems and Microcontrollers Line follower Feb 7, 2010
Embedded Systems and Microcontrollers Line follower and CCS compiler Mar 17, 2009
Embedded Systems and Microcontrollers Line follower using atmega 16 Mar 9, 2009

Share This Page