VFD PROGRAM

//crystal of 16 MHz
#define s1  LATE.F0          //S1
#define s2  LATE.F1           //S2
#define s3  LATE.F2   //S3
#define s4  LATE.F3  //S4
#define s5  LATE.F4   //S3
#define s6  LATE.F5  //S4
void delay(void);
unsigned long int frequency,i;
void main()
{
TRISE.F0=0;TRISE.F1=0;TRISE.F2=0;TRISE.F3=0;
TRISE.F4=0;TRISE.F5=0;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;
TRISB.F0 = 1;
while (1)
{
frequency = ADC1_Read(0)*50/1023;   //freq


if(frequency !=0)
{
frequency = 160000/5/frequency ;   //freq
s1 =1;s3 =1;s5 =1;   delay();     s3 =0;
s1 =1;s6 =1;s5 =1;   delay();     s5 =0;
s1 =1;s6 =1;s2 =1;   delay();     s1 =0;
s4 =1;s6 =1;s2 =1;   delay();     s6 =0;
s4 =1;s3 =1;s2 =1;   delay();     s2 =0;
s4 =1;s3 =1;s5 =1;   delay();     s4 =0;
}
else
{
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;
}
}
}
void delay(void)
{
for(i=0;i<frequency;i++)
{
delay_us(1);
}
}