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
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;
}
}
}
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;
}
}
}