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.

[SOLVED] Programming problem for pic16f72

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Visit site
Activity points
8,254
I can not understand what is the problem in this program. Error is the program can not being able to justify any portion of these conditions. I used "mikroC pro for pic".



unsigned char ch; //
unsigned int adc_rd; // Declare variables
long tlong;
void main()
{
TRISA = 0x3F; // setting AD0 for input
TRISB = 0x00; // setting port B as output.
TRISC = 0b11000000; // selecting port c as output
ADCON0=0x01;
ADCON1=0x00;
loop:

RC0_bit = 1; // delay indicator on
RC1_bit = 0; // mains indicator off
RC5_bit = 0; // Output relay off

/*................................................................................
Delay mode selection for user friendly...
.................................................................................*/

if(RC6_bit = 0)
{
Delay_ms(5000);
}
else
{
Delay_ms(1000);
}

/* ...............................................................................
Main working starts here
..................................................................................*/
RC0_bit = 0; // delay indicator off.
while(1)
{
adc_rd = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 255; // 0..1023 -> 0-5000mV
ch = tlong / 1000; // Extract volts (thousands of millivolts)

/*................................................................................
Main stabilizing is done here
.................................................................................*/

if((ch<=1.9)&&(ch>=1.30))
{
if(ch>1.33)
{
PORTB =0b11111111;
}
if(ch>1.40)
{
PORTB =0b01111111;
}
if(ch>1.48)
{
PORTB =0b00111111;
}
if(ch>1.56)
{
PORTB =0b00011111;
}
if(ch>1.63)
{
PORTB =0b00001111;
}
if(ch>1.704)
{
PORTB =0b00000111;
}
if(ch>1.78)
{
PORTB =0b00000011;
}
if(ch>1.85)
{
PORTB =0b00000001;
}
RC5_bit = 1; // output relay on.
RC1_bit = 1; // mains indicator on
RC3_bit = 1; // normal indicator on.
RC4_bit = 0; // high voltage indicator off
RC2_bit = 0; // low voltage indicator off
}


/*................................................................................
High voltage protection for load is done here
.................................................................................*/
if(ch > 2.10)
{
RC4_bit = 1; // high voltage indicator on
RC2_bit = 0; // low voltage indicator off
RC5_bit = 0; // relay off
RC1_bit = 0; // Mains normal indicator off
RC3_bit = 0; // normal indicator off.
PORTB = 0x00;
goto loop;
}
/*................................................................................
Low voltage protection is done here
.................................................................................*/

if(ch <= 1.30)
{
RC2_bit = 1; // low voltage indicator on
RC5_bit = 0; // O/P relay off
RC3_bit = 0; // Mains normal indicator off
RC4_bit = 0; // high indicator on.
RC1_bit = 0; // Mains normal indicator off
PORTB = 0x00;
goto loop;
}


}

}
 

One of your problems is this statement:


Code C - [expand]
1
if(RC6_bit = 0)



The statement, instead of testing if RC6_bit is equal to 0 or clear, always clears RC6_bit which is always false.

This is probably what you intended:


Code C - [expand]
1
if(RC6_bit == 0)



or simply:


Code C - [expand]
1
if(!RC6_bit)



I just glanced at the program, there maybe other errors.

---------- Post added at 09:48 ---------- Previous post was at 09:38 ----------

Here are additional problems:


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
...
...
[COLOR="#FF0000"]unsigned char ch;[/COLOR]
 
...
...
 
if(([COLOR="#FF0000"]ch<=1.9[/COLOR])&&([COLOR="#FF0000"]ch>=1.30[/COLOR]))
{
if([COLOR="#FF0000"]ch>1.33[/COLOR])
{
PORTB =0b11111111;
}
if([COLOR="#FF0000"]ch>1.40[/COLOR])
{
PORTB =0b01111111;
}
if([COLOR="#FF0000"]ch>1.48[/COLOR])
{
PORTB =0b00111111;
}
if([COLOR="#FF0000"]ch>1.56[/COLOR])
{
PORTB =0b00011111;
}
if([COLOR="#FF0000"]ch>1.63[/COLOR])
{
PORTB =0b00001111;
}
if([COLOR="#FF0000"]ch>1.704[/COLOR])
{
PORTB =0b00000111;
}
if([COLOR="#FF0000"]ch>1.78[/COLOR])
{
PORTB =0b00000011;
}
if([COLOR="#FF0000"]ch>1.85[/COLOR])
{
PORTB =0b00000001;
}
RC5_bit = 1; // output relay on.
RC1_bit = 1; // mains indicator on
RC3_bit = 1; // normal indicator on.
RC4_bit = 0; // high voltage indicator off
RC2_bit = 0; // low voltage indicator off
}
 
 
/*................................................. ...............................
High voltage protection for load is done here
.................................................. ...............................*/
if([COLOR="#FF0000"]ch > 2.10[/COLOR])
{
RC4_bit = 1; // high voltage indicator on
RC2_bit = 0; // low voltage indicator off
RC5_bit = 0; // relay off
RC1_bit = 0; // Mains normal indicator off
RC3_bit = 0; // normal indicator off.
PORTB = 0x00;
goto loop;
}
/*................................................. ...............................
Low voltage protection is done here
.................................................. ...............................*/
 
if([COLOR="#FF0000"]ch <= 1.30[/COLOR])
 
...
...



The variable "ch" is declared as a type "unsigned char," however you are testing "ch" against type "float" literal.
The "ch" may have values ranging from 0 to 255, due to the fact it is an unsigned 8-bit value, this is a type mismatch.
 

if(RC6_bit = 0) this logic is working fine. but I changed unsigned char ch into unsigned int char as unsigned float ch shows error in my compiler. but still the whole program is becoming hanged into the low voltage sensing loop.
 

