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.

Errors compiling C code

Status
Not open for further replies.
Regarding this project, https://pic16f628a.blogspot.com/2010/09/pic16f628a-ds1820-4-digit-seven-segment.html I'm having trouble compiling and I don't know if I'm doing something wrong or there's something wrong with the code itself. I'm trying to compile this code in MPLAB with Hi-Tech C as the compiler. I get a bunch of errors when I build the file.

Code:
/* Project name:
     Seven-segment display digital thermometer
 * Copyright:
     (c) Rajendra Bhatt, 2010.
      MCU:             PIC16F628A
     Oscillator:      XT, 4.0 MHz
*/

// Temperature digits
unsigned short i, DD0=0x3f, DD1=0x3f,DD2=0x3f, CF_Flag=0xff, CF=0x3f, N_Flag;
// CF_Flag = 0: F, 1: C
// Variable to store temperature register value
unsigned temp_value=0, temp_whole;
unsigned int temp_fraction=0;
float temp_F;

//-------------- Function to Return mask for common cathode 7-seg. display
unsigned short mask(unsigned short num) {
  switch (num) {
    case 0 : return 0x3F;
    case 1 : return 0x06;
    case 2 : return 0x5B;
    case 3 : return 0x4F;
    case 4 : return 0x66;
    case 5 : return 0x6D;
    case 6 : return 0x7D;
    case 7 : return 0x07;
    case 8 : return 0x7F;
    case 9 : return 0x6F;
    case 10 : return 0x40;  // Symbol '-'
    case 11 : return 0x39;   // Symbol C
    case 12 : return 0x71;   // Symbol F
    case 13 : return 0x00;  // Blank
  } //case end
}

void display_temp(short DD0, short DD1, short DD2, short CF)    {
    for (i = 0; i<=200; i++) {
      PORTB = DD0;
      RA0_bit = 1;          // Select Ones Digit
      RA1_bit = 0;
      RA2_bit = 0;
      RA3_bit = 0;
      delay_ms(5);
      PORTB = DD1;
      RA0_bit = 0;
      RA1_bit = 1;        // Select Tens Digit
      RA2_bit = 0;
      RA3_bit = 0;
      delay_ms(5);
      PORTB = DD2;
      RA0_bit = 0;
      RA1_bit = 0;
      RA2_bit = 1;        // Select +/- Digit
      RA3_bit = 0;
      delay_ms(5);
      PORTB = CF;
      RA0_bit = 0;
      RA1_bit = 0;
      RA2_bit = 0 ;
      RA3_bit = 1;        // Select CF Digit
      delay_ms(5);
        }
     return;
}


void main() {
  CMCON  |= 7;      // Disable Comparators
  TRISB = 0x00;    // Set PORTB direction to be output
  PORTB = 0x00;    // Turn OFF LEDs on PORTB
  TRISA0_bit = 0;  // RA.0 to RA3 Output
  TRISA1_bit = 0;
  TRISA2_bit = 0;
  TRISA3_bit = 0;


    //--- main loop
  do {

    N_Flag = 0;  // Reset Temp Flag
    //--- perform temperature reading
    Ow_Reset(&PORTA, 4);      // Onewire reset signal
    Ow_Write(&PORTA, 4, 0xCC);   // Issue command SKIP_ROM
    Ow_Write(&PORTA, 4, 0x44);   // Issue command CONVERT_T
    display_temp(DD0, DD1, DD2,CF)   ;
    Ow_Reset(&PORTA, 4);
    Ow_Write(&PORTA, 4, 0xCC);    // Issue command SKIP_ROM
    Ow_Write(&PORTA, 4, 0xBE);    // Issue command READ_SCRATCHPAD

    // Next Read Temperature
    // Read Byte 0 from Scratchpad
    temp_value =  Ow_Read(&PORTA, 4);
    // Then read Byte 1 from Scratchpad and shift 8 bit left and add the Byte 0
    temp_value = (Ow_Read(&PORTA, 4) << 8) + temp_value;

    if (temp_value & 0x8000) {
     temp_value = ~temp_value + 1;
     N_Flag = 1;   // Temp is -ive
     }
    if (temp_value & 0x0001) temp_value += 1;   // 0.5 round to 1
    temp_value = temp_value >> 1 ;
    if (CF_Flag == 0) {
     if (N_Flag ==1) {
      temp_F = (32.0-9.0*temp_value/5.0)*10 + 6;
      if (temp_F < 0){
         N_Flag=1;
         temp_value = abs(temp_value);
         }
         else N_Flag = 0;
      }
    else temp_F = (9.0*temp_value/5.0+32.0)*10 + 6; //If decimal is greater or equal
                                             // to 0.5, add 0.5
    temp_value = temp_F/10;
    CF = 12;
    }

    if (CF_Flag == 0xff) CF = 11;

    DD0 = temp_value%10;  // Extract Ones Digit
    DD0 = mask(DD0);
    DD1 = (temp_value/10)%10; // Extract Tens Digit
    DD1 = mask(DD1);
    DD2 =  temp_value/100; // Extract Hundred digit
    CF = mask(CF);
    if (N_Flag == 1) DD2=10;
    else if (DD2 == 0) DD2 = 13 ;
    DD2 = mask(DD2) ;

      PORTB=0x00;
      CF_Flag =~CF_Flag;

    } while (1);
}

