Can Anyone Convert This Asm/C File to hex

Discussion in 'Programmer's Corner' started by Flyer, Jul 19, 2010.

  1. Flyer

    Thread Starter New Member

    Jul 19, 2010
    3
    0
    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
    Code ( (Unknown Language)):
    1. #include <16f877a.h>                         //declare a PIC header
    2. #device adc=8                                //set the bit for ADC
    3. #fuses hs,nowdt,noprotect                    //set the PIC protection
    4. #use delay (clock=20000000)                  //set the clock frequency
    5. int val1;                                    //ADC value 1  left sensor
    6. int val2;                                    //ADC value 2  center sensor
    7. int val3;                                    //ADC value 3  right sensor
    8. int vref;                                    //voltage reference
    9. void lmotor(int gear);                       //left motor function
    10. void rmotor(int gear);                       //right motor function
    11. #byte porta=5                                //assign port a
    12. #byte portd=8                                //assign port d
    13.  
    14. void main()                                  //main function
    15. {
    16.    vref=0x7f;                                //set voltage reference value
    17.    set_tris_d(0);                            //declare port d as output
    18.    setup_port_a(all_analog);                 //enable port a as ADC port
    19.    setup_adc(adc_clock_internal);            //set the clock for ADC
    20.    setup_ccp1(ccp_pwm);                      //set enable ccp1
    21.    setup_ccp2(ccp_pwm);                      //set enable ccp2
    22.    setup_timer_2(t2_div_by_4,100,1);         //set post scaler timer
    23.  
    24.    while(1)                                  //inifinite loop
    25.    {
    26.    portd=0xaa;                               //set value for motor
    27.    set_adc_channel(0);                       //ADC at port A0 channel
    28.    val1=read_adc();                          //read and store A0 value
    29.    set_adc_channel(2);                       //ADC at port A2 channel
    30.    val2=read_adc();                          //read and store A2 value
    31.    set_adc_channel(4);                       //Adc at port A4
    32.    val3=read_adc();                          //read and store A4 value
    33.    
    34.    //start condition
    35.    //if sensor sense dark then value is greater than Vref
    36.    //if sensor sense bright then value is lower than Vref
    37.    if(val2>vref)                             //if sensor 2 is dark
    38.    {
    39.       if((val1<vref)&&(val3<vref))           //sensor 1&3 is bright
    40.       {                                      //send value to motor ccp
    41.       lmotor(70);                            //both motor moving at same rate
    42.       rmotor(70);
    43.       }
    44.       else if (val1>vref)                    //sensor 1 is dark
    45.       {  
    46.       lmotor(0);                             //left motor stop
    47.       rmotor(70);                            //right motor move
    48.       }        
    49.       else if (val3>vref)                    //sensor 3 is dark
    50.       {
    51.       lmotor(70);                            //left motor move
    52.       rmotor(0);                             //right motor stop
    53.       }
    54.    }
    55.    else if ((val1>vref)&&(val3<vref))        //if only sensor 1 is dark
    56.    {
    57.       lmotor(0);                             //left motor stop
    58.       rmotor(70);                            //right motor move
    59.    }
    60.    
    61.  
    62.  
    63.  
    64.  
    65. else if ((val3>vref)&&(val1<vref))          //if only sensor 3 is dark
    66.    {
    67.       lmotor(70);                            //left motor move
    68.       rmotor(0);                             //right motor stop
    69.    }
    70.    else                                      //other than condition above
    71.    {
    72.       lmotor(60);                            //left motor move slow
    73.       rmotor(60);                            //right motor move slow
    74.    }
    75.    
    76.  
    77.    }
    78. }                      
    79.    //end program
    80. void lmotor(int gear)                        //left motor ccp control function
    81. {
    82.    set_pwm1_duty(gear);                      //ccp1 duty cycle  
    83.    
    84. }
    85.  
    86. void rmotor(int gear)                        //right motor ccp control function
    87. {
    88.    set_pwm2_duty(gear);                      //ccp2 duty cycle  
    89. }
     
  2. tmd_63

    Member

    Oct 20, 2008
    13
    0
    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.
     
  3. Flyer

    Thread Starter New Member

    Jul 19, 2010
    3
    0
    how ???? ( i not using pickit ? )
     
  4. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    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
     
  5. Flyer

    Thread Starter New Member

    Jul 19, 2010
    3
    0
    its ok , i already solve the problem
     
Loading...