Hi there!
I believe the main problem is the oder of your "if's" on:
if((ch<=1.9)&&(ch>=1.30))
{
if(ch>1.33)
{
PORTB =0b11111111;
}
if(ch>1.40)
{
PORTB =0b01111111;
}
if(ch>1.48)
{
PORTB =0b00111111;
}
if(ch>1.56)
{
PORTB =0b00011111;
}
if(ch>1.63)
{
PORTB =0b00001111;
}
if(ch>1.704)
{
PORTB =0b00000111;
}
if(ch>1.78)
{
PORTB =0b00000011;
}
if(ch>1.85)
{
PORTB =0b00000001;

...

for instance. If value is 1.86 it'll hit the first (if), cause 1.86 is bigger than 1.33, ok?
My suggestion is to change the order. Start with bigger number (ifs) and go decreasing it.
 

I know it has been two weeks since you have posted this so maybe you have figured this out but I have to say a couple of things

if(RC6_bit = 0) this logic is working fine.

Not if you want to check the value of the variable, you can't use assignment sign (=) to check for value.

but I changed unsigned char ch into unsigned int char as unsigned float ch shows error in my compiler. but still the whole program is becoming hanged into the low voltage sensing loop.

the char, int, float are types, there is no such thing as a float char.
The types that your compiler supports are described in the manual page 168-169

These are the integer types microC_integer_types.gif

and the floating types microC_floating_types.gif

so to declare a float variable you have to use float ch (or double ch which is the same)

cabelyn is also right, when you use an if/else sequence you have to make sure that you use the correct order.

Alex
 
Oh, Im really sorry. I forgot to post. I've already solved that and its working well.
the program is:

float ch; //
unsigned int adc_rd; // Declare variables
long tlong;
void main()
{
TRISA = 0x3F; // setting AD0 for input
TRISB = 0x00; // setting port B as output.
TRISC = 0b11000000; // selecting port c as output
ADCON0=0x01;
ADCON1=0x00;
//PORTB = 0x00;
loop:

RC0_bit = 1; // delay indicator on
RC1_bit = 0; // mains indicator off
RC5_bit = 0; // Output relay off

/*................................................................................
Delay mode selection for user friendly...
.................................................................................*/

if(RC6_bit = 0)
{
Delay_ms(5000);
}
else
{
Delay_ms(100);
}

/* ...............................................................................
Main working starts here
..................................................................................*/
RC0_bit = 0; // delay indicator off.
while(1)
{
adc_rd = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 255; // 0..1023 -> 0-5000mV
ch =(float) tlong / 1000; // Extract volts (thousands of millivolts)

/*................................................................................
Main stabilizing is done here
.................................................................................*/

if((ch<=1.9)&&(ch>=1.30))
{

if(ch>1.33)
{
if(ch>1.40)
{
if(ch>1.48)
{
if(ch>1.56)
{
if(ch>1.63)
{
if(ch>1.704)
{
if(ch>1.78)
{
if(ch>1.85)
{
PORTB =0b00000001;
}
else
PORTB =0b00000011;
}
else
PORTB =0b00000111;
}
else
PORTB =0b00001111;
}
else
PORTB =0b00011111;
}
else
PORTB =0b00111111;
}
else
PORTB =0b01111111;
}
else
PORTB =0b11111111;

}
else
PORTB = 0x00;

RC5_bit = 1; // output relay on.
RC1_bit = 1; // mains indicator on
RC3_bit = 1; // normal indicator on.
RC4_bit = 0; // high voltage indicator off
RC2_bit = 0; // low voltage indicator off
}

/*................................................................................
High voltage protection for load is done here
.................................................................................*/

if(ch > 2.10)
{
RC4_bit = 1; // high voltage indicator on
RC2_bit = 0; // low voltage indicator off
RC5_bit = 0; // relay off
RC1_bit = 0; // Mains normal indicator off
RC3_bit = 0; // normal indicator off.
PORTB = 0x00;
goto loop;
}
/*................................................................................
Low voltage protection is done here
.................................................................................*/

if(ch <= 1.30)
{
RC2_bit = 1; // low voltage indicator on
RC5_bit = 0; // O/P relay off
RC3_bit = 0; // Mains normal indicator off
RC4_bit = 0; // high indicator on.
RC1_bit = 0; // Mains normal indicator off
PORTB = 0x00;
goto loop;
}


}

}


now its all ok.
 

You are complicating your code without a reason, it is not very easy to read this

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
if((ch<=1.9)&&(ch>=1.30))
{
 
    if(ch>1.33)
    {
        if(ch>1.40)
        {
            if(ch>1.48)
            {
                if(ch>1.56)
                {
                    if(ch>1.63)
                    {
                        if(ch>1.704)
                        {
                            if(ch>1.78)
                            {
                                if(ch>1.85)
                                {
                                    PORTB =0b00000001;
                                }
                                else
                                    PORTB =0b00000011;
                            }
                            else
                                PORTB =0b00000111;
                        }
                        else
                            PORTB =0b00001111;
                    }
                    else
                        PORTB =0b00011111;
                }
                else
                    PORTB =0b00111111;
            }
            else
                PORTB =0b01111111;
        }
        else
            PORTB =0b11111111;
 
    }
    else
        PORTB = 0x00;



instead you can simply use

Code C - [expand]
1
2
3
4
5
6
7
8
9
if(ch>1.85) PORTB =0b00000001;
else if(ch>1.78)PORTB =0b00000011;
else if(ch>1.704) PORTB =0b00000111;
else if(ch>1.63) PORTB =0b00001111;
else if(ch>1.56) PORTB =0b00011111;
else if(ch>1.48) PORTB =0b00111111;
else if(ch>1.40) PORTB =0b01111111;
else if(ch>1.33) PORTB =0b11111111;
else PORTB = 0x00;



And I see that you have kept if(RC6_bit = 0)
Why do you keep using that wrong way?
If you want to check for 1 then use if(RC6_bit == 1) or if(RC6_bit)
If you want to check for 0 then use if(RC6_bit == 0) or if(!RC6_bit)

Alex
 

Thanks alex, I wrote in that way you posted but I don't know why it became in a straight line here.

And also thanks for

"If you want to check for 1 then use if(RC6_bit == 1) or if(RC6_bit)
If you want to check for 0 then use if(RC6_bit == 0) or if(!RC6_bit)"

But it is working well.

---------- Post added at 18:05 ---------- Previous post was at 18:02 ----------

instead you can simply use

Code C - [expand]
1
2
3
4
5
6
7
8
9
if(ch>1.85) PORTB =0b00000001;
else if(ch>1.78)PORTB =0b00000011;
else if(ch>1.704) PORTB =0b00000111;
else if(ch>1.63) PORTB =0b00001111;
else if(ch>1.56) PORTB =0b00011111;
else if(ch>1.48) PORTB =0b00111111;
else if(ch>1.40) PORTB =0b01111111;
else if(ch>1.33) PORTB =0b11111111;
else PORTB = 0x00;




its a nice way.
 

Thanks alex, I wrote in that way you posted but I don't know why it became in a straight line here.

I was referring to the actual code not the formating, for example to see the value that will be assigned when (ch>1.40) you have to scroll 30 lined down...

And also thanks for

"If you want to check for 1 then use if(RC6_bit == 1) or if(RC6_bit)
If you want to check for 0 then use if(RC6_bit == 0) or if(!RC6_bit)"

But it is working well.

You have to understand that if(RC6_bit = 0) actually means "assign 0 to RC6_bit and then check if RC6_bit has a non 0 value", as you can understand this will always be false because it is equivalent to if(0) so the part below

if(RC6_bit = 0)
{
Delay_ms(5000);
}
else
{
Delay_ms(100);
}


can actually be replaced by Delay_ms(100);

You will not find any code example, or bundle or project that uses "=" inside an if condition and you will actually get a warning from the complier when you use it this way.

Alex
 

i give u a sugestion , for Delay mode selection for user friendly... use 10k preset any free ADC port for time delay like sch.....
 

I think you wrote a program for a voltage stabilizer. So, the options for delay selection are 100ms and 5 seconds. The commercial voltage stabilizers have a switch with selectable options for 5-10 seconds and 5-10 minutes.
 
  • Like
Reactions: a.t.r

    a.t.r

    Points: 2
    Helpful Answer Positive Rating
as per my sugestion .we can set time delay selectable options as 3 sec to 10 minutes.
i am right or wrong ?

---------- Post added at 01:02 ---------- Previous post was at 00:59 ----------

I think you wrote a program for a voltage stabilizer. So, the options for delay selection are 100ms and 5 seconds. The commercial voltage stabilizers have a switch with selectable options for 5-10 seconds and 5-10 minutes.
above code not work as voltage stabilizer on OSHON SOFT SIMULATOR .
 

Re: pic16f72 to pic16f676 convestion Programming problem

What's problem with my code which I some change mitun_k_das code's .i am using 16f676

Code:
float ch; //
unsigned int adc_rd; // Declare variables
long tlong;

// Define relay selection port pins
sbit RL1 at RA1_bit; ********//PIN 12
sbit RL2 at RC0_bit; ********//PIN 10
sbit RL3 at RC1_bit; ********//PIN 09
sbit RL4 at RC2_bit; ********//PIN 08
sbit RL5 at RA2_bit; ********//PIN 11

// Define LED/ bzr selection port pins
sbit L1 at *Rc5_bit; ********//PIN 05 hi\lo cut
sbit L2 at *Rc4_bit; ********//PIN 06 mains normal
sbit BZR at Rc3_bit; ********//PIN 07 SOUND

// Define LED/ bzr selection port pins
sbit SW1 at *RA5_bit; ********//PIN 03 hi\lo cut enabol
sbit SW2 at *RA4_bit; ********//PIN 02 QEK SATART


void main()
{
//ANSEL = 0x01; *// RA0 analog input

TRISA = 0x39; // setting RA0 analog input & RA3 -RA5 digital i\p
TRISC = 0x00; // setting port C as output.

*// Configure ADCON0 for channel AN0
**ADCON0.CHS0 = 0;
**ADCON0.CHS1 = 0;
**ADCON0.CHS2 = 0;
**ADCON0=0x01;
*// Configure ADCON1
**ADCON1=0x00;

loop:

L2 = 1; ****// mains normal on
L1 = 0; ****// hi\lo cut off
BZR = 0;****// SOUND off
RL4 = 0;****// Output relay off R4

/*................................................. ...............................
Delay mode selection for user friendly...
.................................................. ...............................*/

if(SW2 == 0)
{
Delay_ms(5);
}
else
{
Delay_ms(1);
}

/* .................................................. .............................
Main working starts here
.................................................. ................................*/
L1 = 0; // delay indicator off.
while(1)
{
adc_rd = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 255; // 0..1023 -> 0-5000mV
ch =(float) tlong / 1000; // Extract volts (thousands of millivolts)

/*................................................. ...............................
Main stabilizing is done here
.................................................. ...............................*/

if((ch<=1.9)&&(ch>=1.40))
**{
**
** if(ch>1.85)
** {
** *if(ch>1.78)
** *{
** * if(ch>1.704)
** * {
** * *if(ch>1.63)
** * *{
** * * if(ch>1.56)
** * * {
** * * if(ch>1.48)
** * * {
** * * *//if(ch>1.40)
** * * *//{
** * * * RL5 = 1;
** * * * RL3 = 1;
** * * * RL2 = 1;
** * * * RL1 = 1; ************//STP7
** * * *}
** * * *else
** * * *RL5 = 1;
** * * *RL2 = 1;
** * * *RL1 = 1;
** * * *RL3 = 0;********//STP6
** * * }
** * * else
** * * *RL3 = 1;
** * * *RL2 = 1;
** * * *RL1 = 1;
** * * *RL5 = 0;****//STP5
** * *}
** * * *else
** * * *RL2 = 1;
** * * *RL1 = 1;
** * * *RL5 = 0;
** * * *RL3 = 0;********//STP4
** * }
** * *else
** * * RL3 = 1;
** * * RL1 = 1;
** * * RL5 = 0;
** * * RL2 = 0;********//STP3
** *}
** * *else
** * * RL1 = 1;
** * * RL3 = 0;
** * * RL5 = 0;
** * * RL2 = 0;********//STP2
** }
** * *else
** * *RL3 = 1;
** * *RL1 = 0;
** * *RL5 = 0;
** * *RL2 = 0;********//STP1
**}
** * *else
** * RL5 = 0;
** * RL3 = 0;
** * RL2 = 0;
** * RL1 = 0;

** * RL4 = 1; // output relay on.
** * L2 = 1; // mains indicator on
** * L1 = 0; // high //low voltage indicator off
** * BZR = 0; // high //low voltage indicator off

** * * * * * * * * * * * * }

/*................................................. ...............................
High voltage protection for load is done here
.................................................. ...............................*/

if(ch > 2.10)
{
L1 = 1; // high // low voltage indicator on
BZR = 1; // cret sound
RL4 = 0; // relay off
L2 = 0; // Mains normal indicator off
goto loop;
}
/*................................................. ...............................
Low voltage protection is done here
.................................................. ...............................*/

if((ch <= 1.30) && (SW1=0))
{
L1 = 1; // high // low voltage indicator on
BZR = 1; // cret sound
RL4 = 0; // relay off
L2 = 0; // Mains normal indicator off
goto loop;
}

** * * * * * * * *}


}

mikroC Compilers show ' Internal error '

pl clear me where i wrong ?
 

i got Internal error
now find new error . like ..


error: 102 342 There is not enough ROM space __Lib_MathDouble.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 22 392 Address must be greater than 0 main MyProject.c
error: 1091 392 Address must be greater than 0 Div_32x32_S __Lib_Math.c
error: 1091 392 Address must be greater than 0 Div_32x32_S __Lib_Math.c
error: 49 392 Address must be greater than 0 ADC_Read __Lib_ADC_A_B.c
error: 1903 392 Address must be greater than 0 Longint2Double __Lib_MathDouble.c
error: 24 392 Address must be greater than 0 __CC2DW __Lib_System.c
error: 761 392 Address must be greater than 0 Div_32x32_FP __Lib_MathDouble.c
error: 761 392 Address must be greater than 0 Div_32x32_FP __Lib_MathDouble.c
error: 761 392 Address must be greater than 0 Div_32x32_FP __Lib_MathDouble.c
error: 761 392 Address must be greater than 0 Div_32x32_FP __Lib_MathDouble.c
error: 245 392 Address must be greater than 0 NRM4032 __Lib_MathDouble.c
error: 245 392 Address must be greater than 0 NRM4032 __Lib_MathDouble.c
error: 245 392 Address must be greater than 0 NRM4032 __Lib_MathDouble.c
error: 245 392 Address must be greater than 0 NRM4032 __Lib_MathDouble.c
error: 0 102 Finished (with errors): 05 Aug 2011, 22:58:28 MyProject.mcppi
 

Re: pic16f72 to pic16f676 convestion Programming problem

What's problem with my code which I some change mitun_k_das code's .i am using 16f676

Code:
float ch; //
unsigned int adc_rd; // Declare variables
long tlong;

// Define relay selection port pins
sbit RL1 at RA1_bit; ********//PIN 12
sbit RL2 at RC0_bit; ********//PIN 10
sbit RL3 at RC1_bit; ********//PIN 09
sbit RL4 at RC2_bit; ********//PIN 08
sbit RL5 at RA2_bit; ********//PIN 11

// Define LED/ bzr selection port pins
sbit L1 at *Rc5_bit; ********//PIN 05 hi\lo cut
sbit L2 at *Rc4_bit; ********//PIN 06 mains normal
sbit BZR at Rc3_bit; ********//PIN 07 SOUND

// Define LED/ bzr selection port pins
sbit SW1 at *RA5_bit; ********//PIN 03 hi\lo cut enabol
sbit SW2 at *RA4_bit; ********//PIN 02 QEK SATART


void main()
{
//ANSEL = 0x01; *// RA0 analog input

TRISA = 0x39; // setting RA0 analog input & RA3 -RA5 digital i\p
TRISC = 0x00; // setting port C as output.

*// Configure ADCON0 for channel AN0
**ADCON0.CHS0 = 0;
**ADCON0.CHS1 = 0;
**ADCON0.CHS2 = 0;
**ADCON0=0x01;
*// Configure ADCON1
**ADCON1=0x00;

loop:

L2 = 1; ****// mains normal on
L1 = 0; ****// hi\lo cut off
BZR = 0;****// SOUND off
RL4 = 0;****// Output relay off R4

/*................................................. ...............................
Delay mode selection for user friendly...
.................................................. ...............................*/

if(SW2 == 0)
{
Delay_ms(5);
}
else
{
Delay_ms(1);
}

/* .................................................. .............................
Main working starts here
.................................................. ................................*/
L1 = 0; // delay indicator off.
while(1)
{
adc_rd = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 255; // 0..1023 -> 0-5000mV
ch =(float) tlong / 1000; // Extract volts (thousands of millivolts)

/*................................................. ...............................
Main stabilizing is done here
.................................................. ...............................*/

if((ch<=1.9)&&(ch>=1.40))
**{
**
** if(ch>1.85)
** {
** *if(ch>1.78)
** *{
** * if(ch>1.704)
** * {
** * *if(ch>1.63)
** * *{
** * * if(ch>1.56)
** * * {
** * * if(ch>1.48)
** * * {
** * * *//if(ch>1.40)
** * * *//{
** * * * RL5 = 1;
** * * * RL3 = 1;
** * * * RL2 = 1;
** * * * RL1 = 1; ************//STP7
** * * *}
** * * *else
** * * *RL5 = 1;
** * * *RL2 = 1;
** * * *RL1 = 1;
** * * *RL3 = 0;********//STP6
** * * }
** * * else
** * * *RL3 = 1;
** * * *RL2 = 1;
** * * *RL1 = 1;
** * * *RL5 = 0;****//STP5
** * *}
** * * *else
** * * *RL2 = 1;
** * * *RL1 = 1;
** * * *RL5 = 0;
** * * *RL3 = 0;********//STP4
** * }
** * *else
** * * RL3 = 1;
** * * RL1 = 1;
** * * RL5 = 0;
** * * RL2 = 0;********//STP3
** *}
** * *else
** * * RL1 = 1;
** * * RL3 = 0;
** * * RL5 = 0;
** * * RL2 = 0;********//STP2
** }
** * *else
** * *RL3 = 1;
** * *RL1 = 0;
** * *RL5 = 0;
** * *RL2 = 0;********//STP1
**}
** * *else
** * RL5 = 0;
** * RL3 = 0;
** * RL2 = 0;
** * RL1 = 0;

** * RL4 = 1; // output relay on.
** * L2 = 1; // mains indicator on
** * L1 = 0; // high //low voltage indicator off
** * BZR = 0; // high //low voltage indicator off

** * * * * * * * * * * * * }

/*................................................. ...............................
High voltage protection for load is done here
.................................................. ...............................*/

if(ch > 2.10)
{
L1 = 1; // high // low voltage indicator on
BZR = 1; // cret sound
RL4 = 0; // relay off
L2 = 0; // Mains normal indicator off
goto loop;
}
/*................................................. ...............................
Low voltage protection is done here
.................................................. ...............................*/

if((ch <= 1.30) && (SW1=0))
{
L1 = 1; // high // low voltage indicator on
BZR = 1; // cret sound
RL4 = 0; // relay off
L2 = 0; // Mains normal indicator off
goto loop;
}

** * * * * * * * *}


}

mikroC Compilers show ' Internal error '

pl clear me where i wrong ?

One problem is the multiple asterisks in front of the double forward slash:

Code:
// Define relay selection port pins
sbit RL1 at RA1_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 12
sbit RL2 at RC0_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 10
sbit RL3 at RC1_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 09
sbit RL4 at RC2_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 08
sbit RL5 at RA2_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 11

They are not considered to be a comment by the compiler, you should remove them.

There are numerous problems stemming from the over use of asterisks throughout your program.

BigDog
 

Re: pic16f72 to pic16f676 convestion Programming problem

One problem is the multiple asterisks in front of the double forward slash:

Code:
// Define relay selection port pins
sbit RL1 at RA1_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 12
sbit RL2 at RC0_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 10
sbit RL3 at RC1_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 09
sbit RL4 at RC2_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 08
sbit RL5 at RA2_bit; [COLOR="#FF0000"]********[/COLOR]//PIN 11

They are not considered to be a comment by the compiler, you should remove them.

There are numerous problems stemming from the over use of asterisks throughout your program.

BigDog

like this ...

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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
float ch;
unsigned int ADC_Value;
long tlong;
/*................................................. ...............................
 Define relay selection port pins
.................................................. ...............................*/
sbit RL1 @ PORTA:1;
sbit RL2 @ PORTC:0;
sbit RL3 @ PORTC,1;
sbit RL4 @ PORTC,2;
sbit RL5 @ PORTA,2;
//defined RL1 at PORTA,1;//PIN 12
//sbit RL2 at RC0_bit;//PIN 10
//sbit RL3 at RC1_bit;//PIN 09
//sbit RL4 at RC2_bit;//PIN 08
//sbit RL5 at PORTA,2;//PIN 11
/*................................................. ...............................
 Define LED/ bzr selection port pins
.................................................. ...............................*/
sbit L1 at  Rc5_bit;//PIN 05 hi\lo cut
sbit L2 at  Rc4_bit;//PIN 06 mains normal
sbit BZR at Rc3_bit;//PIN 07 SOUND
 
/*................................................. ...............................
 Define LED/ bzr selection port pins
.................................................. ...............................*/
 
sbit SW1 at  PORTA,5;//PIN 03 hi\lo cut enabol
sbit SW2 at  PORTA,4;//PIN 02 QEK SATART
 
 
void main()
{
//ANSEL = 0x01;  // RA0 analog input
    TRISA = 0x39; // setting RA0 analog input & RA3 -RA5 digital i\p
    TRISC = 0x00; // setting port C as output.
    // Configure ADCON0 for channel AN0
    ADCON0=0x01;
    ADCON1=0x00;
 
 
loop_01:
 
    L2 = 1;// mains normal on
    L1 = 0;// hi\lo cut off
    BZR = 0;// SOUND off
    RL4 = 0;// Output relay off R4
 
    /*................................................. ...............................
    Delay mode selection for user friendly...
    .................................................. ...............................*/
 
    if(SW2 == 0)
    {
        Delay_ms(5);
    }
    else
    {
        Delay_ms(1);
    }
 
    /* .................................................. .............................
    Main working starts here
    .................................................. ................................*/
    L1 = 0; // delay indicator off.
    while(1)
    {
        ADC_Value = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
        tlong =(long)ADC_Value*5000; // Convert the result in millivolts
        tlong = tlong/1023; // 0..1023 -> 0-5000mV
        ch =(float)tlong/1000; // Extract volts (thousands of millivolts)
 
        /*................................................. ...............................
        Main stabilizing is done here
        .................................................. ...............................*/
 
        if((ch<=4.60)&&(ch>=1.40))
        {
 
            if(ch>4.65)
            {
                if(ch>4.00)
                {
                    if(ch>3.65)
                    {
                        if(ch>3.15)
                        {
                            if(ch>2.56)
                            {
                                if(ch>1.48)
                                {
                                    //if(ch>1.40)
                                    //{
                                    RL5 = 1;
                                    RL3 = 1;
                                    RL2 = 1;
                                    RL1 = 0;//STP7
                                }
                                //else
                                RL5 = 1;
                                RL2 = 1;
                                RL1 = 0;
                                RL3 = 0;//STP6
                            }
                            //else
                            RL3 = 1;
                            RL2 = 1;
                            RL1 = 0;
                            RL5 = 0;//STP5
                        }
                        //else
                        RL2 = 1;
                        RL1 = 0;
                        RL5 = 0;
                        RL3 = 0;//STP4
                    }
                    //else
                    RL3 = 1;
                    RL1 = 0;
                    RL5 = 0;
                    RL2 = 0;//STP3
                }
                //else
                RL1 = 0;
                RL3 = 1;
                RL5 = 0;
                RL2 = 0;//STP2
            }
            //else
            RL3 = 1;
            RL1 = 0;
            RL5 = 0;
            RL2 = 0;//STP1
        }
        //else
        RL5 = 1;
        RL3 = 1;
        RL2 = 1;
        RL1 = 0;
 
        RL4 = 1;// output relay on.
        L2 = 1; // mains indicator on
        L1 = 0; // high //low voltage indicator off
        BZR = 0; // high //low voltage indicator off
 
    }
 
    /*................................................. ...............................
    High voltage protection for load is done here
    .................................................. ...............................*/
 
    if(ch > 4.80)
    {
        L1 = 1; // high // low voltage indicator on
        BZR = 1; // cret sound
        RL4 = 0; // relay off
        L2 = 0; // Mains normal indicator off
        goto loop_01;
    }
    /*................................................. ...............................
    Low voltage protection is done here
    .................................................. ...............................*/
 
    if(ch <= 1.30)
    {
        L1 = 1; // high // low voltage indicator on
        BZR = 1; // cret sound
        RL4 = 0; // relay off
        L2 = 0; // Mains normal indicator off
        goto loop_01;
    }
 
}  // End main()


it also give error.


I have indented the code and I have used the syntax highlighter so that it is easier to read [alexan_e]
 

What compiler are you using Sahu?

You're on the right track but I still see several syntax errors. After you tell the compiler, I can clean it up the syntax.

BigDog
 

In post #14 he wrote
Alex
after correction found error like this ...
error: 102****342****There is not enough ROM space****__Lib_MathDouble.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 1091****392****Address must be greater than 0 Div_32x32_S****__Lib_Math.c
error: 1091****392****Address must be greater than 0 Div_32x32_S****__Lib_Math.c
error: 49****392****Address must be greater than 0 ADC_Read****__Lib_ADC_A_B.c
error: 1903****392****Address must be greater than 0 Longint2Double****__Lib_MathDouble.c
error: 24****392****Address must be greater than 0 __CC2DW****__Lib_System.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 0****102****Finished (with errors): 12 Aug 2011, 21:43:39****MyProject.mcppi

i want use only 16f676 .i our local market available it ckt*
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top