When you find yourself writing the same section of code over and over with only changes to the values ....
It usually means you are doing it the hardest and least efficient way. 
Instead of a bunch of IF/THEN's, use a little math, and a couple FOR/NEXT loops.
Code:
'Initialize variables PIC16F88
#CONFIG
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
#ENDCONFIG
DEFINE OSC 4
OSCCON=$60 'Set Internal Oscillator to 4MHz
DEFINE ADC_BITS 10 ' 10 bit A/D Conversion
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' 50 uS A/D sample time
ANSEL = %00000001 ' Set pin (AN0) to analog input, the rest to digital
ADCON1.7 = 1 ' Right Justify A/D results
LED VAR BYTE
Row VAR BYTE
Col VAR BYTE
Idx VAR BYTE
Row_Pin VAR BYTE
Col_Pin VAR BYTE
adval VAR WORD
LEDcount CON 35
Spaces CON LEDcount + 1
Margin CON 1023 / Spaces
;-------------------------------------------------------------------------------
Main:
ADCIN 0, adval
LED = adval * LEDcount ; Determine which LED to light
LED = DIV32 (1023 - Margin) - 1
Row = -1 ; Turn OFF all dots
Col = -1 ; to prevent ghosting
GOSUB ShowDot
Row = LED // 7 ; convert LED to Row/Column
Col = LED / 7
GOSUB ShowDot
GOTO Main
;-------------------------------------------------------------------------------
ShowDot:
FOR Idx = 0 To 6 ; Set Row's
LOOKUP Idx,[1,2,3,4,5,6,7],Row_Pin
IF Idx = Row THEN
HIGH Row_Pin
ELSE
LOW Row_Pin
ENDIF
NEXT Idx
FOR Idx = 0 TO 4 ; Set Column's
LOOKUP Idx,[9,10,11,12,0],Col_Pin
IF Idx = Col THEN
LOW Col_Pin
ELSE
HIGH Col_Pin
ENDIF
NEXT Idx
RETURN
And, for the two lights on at a time ... you may want to add this ...
http://www.picbasic.co.uk/forum/cont...ith-hysteresis
Bookmarks