PIC 16F877A C code problem - diyAudio
Go Back   Home > Forums > Source & Line > Digital Source

Digital Source Digital Players and Recorders: CD , SACD , Tape, Memory Card, etc.

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 29th March 2012, 06:37 PM   #1
diyAudio Member
 
Join Date: Oct 2011
Default PIC 16F877A C code problem

hello every body,
I need help on my line follower robot based on PIC 16f877A. i download C source code and try to Hi Tech compiler to compile this code in MPLAB. but it show missing error in first 6 line. but i can't find any problem those line. i give the code without header file. plz any body find the error or convert it HEX format.
<><><><><><><><><><><><><><><><><><><><><><><><><< >

#include <16F877A.h>; //declare a PIC header
#include <stdlib.h>
//#include <pic.h>
#include <delay.h>
#device adc=8; //set the bit for ADC
#fuses hs, nowdt, noprotect; //set the PIC protection
#use delay (clock=20000000); //set the clock frequency
int val1; //ADC value 1 left sensor
int val2; //ADC value 2 center sensor
int val3; //ADC value 3 right sensor
int vref; //voltage reference
void lmotor(int gear); //left motor function
void rmotor(int gear); //right motor function
#byte PORTA=5; //assign port a
#byte PORTD=8; //assign port d

void main() //main function
{
vref=0x7f; //set voltage reference value
set_tris_d(0); //declare port d as output
setup_port_a(ALL_ANALOG); //enable port a as ADC port
setup_adc(ADC_CLOCK_INTERNAL); //set the clock for ADC
setup_ccp1(CCP_PWM); //set enable ccp1
setup_ccp2(CCP_PWM); //set enable ccp2
setup_timer_2(T2_DIV_BY_4,100,1); //set post scaler timer

while(1) //inifinite loop
{
PORTD=0xaa; //set value for motor
set_adc_channel(0); //ADC at port A0 channel
val1=read_adc(); //read and store A0 value
set_adc_channel(2); //ADC at port A2 channel
val2=read_adc(); //read and store A2 value
set_adc_channel(4); //Adc at port A4
val3=read_adc(); //read and store A4 value

//start condition
//if sensor sense dark then value is greater than Vref
//if sensor sense bright then value is lower than Vref
if(val2>vref) //if sensor 2 is dark
{
if((val1<vref)&&(val3<vref)) //sensor 1&3 is bright
{ //send value to motor ccp
lmotor(70); //both motor moving at same rate
rmotor(70);
}
else if (val1>vref) //sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}
else if (val3>vref) //sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
}
else if ((val1>vref)&&(val3<vref)) //if only sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}

else if ((val3>vref)&&(val1<vref)) //if only sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
else //other than condition above
{
lmotor(60); //left motor move slow
rmotor(60); //right motor move slow
}


}
}
//end program
void lmotor(int gear) //left motor ccp control function
{
set_pwm1_duty(gear); //ccp1 duty cycle

}

void rmotor(int gear) //right motor ccp control function
{
set_pwm2_duty(gear); //ccp2 duty cycle
}

<><><><><><><><><><><><><><><><><><><><><><><>

It is very very emargency in my study.

Plz help me very queckly.

Thanks to all

Mehedi.

Last edited by mirrayhan08; 29th March 2012 at 06:48 PM. Reason: Change Something
  Reply With Quote
Old 6th April 2012, 12:02 AM   #2
Wolfsin is offline Wolfsin  United States
diyAudio Member
 
Join Date: Aug 2009
Blog Entries: 2
#include <16F877A.h>; //declare a PIC header

; appears misplaced
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LED UV lightbox, Inkjet stencils, SMT, PIC 16F887 and BCD code wakibaki Construction Tips 14 8th September 2010 04:36 AM
Problem witht [code]blah[/code] ? elseif Forum Problems 1 17th August 2008 12:30 AM
PGA/PIC Interface Problem biff584 Digital Source 14 27th September 2004 09:45 PM
Bold problem in vB Code EC8010 Forum Problems 5 8th March 2003 02:33 AM


New To Site? Need Help?

All times are GMT. The time now is 04:04 PM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2