Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

creating hex file to run 16f877a in proteus

Status
Not open for further replies.

minhduc515

New Member
Hello guys... I'm new with microcontroller and i get some issue with CCS C compiler

I have downloaded an code folder for 16f877a, which is contain that following C soure file
Code:
 float phaseA,phaseB,phaseC;
 #define pa RB4_bit
 #define pb RB1_bit
 #define pc RB0_bit
 #define role RB3_bit
 #define phase 311.23
void main() {
  C1INV_bit=0;
  C2INV_bit=0;
  TRISB=0;
  pa=0;
  pb=0;
  pc=0;
  role=0;
  ADC_Init();
  while(1)
  {
    phaseA=(ADC_Read(5)*5.0/1023)*101;
    phaseB=(ADC_Read(1)*5.0/1023)*101;
    phaseC=(ADC_Read(4)*5.0/1023)*101;
    if(phaseA>1.1*phase||phaseB>1.1*phase||phaseC>1.1*phase||phaseA<0.9*phase||phaseB<0.9*phase||phaseC<0.9*phase)
    {
       delay_ms(2);
        if(phaseA>1.1*phase||phaseB>1.1*phase||phaseC>1.1*phase||phaseA<0.9*phase||phaseB<0.9*phase||phaseC<0.9*phase)
        {
           role=1;
           if(phaseA>1.1*phase)
           {
             pa=1;
           }
           else
           {
             pa=0;
           }
           if(phaseB>1.1*phase||phaseB<0.9*phase)
           {
             pb=1;
           }
           else
           {
             pb=0;
           }
           if(phaseC>1.1*phase||phaseC<0.9*phase)
           {
             pc=1;
           }
           else
           {
             pc=0;
           }
        }
        else
        {
          role=0;
        }
    }
  }
}
. I test on proteus and it works well..
But i when i re-complie that C Soure File, it has some error

Z880oFu.png


How can i fix this issue ? and why it still running well in proteus , even it doesn's have header (#include <16f877a.h> ...... )?
 
If you do not get a clean compile, the hex file will be left untouched, so it will still work ok!!
To compile the C file CCS is asking you for a target as It cannot continue... #include<16f877a> will have the information it needs..
 
If you do not get a clean compile, the hex file will be left untouched, so it will still work ok!!
To compile the C file CCS is asking you for a target as It cannot continue... #include<16f877a> will have the information it needs..

what i have to do now to compile that C file ?
 
I think that code is for MiKroC so it'll need a bit of work to use the CCS compiler..

MikroC isn't fully ANSI C compatible so using CCS or XC8 will need a re-write ...

You need to change all SFR references to the CCS definitions... You need an ADC init routine , a ADC read routine also a delay_ms routine...
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top