I'm using a 16f88 to read a adc value from a V/r but when i display it on 4 seven segs there value is changing very quickly
though the v/r is not changed
please give me a help
my code is
//-------------- Returns mask for common anode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 192;
case 1 : return 249;
case 2 : return 164;
case 3 : return 176;
case 4 : return 153;
case 5 : return 146;
case 6 : return 130;
case 7 : return 248;
case 8 : return 128;
case 9 : return 144;
} //case end
}//~
int i,j,h,t ;
short on , te, hu , th ;
void main(){
OSCCON=0b01111111;
ANSEL= 0b00010000;
ADCON0 =0b11001101;
ADCON1 = 0x80; // Configure analog inputs and Vref
TRISB = 0;
TRISA = 0b00111100;
/*****************************/
while(1){
i = Adc_read(3 );
while (t<25){
on = i % 10 ;
PORTA.F6 = 1 ;
PORTB = mask(on);
Delay_ms(5);
PORTA.F6 = 0 ;
j = (i - on )/10 ;
te = j%10 ;
PORTA.F7 = 1;
PORTB = mask(te);
Delay_ms(5);
PORTA.F7 = 0;
h = (j - te)/10 ;
hu = (h)%10 ;
PORTA.F0 = 1;
PORTB = mask(hu);
Delay_ms(5);
PORTA.F0 = 0;
th = (h - hu)/10 ;
PORTA.F1 = 1;
PORTB = mask(th);
Delay_ms(5);
PORTA.F1 = 0;
t++;
}
t = 0 ;
}
}
PLEASE help me I'm helpless
Re: PLEASE help me I'm helpless
To me the code seems alright
If the ADC port pin is left open then the output will wary very fast.
However this can be verified by pulling the ADC port pin to ground.
Then it should display "0"
After that pullup the port pin to 5V. It should show "1023" (applicable to 10 bit ADC)
If the result is OK then all you can assume that ADC is working fine.
So all you want to do now is slow down the pic by adding sufficient delay between each ADC read.
Say, 500ms.
If the ADC port pin is left open then the output will wary very fast.
However this can be verified by pulling the ADC port pin to ground.
Then it should display "0"
After that pullup the port pin to 5V. It should show "1023" (applicable to 10 bit ADC)
If the result is OK then all you can assume that ADC is working fine.
So all you want to do now is slow down the pic by adding sufficient delay between each ADC read.
Say, 500ms.
- ranko.rankovic
- Posts: 433
- Joined: 11 Jun 2010 09:22
Re: PLEASE help me I'm helpless
Hello rat16f88,
I see you are using our old compiler, may I suggest you to try out our new one. You can download it here.
Regarding, example you wrote, there is working one that you can find here, although it is written for new compiler.
Best regards
I see you are using our old compiler, may I suggest you to try out our new one. You can download it here.
Regarding, example you wrote, there is working one that you can find here, although it is written for new compiler.
Best regards
Ranko Rankovic
mikroElektronika [Support Department]
mikroElektronika [Support Department]
Re: PLEASE help me I'm helpless
THANKS every body ur help is so great
but it only reads maxm of 600 ..700 some thinf it never gives 1023
but it only reads maxm of 600 ..700 some thinf it never gives 1023