Can Anyone Convert This Asm/C File to hex

Thread Starter

Flyer

Joined Jul 19, 2010
3
hi,
i in the project of making line follower robot
i already have the asm/c file but i cant convert
here is the code
Rich (BB code):
#include <16f877a.h>                         //declare a PIC header
#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  
}
 

tmd_63

Joined Oct 20, 2008
13
Rather than just converting this code to hex.
Have you thought of using the MPLAB IDE from Microchip. This environment will allow you to create your own hex files and is free to download and use from www.microchip.com.
Then you can create and debug further code without asking here.
 

Thread Starter

Flyer

Joined Jul 19, 2010
3
Rather than just converting this code to hex.
Have you thought of using the MPLAB IDE from Microchip. This environment will allow you to create your own hex files and is free to download and use from www.microchip.com.
Then you can create and debug further code without asking here.
how ???? ( i not using pickit ? )
 

BMorse

Joined Sep 26, 2009
2,675
how ???? ( i not using pickit ? )

If not using a programmer, what do you expect to do with the hex file??
Once compiled to Hex, you still have to program the uc... and you will need a Pickit2/3 and MPLAB from microchip.... or some other programmer...

B. Morse
 
Top