dexanu
Newbie level 3
Hello guys!
I started to learn programming PICs a couple of days ago using Myke Predko's "123 Microcontroller Experiments for the Evil Genius" and Proteus 8.
I reached an experiment where the author shows how to program a 2 digit 7 segment led, so I decided to do something more challenging for me: to read the value of ADRESH and display it on the 7 segment leds. The problem is that even the code is okay for me and I tried to debug it and it worked fine, when I have a number bigger than 9 both 7 segment leds wil display the same number(e.g. 11,22,33...) instead of the real value of ADRESH.
Here is the code:
I also attach the circuit diagram.
Any help is appreciated and thank you!
I started to learn programming PICs a couple of days ago using Myke Predko's "123 Microcontroller Experiments for the Evil Genius" and Proteus 8.
I reached an experiment where the author shows how to program a 2 digit 7 segment led, so I decided to do something more challenging for me: to read the value of ADRESH and display it on the 7 segment leds. The problem is that even the code is okay for me and I tried to debug it and it worked fine, when I have a number bigger than 9 both 7 segment leds wil display the same number(e.g. 11,22,33...) instead of the real value of ADRESH.
Here is the code:
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 #include <htc.h> #include <pic.h> __CONFIG( IESODIS & PWRTEN & WDTDIS & MCLRDIS & BOREN); const char Digit[10]={1,0b1001111,0b0010010,0b0000110,0b1001100,0b0100100,0b0100000,0b0001111,0,4}; main(){ int ADCValue,a,b; TRISC=0; TRISA=0b00010000; ADCON0=0b1101; ADCON1=0b1100000; ANSEL=0b1000; while(1){ __delay_us(500); GODONE=1; while(!GODONE); ADCValue=ADRESH>>2; //size down the value if(ADCValue<=9){ RA2=1; RA1=0; PORTC=Digit[ADCValue%10]; if(ADCValue==1 || ADCValue==4) RA0=1; else RA0=0; }//if1 if(ADCValue>=10){ RA2=1; RA1=0; a=ADCValue%10; PORTC=Digit[a]; if(a==1 || a==4) RA0=1; else RA0=0; __delay_ms(30); RA2=0; RA1=1; b=ADCValue/10; PORTC=Digit[b]; if(b==1 || b==4) RA0=1; else RA0=0; __delay_ms(30); }//if2 }//while }//main
I also attach the circuit diagram.
Any help is appreciated and thank you!
Last edited by a moderator: