'Program to read adc at AN4 and show on 4 digit display 'Decimal point xxx.x for 100.2v scaling Use 200k/4.99k for divider. @ Device PIC16F88, HS_osc, Wdt_Off, Pwrt_On, Bod_On, Lvp_Off, Cpd_Off, Protect_Off ,MCLR_ON INCLUDE "modedefs.bas" DEFINE OSC 20 CMCON = 7 trisb = %00000000 trisa = %11110000 ANSEL = %00010000 ADCON1 = %10000000 ' Set PORTA analog and RIGHT justify result n Var Byte 'counter B0 Var Byte W1 Var Word adval Var Word 'adc value turnon: ADCON0 = %11100101 ' Configure and turn on A/D Module loop: ADCON0.2 = 1 ' Start Conversion notdone: Pauseus 5 If ADCON0.2 = 1 Then notdone ' Wait for low on bit-2 of ADCON0, conversion finished adval.highbyte = ADRESH ' Move HIGH byte of result to adval adval.lowbyte = ADRESL ' Move LOW byte of result to adval n = 0 display4: n = n + 1 if n = 100 then loop w1 = adval B0 = W1 / 1000 ' Find number of thousands W1 = W1 // 1000 ' Remove thousands from W1 GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED PORTA = 8 ' Turn on fourth digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting B0 = W1 / 100 ' Find number of hundreds W1 = W1 // 100 ' Remove hundreds from W1 GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED Poke PORTA, 4 ' Turn on third digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting B0 = W1 / 10 ' Find number of tens W1 = W1 // 10 ' Remove tens from W1 GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED PORTA = 1 ' Turn on second digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting B0 = W1 ' Get number of ones GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED PORTA = 2 ' Turn on first digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting decpoint: portb = %11111101 'turn on DP porta = %00000001 ' select digit3 pause 1 'light DP for a moment porta = 0 'turn off DP goto display4 ' Convert binary number in B0 to segments for LED bin2seg: LookUp B0,[34,123,22,26,75,138,194,59,2,11],B0 Return End