Here's the error message:

Code:
Build C:\PK2 Lessons\LPC Demo Board\Clock_Temp\Clock_temp for device 16F628A
Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe

Make: The target "C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 "C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c" -q --chip=16F628A -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --debugger=icd2 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
Warning [343] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 35.1 implicit return at end of non-void function
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 39.1 undefined identifier "PORTB"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 40.1 undefined identifier "RA0_bit"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 41.1 undefined identifier "RA1_bit"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 42.1 undefined identifier "RA2_bit"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 43.1 undefined identifier "RA3_bit"
Warning [361] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 44.1 function declared implicit int
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 69.1 undefined identifier "CMCON"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 70.1 undefined identifier "TRISB"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 71.1 undefined identifier "PORTB"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 72.1 undefined identifier "TRISA0_bit"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 73.1 undefined identifier "TRISA1_bit"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 74.1 undefined identifier "TRISA2_bit"
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 75.1 undefined identifier "TRISA3_bit"
Warning [361] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 83.1 function declared implicit int
Error   [192] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 83.11 undefined identifier "PORTA"
Warning [361] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 84.1 function declared implicit int
Warning [361] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 93.14 function declared implicit int
Warning [361] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 108.14 function declared implicit int
Warning [356] C:\PK2 Lessons\LPC Demo Board\Clock_Temp\clock.c; 114.23 implicit conversion of float to integer

********** Build failed! **********


Could someone try to compile the code and let me know if it works on their end? Thanks :)
 
As above..... You only need to include the htc.h header file as it calls the necessary files to compile...

I also noticed there s no __CONFIG() statement.... It's always wise to have a config setting.
 
Thanks for your help. I'll try that tonight. I was wondering about some sort of include file.

What should the config line say?
 
OK, looked at a few examples from Ian's tutorials and added this to the code:

#include <pic.h> // pic specific identifiers
#define _XTAL_FREQ 4000000 // Xtal speed

I added those 2 after the 7th line in the original code and I still get the same errors.
 
That code was written for MikroC Compiler from Mikroelectronika.

....Whichever version was current in year 2010, though I suspect that it may well work with current compiler.

To make it work with Hitech compiler would need a lot of effort.
 
This compiles and runs on Hi-Tech and XC8

I only renamed your C file for my purposes.. You still need to insert a config command ( I have just modified the default in MPLAB IDE.

One other thing.... I forgot to change the short to unsigned char... You;ll need to do this as HTC sees a short as an int.... Thus the code doesn't swap from F to C
 

Attachments

  • 1wire.c
    7.9 KB · Views: 381
  • 1wire.h
    918 bytes · Views: 239
  • seven.c
    3.7 KB · Views: 247
Last edited:
@Ian Rogers

Hey, I like the idea that you have alternative libraries to the closed-source mikroC libraries.

And nice that you are willing to share. :) Thanks.

If only MPLAB was a bit more user-friendly (and frankly - not in such a mess) - I might be tempted to switch back to Microchip tools.
 
I just alter the ones I need.... Most libraries I write myself.

Just another observation..... I do wish that Hitech was more high level, however, I think it's better for me that they are not.... It's far more efficient to write all the low level stuff yourself.... You gain far more knowledge and can then modify to suit non standard code..

Ie... SPI is a pretty robust interface.... but!!! There are sooo many applications that stray "slightly" from the norm... If you have the source, you can do something...
 
Last edited:
Gentlemen I do appreciate your help and patience. I see I have alot to learn regarding micro controllers and programming. I try this out tonight or tomorrow and let you guys know what happens.
 
