Void init_peripheral();
Void Referesh();
void setRelay();
void display();
#bit sel1 =0x07.7
#bit sel2 =0x07.6
#bit sel3 =0x07.5
#bit sel4 =0x07.4
#byte portb=0x06
#bit menu =0x07.0
#bit up = 0x07.1
#bit down =0x05.1
#bit enter =0x7.3
#bit relay1=0x05.4
#byte trisb=0x86
#byte trisa=0x85
#byte trisc =0x87
#byte portc =0x07
//#define step_size=0.01640625
float digital_data;
int16 count,digital,value;
int8 i;
int8 A2=0;
const int8 seg[10]={0x7e,0x0c,0xb6,0x9e,0xcc,0xda,0xfa,0x0e,0xfe,0xce};
void display()
{
setup_adc_ports( AN0 );
set_adc_channel(0);
delay_ms(1);
//this calcultion for getting voltage level.
//count=(read_adc()/51.00)*100;
count=read_adc();
if(count<20)
{
portb=0x80;sel4=1;delay_ms(1);sel4=0;
portb=0x80;sel3=1;delay_ms(1);sel3=0;
portb=0x80;sel2=1;delay_ms(1);sel2=0;
portb=0x80;sel1=1;delay_ms(1);sel1=0;
digital=0;
}
else if((count>=21)&&(count<=75))
{
digital=0;
referesh();
}
else if((count>=76)&&(count<=80))
{
digital=(1+((count-76)*0.5));
referesh();
}
else if((count>=81)&&(count<=96))
{
digital=(3+((count-81)*0.266));
referesh();
}
else if((count>=97)&&(count<=112))
{
digital=(7+((count-97)*0.333));
referesh();
}
else if((count>=113)&&(count<=117))
{
digital=(12+((count-113)*0.75));
referesh();
}
else if((count>=118)&&(count<=164))
{
digital=(15+((count-118)*0.217));
referesh();
}
else if ((count>=165)&&(count<=252))
{
digital=(25+((count-165)*4.31));
referesh();
}
else if(count>=253)
{
digital=400;
referesh();
}
}
void main(void)
{
//setup_adc_ports( ALL_ANALOG );
setup_adc(Adc_clock_DIV_64);
//setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(int_timer1);
enable_interrupts(global);
init_peripheral();
count=0;
while(1)
{
display();
}
}
void init_peripheral()
{
trisa=0x0f;trisb=0;digital_data=0;
trisb=0;trisc=0x0b;
}
void referesh()
{
int16 d1,d2,d3,d4;
d3=(digital%10); //third digit
d2=(digital/10)%10;//second digit
d1= digital/100; //first disgit
portb=seg[d3];sel4=1;delay_ms(1);sel4=0; //display first digit
portb=0x01;sel2=1;delay_ms(1);sel2=0; //dispaly decimal point
portb=seg[d2];sel3=1;delay_ms(1);sel3=0; //display second digit
portb=seg[d1];sel2=1;delay_ms(1);sel2=0; //display third digit
}
this is my code and i want to set a relay point
if i press menu it will go to 'set' and if i press enter then it will go to set value 0.00 to 4.00
adc out is 0.00 to 4.00 to seven segment disp