Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16f877a programming error in HITECHC

Status
Not open for further replies.

7ezhil7

Junior Member level 2
Joined
Mar 31, 2016
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
214
Hello,
I am a beginner in Embedded programming. I am doing a project to measure temperature,humidity,wind speed and produce a high output with respect to measured values.I need to measure temperatures from two different areas using sensors placed at different port pins.I need the code reused for both sensors.I tried a code which contains a lot of errors.So please help to correct my code as soon as possible.Thanks in advance.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include<htc.h> 
 
 
void ReadData()
{
 for(int b=0;b<8;b++)
{int i;
 while(!PORTE);                          //Wait until PORTE.Fx goes HIGH
Delay_us(30);
 if(PORTE == 0)  
  i&=~(1<<(7-b));   `        //Clear bit (7-b)
else
{i|= (1<<(7-b));                     //Set bit (7-b)
 while(PORTE);}              //Wait until PORTE.Fx goes LOW
 }
 
 
void main() 
{
unsigned char a = 0;
unsigned char b = 0;
unsigned char i = 0;
int t1[1] = 0;
int t2 = 0;
int rh1[1] = 0;
int rh2 = 0;
unsigned char sum = 0;
unsigned char v=0;
unsigned char u=0;
 TRISA=00000110;
 CMCON=0x02;
 TRISC=0;
 PORTC=0;
v=0b110;t=0;
temp(v);
 v=v<<1;        //left shift zero to next bit(next sensor)
t=1;
temp(v);
 tempdiff=t1[0]-t1[1];
windspeed();
if (ws>383)                     //needed condition
    {PORTC=0;}
else
if(tempdiff<8 && (25<rh1[0]<80))
    {PORTC=1;}
while(show)
{ text = "Temp Diff:";
      Lcd_Out(1,1,text);
      text = "ExH:";
      Lcd_Out(2,1,text);
      text = "WS:";
      Lcd_Out(2,9,text);
      text=tempdiff"C";
      Lcd_Out(1,11,text);
      text=rh1[0]"%";
      Lcd_Out(2,5,text);
      text=ws"m/s";
      Lcd_Out(2,12,text);
    }
 
}
 
    
   temp(int u)        
{                   //start signal
 TRISE = u;    //Configure RB2 as output
 PORTE = 0;    //RB2 senBs 0 to the sensor
 Delay_ms(18);
 PORTE = 1;    //RB2 senBs 1 to the sensor
 Delay_us(30);
 TRISE =~u;    //Configure RB2 as input
 
                          // CheckResponse
int a = 0;
 Delay_us(40);
 if (PORTE == 0)
{
 Delay_us(80);
 if (PORTE == 1)  
 a = 1;  
 Delay_us(40);
}
 
  if(a == 1)
{
  ReadData();
  rh1[t]=i;
  ReadData();
  rh2 =i;
  ReadData();
  t1[t] =i;
  ReadData();
  t2 =i;
  ReadData();
  sum = i;
 
if(sum == rh1[t]+rh2+t1[t]+t2 )
       {  }                           //check sum and do nothing if correct.
 
else
{
 Lcd_Cmd(_Lcd_CURSOR_OFF);        // cursor off
  Lcd_Cmd(_Lcd_CLEAR);             // clear Lcd
  text = "Check sum error";
  Lcd_Out(1,1,text);
main();
}
  }
  else { 
  Delay_ms(2000);
main();
  }
windspeed()             //wind speed 
{ 
T1CON=0b00110100;
  TMR1IE=1;
 TMR1IF=0;
   INTCON=0b11000000;
   TMR1H=0x0B;
   TMR1L=0xDC;
T1CON=0b00110101;
CIS=1 ;   //CMCON<3>
while(TMR1IF=0)
{
if (C2OUT=1)         //measuring wind speed for 0.5 second.
{     
 ws=ws+1; 
}
}
ws=ws*2;   //calculating wind speed  for a second
}
}

 
Last edited by a moderator:

What sensors are you using ? You are using my LCD library. Post the complete LCD library. What are the distances between each sensor and PIC ?
 

show your schematic and error details.
you are using HI-TECH compiler while your code is of MikroC I wonder!!!!!!
 

His
Code:
Delay_us()
function looks like mikroC Code. maybe he has used mikroC Code in Hi-Tech PICC Compiler.
 

Thanks for your reply. DHT11 temperature sensor module.Two temperature sensors at adjacent pins.Yes I am using LCD library..how to post the LCD library?
 

The mikroC Code (My LCD Library) uses sbit defines for LCD and they have to be replaced by #defines. I have not used Hi-Tech PICC Compiler for a while and so don't remember whether it has

Code:
Delay_us()
Delay_ms()

functions.

If it doesn't have then you have to make precise Delay routines for LCD and other things.

Please zip and post the complete Hi-Tech PIC C project so that it can be checked thoroughly. Only then we can answer more about what changes the mikroC code needs to work in Hi-Tech PICC Compiler.
 

Thanks for your reply.I have corrected those mistakes that you specified.Still lots of errors prevails.I have tried to pass binary mask bit as argument(TEMP(v)).I think it needs some datatype conversion.I dont know such conversions.So please help..
corrected code:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include<htc.h> 
#define _XTAL_FREQ 8000000
#define RS RB0
#define EN RB2
#define D0 RD0
#define D1 RD1
#define D2 RD2
#define D3 RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
 
void ReadData()
{
 for(int b=0;b<8;b++)
{int i;
 while(!PORTE);                          //Wait until PORTE.Fx goes HIGH
__delay_us(30);
 if(PORTE == 0)  
  i&=~(1<<(7-b));   `        //Clear bit (7-b)
else
{i|= (1<<(7-b));                     //Set bit (7-b)
 while(PORTE);}              //Wait until PORTE.Fx goes LOW
 }
 
 
void main() 
{unsigned char a = 0;
unsigned char b = 0;
unsigned char i = 0;
int t1[3] ;
int t2;
int rh1[3] ;
int rh2 = 0;
int tempdiff;
unsigned char sum = 0;
unsigned char v=0;
unsigned char u=0;
unsigned char text;
int ws,show,t,tempdiff;
 TRISA=00000110;
 CMCON=0x02;
 TRISC=0;
 PORTC=0;
v=0b110;t=0;
temp(v);
 v=v<<1;        //left shift zero to next bit
t=1;
temp(v);
 tempdiff=t1[0]-t1[1];
windspeed();
if (ws>383)                     //needed condition
    {PORTC=0;}
else
if(tempdiff<8 && (25<rh1[0]<80))
    {PORTC=1;}
while(show)
{ text = "Temp Diff:";
      Lcd_Out(1,1,text);
      text = "ExH:";
      Lcd_Out(2,1,text);
      text = "WS:";
      Lcd_Out(2,9,text);
      text=tempdiff"C";
      Lcd_Out(1,11,text);
      text=rh1[0]"%";
      Lcd_Out(2,5,text);
      text=ws"m/s";
      Lcd_Out(2,12,text);
    }
 
}
 
    
   temp(int u)        
{                   //start signal
 TRISE = u;    //Configure RB2 as output
 PORTE = 0;    //RB2 senBs 0 to the sensor
 __delay_ms(18);
 PORTE = 1;    //RB2 senBs 1 to the sensor
 __delay_us(30);
 TRISE =~u;    //Configure RB2 as input
 
                          // CheckResponse
int a = 0;
 __delay_us(40);
 if (PORTE == 0)
{
 __delay_us(80);
 if (PORTE == 1)  
 a = 1;  
 __delay_us(40);
}
 
  if(a == 1)
{
  ReadData();
  rh1[t]=i;
  ReadData();
  rh2 =i;
  ReadData();
  t1[t] =i;
  ReadData();
  t2 =i;
  ReadData();
  sum = i;
 
if(sum == rh1[t]+rh2+t1[t]+t2 )
       {  }
 
else
{
 Lcd_Cmd(_Lcd_CURSOR_OFF);        // cursor off
  Lcd_Cmd(_Lcd_CLEAR);             // clear Lcd
  text = "Check sum error";
  Lcd_Out(1,1,text);
main();
}
  }
  else { 
  __delay_ms(2000);
main();
  }
windspeed()             //wind speed 
{ 
T1CON=0b00110100;
  TMR1IE=1;
 TMR1IF=0;
   INTCON=0b11000000;
   TMR1H=0x0B;
   TMR1L=0xDC;
T1CON=0b00110101;
CIS=1 ;   //CMCON<3>
while(TMR1IF=0)
{
if (C2OUT=1)
{     
 ws=ws+1; 
}
}
ws=ws*2;
}
}



Errors:
Build C:\Users\Lenovo\Documents\dht111 for device 16F877A
Using driver C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe

Make: The target "C:\Users\Lenovo\Documents\dht111.p1" is out of date.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Lenovo\Documents\dht111.c -q --chip=16F877A -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"
Warning [228] C:\Users\Lenovo\Documents\dht111.c; 21.17 illegal character (0x60)
Error [314] C:\Users\Lenovo\Documents\dht111.c; 29.1 ";" expected
Warning [361] C:\Users\Lenovo\Documents\dht111.c; 47.1 function declared implicit int
Warning [361] C:\Users\Lenovo\Documents\dht111.c; 52.1 function declared implicit int
Warning [358] C:\Users\Lenovo\Documents\dht111.c; 59.22 illegal conversion of pointer to integer
Warning [361] C:\Users\Lenovo\Documents\dht111.c; 60.1 function declared implicit int
Warning [358] C:\Users\Lenovo\Documents\dht111.c; 61.14 illegal conversion of pointer to integer
Warning [358] C:\Users\Lenovo\Documents\dht111.c; 63.13 illegal conversion of pointer to integer
Error [195] C:\Users\Lenovo\Documents\dht111.c; 65.14 expression syntax
Error [195] C:\Users\Lenovo\Documents\dht111.c; 67.12 expression syntax
Error [195] C:\Users\Lenovo\Documents\dht111.c; 69.8 expression syntax
Error [987] C:\Users\Lenovo\Documents\dht111.c; 77.1 arguments redeclared
Error [1098] C:\Users\Lenovo\Documents\dht111.c; 77.1 conflicting declarations for variable "temp" (C:\Users\Lenovo\Documents\dht111.c:47)
Error [192] C:\Users\Lenovo\Documents\dht111.c; 99.1 undefined identifier "rh1"
Error [192] C:\Users\Lenovo\Documents\dht111.c; 99.5 undefined identifier "t"
Error [981] C:\Users\Lenovo\Documents\dht111.c; 99.7 pointer required
Error [981] C:\Users\Lenovo\Documents\dht111.c; 99.7 pointer required
Error [192] C:\Users\Lenovo\Documents\dht111.c; 99.8 undefined identifier "i"
Error [192] C:\Users\Lenovo\Documents\dht111.c; 101.1 undefined identifier "rh2"
Error [192] C:\Users\Lenovo\Documents\dht111.c; 103.1 undefined identifier "t1"
Error [981] C:\Users\Lenovo\Documents\dht111.c; 103.7 pointer required
Error [981] C:\Users\Lenovo\Documents\dht111.c; 103.7 pointer required
Error [192] C:\Users\Lenovo\Documents\dht111.c; 105.1 undefined identifier "t2"
Error [192] C:\Users\Lenovo\Documents\dht111.c; 107.1 undefined identifier "sum"
Error [981] C:\Users\Lenovo\Documents\dht111.c; 109.17 pointer required
Error [981] C:\Users\Lenovo\Documents\dht111.c; 109.17 pointer required
Error [981] C:\Users\Lenovo\Documents\dht111.c; 109.27 pointer required
Error [981] C:\Users\Lenovo\Documents\dht111.c; 109.27 pointer required
Advisory[1] too many errors (21)

********** Build failed! **********
 
Last edited by a moderator:

Work on one thing at a time. You need to display temperature, humidity values on LCD and so first get the LCD code working. After that make DHT11 library and then test its working. Without LCD you can't test working of DHT11 code. I asked you to zip and post the complete MPLAB Hi_Tech PICC project. Also mention which version of MPLAB and Hi-Tech PICC you are using. Did you check whether Hi-Tech PIC has
Code:
Delay_us() and Delay_ms()
functions ?

My LCD library is for 4 bit. It uses 6 pins of LCD and PIC namely Rs, En, D4, D5, D6 and D7. Why are you making it 8 bit ?

What is the Crystal frequency you are using ?
 

seriously you are still using Mikroc LCD library. It will not work on Hitech.
Either write your own library for Hitech or use Mirkoc instead.
 

I have corrected those mistakes that you specified.Still lots of errors prevails

I note that your are using a variable text that was not previously declared. Furthermore, I'm not sure if you can assign a value to it without using some String library proper for managing variable arrays like that.
 

Code:
unsigned char text
is declared in
Code:
void main() {...}
but it is a char type variable but used with
Code:
LCD_Out()
which expects a string variable.
 

It could be the way the code is presented in the OP but it looks as though the 'ReadData()' function is missing a closing brace which means the 'main' function is being interpreted as part of it.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top