...One other thing.... I forgot to change the short to unsigned char... You;ll need to do this as HTC sees a short as an int.... Thus the code doesn't swap from F to C

In which file, seven.c?

Does either 1wire.c or 1wire.h need to be renamed as a .lib file?
 
In which file, seven.c?
Yes! seven.c

Does either 1wire.c or 1wire.h need to be renamed as a .lib file?

No! but you need to include 1wire.c into your build.. If you have never compiled more than one C file, you need to make sure the compiler sees it before you compile.

If you are using MPLAB IDE then in the project ( I'm assuming you created a project ) add the file to the source list.

If this is going over your head, and you don't know what I'm talking about, then let me know and I'll do you a little walkthrough....
 
Never compiled a C file at all. On top of that, I don't know much about C or machine language. I've had some experience with basic 20 something years ago but that's all. Makes me wish I kept down the electrical engineering path in college but life gets in the way sometimes.

Ok, that's what I thought and tried. I am using MPLAB IDE. I started a new project, I added the 3 text files (1wire.c, 1wire.h, and seven.c) to the project. Then 1 at a time I opened a blank page, copy and pasted the text of each and saved them as 1wire.c, 1wire.h, and renamed seven.c to thermometer.c. I then added each to the project and put them in the appropriate folders, thermometer.c and 1wire.c both went in the source folder and 1wire.h went in the header folder. I also changed the code of thermometer.c to this:

Code:
/* Project name:
     Seven-segment display digital thermometer
 * Copyright:
     (c) Rajendra Bhatt, 2010.
      MCU:             PIC16F628A
     Oscillator:      XT, 4.0 MHz
*/
#include<htc.h>
#include "1wire.h"
#define _XTAL_FREQ 4000000	 // Xtal speed
#define abs(N) ( (N) >= 0 ? (N) : -(N) ) 
// Temperature digits
unsigned short i, DD0=0x3f, DD1=0x3f,DD2=0x3f, CF_Flag=0xff, CF=0x3f, N_Flag;
// CF_Flag = 0: F, 1: C
// Variable to store temperature register value
int temp_value=0;
float temp_F;
 
//-------------- Function to Return mask for common cathode 7-seg. display
unsigned short mask(unsigned short num) {
  switch (num) {
    case 0 : return 0x3F;
    case 1 : return 0x06;
    case 2 : return 0x5B;
    case 3 : return 0x4F;
    case 4 : return 0x66;
    case 5 : return 0x6D;
    case 6 : return 0x7D;
    case 7 : return 0x07;
    case 8 : return 0x7F;
    case 9 : return 0x6F;
    case 10 : return 0x40;  // Symbol '-'
    case 11 : return 0x39;   // Symbol C
    case 12 : return 0x71;   // Symbol F
    case 13 : return 0x00;  // Blank
  	} //case end
	return 0;
}
 
void display_temp(unsigned char DD0, unsigned char DD1, unsigned char DD2, short CF)    {
    for (i = 0; i<=200; i++) {
      PORTB = DD0;
      RA0 = 1;          // Select Ones Digit
      RA1 = 0;
      RA2 = 0;
      RA3 = 0;
      __delay_ms(5);
      PORTB = DD1;
      RA0 = 0;
      RA1 = 1;        // Select Tens Digit
      RA2 = 0;
      RA3 = 0;
      __delay_ms(5);
      PORTB = DD2;
      RA0 = 0;
      RA1 = 0;
      RA2 = 1;        // Select +/- Digit
      RA3 = 0;
      __delay_ms(5);
      PORTB = CF;
      RA0 = 0;
      RA1 = 0;
      RA2 = 0 ;
      RA3 = 1;        // Select CF Digit
      __delay_ms(5);
        }
     return;
}
 
 
void main() {
  CMCON  |= 7;      // Disable Comparators
  TRISB = 0x00;    // Set PORTB direction to be output
  PORTB = 0x00;    // Turn OFF LEDs on PORTB
  TRISA0 = 0;  // RA.0 to RA3 Output
  TRISA1 = 0;
  TRISA2 = 0;
  TRISA3 = 0;
 
 
    //--- main loop
  do {
 
    N_Flag = 0;  // Reset Temp Flag
    //--- perform temperature reading
    OW_reset_pulse();      // Onewire reset signal
    OW_write_byte(0xCC);   // Issue command SKIP_ROM
    OW_write_byte(0x44);   // Issue command CONVERT_T
    display_temp(DD0, DD1, DD2,CF)   ;
    OW_reset_pulse();
    OW_write_byte(0xCC);    // Issue command SKIP_ROM
    OW_write_byte(0xBE);    // Issue command READ_SCRATCHPAD
 
    // Next Read Temperature
    // Read Byte 0 from Scratchpad
    temp_value =  OW_read_byte();
    // Then read Byte 1 from Scratchpad and shift 8 bit left and add the Byte 0
    temp_value = (OW_read_byte() << 8) + temp_value;
 
    if (temp_value & 0x8000) {
     temp_value = ~temp_value + 1;
     N_Flag = 1;   // Temp is -ive
     }
    if (temp_value & 0x0001) temp_value += 1;   // 0.5 round to 1
    temp_value = temp_value >> 1 ;
    if (CF_Flag == 0) {
     if (N_Flag ==1) {
      temp_F = (32.0-9.0*temp_value/5.0)*10 + 6;
      if (temp_F < 0){
         N_Flag=1;
         temp_value = abs(temp_value);
         }
         else N_Flag = 0;
      }
    else temp_F = (9.0*temp_value/5.0+32.0)*10 + 6; //If decimal is greater or equal
                                             // to 0.5, add 0.5
    temp_value = (int)(temp_F/10);
    CF = 12;
    }
 
    if (CF_Flag == 0xff) CF = 11;
 
    DD0 = temp_value%10;  // Extract Ones Digit
    DD0 = mask(DD0);
    DD1 = (temp_value/10)%10; // Extract Tens Digit
    DD1 = mask(DD1);
    DD2 =  temp_value/100; // Extract Hundred digit
    CF = mask(CF);
    if (N_Flag == 1) DD2=10;
    else if (DD2 == 0) DD2 = 13 ;
    DD2 = mask(DD2) ;
 
      PORTB=0x00;
      CF_Flag =~CF_Flag;
 
    } while (1);
}

Hopefully I changed the "short" to "unsigned char" in all the correct places. I didn't edit the config yet, trying to get it to assemble properly first.

If I've I done everything correctly I still get errors, though they're different than last time,

Code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\thermometer.p1".
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\1wire.p1".
Clean Warning: File "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.cof" doesn't exist.
Clean Warning: File "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.hex" doesn't exist.
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.sym".
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.map".
Clean Warning: File "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.hxl" doesn't exist.
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\startup.lst".
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\startup.rlf".
Clean Warning: File "C:\PK2 Lessons\LPC Demo Board\Thermometer\doprnt.p1" doesn't exist.
Clean Warning: File "C:\PK2 Lessons\LPC Demo Board\Thermometer\doprnt.pre" doesn't exist.
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.obj".
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.lst".
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.rlf".
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.sdb".
Clean: Deleted file "C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer.mcs".
Clean: Done.
Build C:\PK2 Lessons\LPC Demo Board\Thermometer\Thermometer for device 16F628A
Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe

Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 "C:\PK2 Lessons\LPC Demo Board\Thermometer\thermometer.c" -q --chip=16F628A -P --runtime=default --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 "C:\PK2 Lessons\LPC Demo Board\Thermometer\1wire.c" -q --chip=16F628A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" -oThermometer.cof -mThermometer.map --summary=default --output=default thermometer.p1 1wire.p1 --chip=16F628A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error   [1347] ; 0. can't find 0x61 words (0x61 withtotal) for psect "text444" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x26 words (0x26 withtotal) for psect "text437" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x22 words (0x22 withtotal) for psect "text435" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x1D words (0x1d withtotal) for psect "cinit" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x1C words (0x1c withtotal) for psect "text442" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x1B words (0x1b withtotal) for psect "text436" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x17 words (0x17 withtotal) for psect "text443" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x15 words (0x15 withtotal) for psect "text441" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x13 words (0x13 withtotal) for psect "text451" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0xE words (0xe withtotal) for psect "swtext1" in class "CONST" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0xC words (0xc withtotal) for psect "text447" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0xA words (0xa withtotal) for psect "idataBANK0" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x7 words (0x7 withtotal) for psect "text452" in class "CODE" (largest unused contiguous range 0x0)
Error   [1347] ; 0. can't find 0x7 words (0x7 withtotal) for psect "text453" in class "CODE" (largest unused contiguous range 0x0)

********** Build failed! **********

Here's my workspace,

screencap01.JPG
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top