Mithun_K_Das
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
- Activity points
- 8,254
Code C - [expand] 1 if(RC6_bit = 0)
Code C - [expand] 1 if(RC6_bit == 0)
Code C - [expand] 1 if(!RC6_bit)
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]) ... ...
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.
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;
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;
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;
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.
above code not work as voltage stabilizer on OSHON SOFT SIMULATOR .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.
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;
}
** * * * * * * * *}
}
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 ?
// 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
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
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()
I have indented the code and I have used the syntax highlighter so that it is easier to read [alexan_e]
after correction found error like this ...In post #14 he wrote
Alex
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
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?