Este ejemplo es del proton,
" Program to display result of ADC in 3 segment bargraph.
" The last LED in the graph dims or brightens with changes in the
" analog input.
DEVICE = 16F877
XTAL = 4
" Define ADC parameters
ADIN_RES = 10 " 10-bit result required
ADIN_TAD = FRC " RC OSC chosen
ADIN_STIME = 50 " Allow 50us sample time
DIM Adval AS BYTE " ADC result variable
DIM I AS BYTE " For-loop variable
DIM Position AS BYTE " LED position variable
DIM Bright AS BYTE " Brightness variable
ADCON1 = %00000010 " Set PORTA analog
Loop: Adval = ADIN 0 " Store ADC value to adval
Position = Adval / 85 " Position of last lit LED
Bright = (Adval // 85) * 3 " Brightness of last lit LED
FOR I = 0 TO 7 " Set each LED
IF I < Position THEN
HIGH I " Turn on if lower than last lit LED
ELSE
LOW I " Turn off if higher than last lit
ENDIF
NEXT
PWM Position,Bright,5 " Dim the last LED
GOTO Loop " Do it forever
END
Saludos,
Ricky