line follower using microcontroller pic16f877a

Thread Starter

qkiwa26

Joined May 15, 2014
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..
 

tshuck

Joined Oct 18, 2012
3,534
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..
And this PCB is...?

What is your design? Approach? What do you need help with?
 

ErnieM

Joined Apr 24, 2011
8,377
my instructor gave us until wednesday for last submission :( yet until now.. i dont have a program..:(
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.
 

djsfantasi

Joined Apr 11, 2010
9,163
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.
 

tshuck

Joined Oct 18, 2012
3,534
yes.. i need your help.. i used pic16f877a.. i need a code using C program.. i used also MPLAB IDE for that.
my instructor gave us until wednesday for last submission :( yet until now.. i dont have a program..:(
5 leds, 5 sensor !!
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
5 leds, 5 sensor !!
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.
 

Thread Starter

qkiwa26

Joined May 15, 2014
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.
 

tshuck

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

[...]I need a program that will run to as LEFT,RIGHT and FORWARD.
...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:
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.
 
Last edited:

Thread Starter

qkiwa26

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

Rich (BB 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:

Thread Starter

qkiwa26

Joined May 15, 2014
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."
 

tshuck

Joined Oct 18, 2012
3,534
[...]can you guys clear this code..??
The code is pretty clear. What are you not understanding?

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

This is the code program of my classmate[...]
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...
 
Top