Lighting 32 LEDs from Allegro LED Driver



Define OSC 4

high portb.7
pause 500
low portb.7
pause 500

'include "modedefs.bas"


define adc_bits 10
define adc_clock 3
define adc_sampleus 50

trisa = %11111111
adcon1 = %10000010
pause 500


serialPin1 var PORTD.1
strobePin1 var PORTC.3
clockPin1 var PORTD.0
blankPin1 var PORTD.2

outarray var byte [32]

ADCVar var word
ADCx VAR byte
destX var byte
i var byte

main:
    adcin 0, adcvar
    ADCx = ADCVar/8
    destX = ADCx
    destX = destX + (ADCx - destX)/50000 
    for i = 0 to 31 step 1 
        outArray[i] = 0
        next i
    outarray[destX] = 1     




    high blankPin1
        for i = 0 to 31 step 1
        low strobePin1
        low clockPin1                              
        shiftout serialPin1, clockPin1, 0, [outArray[i]\1] 
        high strobePin1
        next i

    low blankpin1

    Serout2 portc.6, 16468, ["ADCx= ", DEC ADCx, " ADCVar= " , dec ADCVar, 13, 10]

    pause 5


goto main

Multiple switch in to pic -> analog value


Define OSC 4

high portb.7
pause 500
low portb.7
pause 500


trisa = %11110111    'analoge pin to digital

switch var bit [25]


'--------------[declare input]-------------
input  portd.7
input portd.6
input portd.5
input portd.4
input portd.3
input portd.2
input portd.1
input portd.0

input portc.0

input porte.2
input porte.1
input porte.0

input porta.5
input porta.3
input porta.2
input porta.1
input porta.0

input portb.0
input portb.1
input portb.2
input portb.3
input portb.4
input portb.5
input portb.6
input portb.7

'-----------------[switch variables]--------------------
switch[0] = portd.7
switch[1] = portd.6
switch[2] = portd.5
switch[3] = portd.4
switch[4] = portd.3
switch[5] = portd.2
switch[6] = portd.1
switch[7] = portd.0

switch[8] = portc.0

switch[9] = porte.2
switch[10] = porte.1
switch[11] = porte.0

switch[12] = porta.5
switch[13] = porta.3
switch[14] = porta.2
switch[15] = porta.1
switch[16] = porta.0

switch[17] = portb.0
switch[18] = portb.1
switch[19] = portb.2
switch[20] = portb.3
switch[21] = portb.4
switch[22] = portb.5
switch[23] = portb.6
switch[24] = portb.7





FakeADC VAR byte

i var byte
total var byte

main:
    total = 0

for i=0 to 24 step 1
    i = 0
    if i < 25 then


       if switch[i] = 1 then
            total = total + 1 

       endif 
       i = i + 1
       endif

    next i  
    fakeadc = (10 * total)
    Serout2 portc.6, 16468, ["FakeADC= ", DEC FakeADC, 13, 10]

    goto main