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.

Hi-Tech C, Warning ?

Status
Not open for further replies.

PICMICRO

New Member
Compiling this test code with Hi-tech C
Code:
#include<htc.h>
void main(){
TRISC5 = 0;
unsigned char x;
x = 5;
if(x >= 0){
RC5 = 1;
}
}
issues the following warning
Warning [765] D:\pic experimental\main.c; 7. degenerate unsigned comparison

We well know what the warning means, since x is unsigned, its trivial that x >=0 is always true. But guess what? Its actually error. RC5 isn't set, the statement RC5 = 1; isn't executed at all!
My god, who would have thought like that?
It was part of my bigger program, took my whole day to figure this out.
 
The asm is correct and the simulator executes it correctly.
Code:
1:                 
2:                 #include<htc.h>
3:                 void main(){
4:                 unsigned char x;
5:                     x = 5;
  0003    3005     MOVLW 0x5
  0004    00F0     MOVWF 0x70
6:                 TRISC5 = 0;
  0005    1683     BSF 0x3, 0x5
  0006    1303     BCF 0x3, 0x6
  0007    1287     BCF 0x7, 0x5
7:                     if(x >= 0){
8:                         RC5 = 1;
  0008    1283     BCF 0x3, 0x5
  0009    1303     BCF 0x3, 0x6
  000A    1687     BSF 0x7, 0x5
9:                     }
10:                }
  000B    120A     BCF 0xa, 0x4

Maybe you need to add a while(1) instead of getting to the end of main().

Mike.
 
The asm is correct and the simulator executes it correctly.
Code:
1:                 
2:                 #include<htc.h>
3:                 void main(){
4:                 unsigned char x;
5:                     x = 5;
  0003    3005     MOVLW 0x5
  0004    00F0     MOVWF 0x70
6:                 TRISC5 = 0;
  0005    1683     BSF 0x3, 0x5
  0006    1303     BCF 0x3, 0x6
  0007    1287     BCF 0x7, 0x5
7:                     if(x >= 0){
8:                         RC5 = 1;
  0008    1283     BCF 0x3, 0x5
  0009    1303     BCF 0x3, 0x6
  000A    1687     BSF 0x7, 0x5
9:                     }
10:                }
  000B    120A     BCF 0xa, 0x4

Maybe you need to add a while(1) instead of getting to the end of main().

Mike.

Hi, Pommie,
Which version of compiler did you use?
Also, how do I create the assmebly listing like that. I tried View->Disassmebly Listing from Mplab and got this.
Code:
---  D:\pic experimental\exp.as  -----------------------------------------------------------------
1:                 opt subtitle "HI-TECH Software Omniscient Code Generator (PRO mode) build 5239"
2:                 
3:                 opt pagewidth 120
4:                 
5:                 	opt pm
6:                 
7:                 	processor	16F877A
8:                 clrc	macro
9:                 	bcf	3,0
10:                	endm
11:                clrz	macro
12:                	bcf	3,2
13:                	endm
14:                setc	macro
15:                	bsf	3,0
16:                	endm
17:                setz	macro
18:                	bsf	3,2

........
<REMOVED BECAUSE ITS TOO LONG>
...............................................

608:               psect cinit,class=CODE,delta=2
609:               global end_of_initialization
610:               
611:               ;End of C runtime variable initationation code
612:               
613:               end_of_initialization:
614:               clrf status
  07F5    0183     CLRF 0x3
615:               ljmp _main	;jump to C main() function
  07F6    120A     BCF 0xa, 0x4
  07F7    118A     BCF 0xa, 0x3
  07F8    2FF9     GOTO 0x7f9
---  D:\pic experimental\main.c  -----------------------------------------------------------------
1:                 #include<htc.h>
2:                 
3:                 void main(){
4:                 unsigned char x;
5:                 x = 5;
6:                 TRISC5 = 0;
  07F9    1683     BSF 0x3, 0x5
  07FA    1287     BCF 0x7, 0x5
7:                 if(x >= 1){
8:                 RC5 = 1;
  07FB    1283     BCF 0x3, 0x5
 
I'm using HI-TECH C PRO for the PIC10/12/16 MCU family (Lite) V9.65PL1 with MPLAB v8.40 and just did View->Disassembly.

Mike.
 
I am using HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.70
with mplab 8.66
Seems like issue with my Version
 
Status
Not open for further replies.

Latest threads

Back
Top