multiplexer : MC14051BCP (FUF9808)

http://kitsrus.com/pdf/uln2003a.pdf
http://www.segyung.co.kr/DN/4000/MC14053.pdf
http://www.birnboim.com/nyu/pcomp
http://www.birnboim.com/nyu/pcomp/techresearch/

11/12/03
'****************************************************************
'* Name : final_multiplexer.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2003 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 11/12/2003 *
'* Version : 1.0 *
'* Notes : *

'* : *
'****************************************************************
' http://stage.itp.tsoa.nyu.edu/~tigoe/pcomp/examples/pic-adcin-pbpro.shtml
' PicBasic Pro program to display result of
' 10-bit A/D conversion through serial at 9600 baud
' Connect analog input to channel-0 (RA0)

INCLUDE "modedefs.bas"
DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit

'The following DEFINEs specify which timer, 1 or 2,
'to use with PWM channel 2 and PWM channel 3 for the PIC17C7xx devices.
'The default is timer 1 if no DEFINE is specified.
DEFINE HPWM2_TIMER 1 'Hpwm 2 timer select
DEFINE HPWM3_TIMER 1 'Hpwm 3 timer select

' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

addressVar var byte
mstime VAR BYTE
adval VAR WORD ' Create variable to store result
'adval2 VAR WORD

mstime = 0

lf con 10 ' line feed charactger in ASCII
cr con 13 ' carriage return character in ASCII

TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000
ADCON1 = %10000010 ' Set PORTA analog and right justify result
Pause 500 ' Wait .5 second

'flash me
while mstime < 3
high portb.6
pause 500
low portb.6
pause 500
mstime = mstime + 1
wend
main:

ADCIN 0, adval ' Read channel 0 to adval

for addressVar = 0 to 7
'portb = addressVar 'this works in one line but wastes pins
portb.0 = addressvar.0
portb.1 = addressvar.1
portb.2 = addressvar.2
HPWM 1,(1023- (adval * addressVar)/8 ),9000 ' Send a 50% duty cycle PWM signal at 1kHz
pause 1
NEXT
'for datavar = 0 to 7
' portb = datavar
' adcin 0, init[datavar]
'Next

'Debug "potVar: ", DEC adval,cr,lf ' print it to serial out 'this makes LED dim
'Pause 30 ' Wait.03 second 'this also makes LED dim, so let's take it out
'HPWM Channel,Dutycycle,Frequency
'HPWM 2,adval,2000 ' Send a 25% duty cycle PWM signal at 2kHz

GoTo main ' Do it forever
----------------------------------------------------------------------------


11/07/03
-----------------------------------------------------------
'****************************************************************
'* Name : HPWM test to turn on two LEDs.BAS *
'* Author : Hyun Jean Lee *
'* Notice : Copyright (c) 2003 [set under view...options] *
'* : All Rights Reserved *
'* Date : 11/6/03 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
' http://stage.itp.tsoa.nyu.edu/~tigoe/pcomp/examples/pic-adcin-pbpro.shtml
' PicBasic Pro program to display result of
' 10-bit A/D conversion through serial at 9600 baud
'
' Connect analog input to channel-0 (RA0)
INCLUDE "modedefs.bas"
DEFINE OSC 20 'define clock speed
DEFINE DEBUG_REG PORTB ' Set Debug pin port
DEFINE DEBUG_BIT 7 ' Set Debug pin BIT
DEFINE DEBUG_BAUD 9600 ' Set Debug baud rate
DEFINE DEBUG_MODE 1 ' Set Debug mode: 0 = true, 1 = inverted

DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit

'The following DEFINEs specify which timer, 1 or 2,
'to use with PWM channel 2 and PWM channel 3 for the PIC17C7xx devices.
'The default is timer 1 if no DEFINE is specified.
DEFINE HPWM2_TIMER 1 'Hpwm 2 timer select
DEFINE HPWM3_TIMER 1 'Hpwm 3 timer select

' Define ADCIN parameters
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

mstime VAR BYTE
adval VAR BYTE ' Create variable to store result
'adval2 VAR WORD
mstime = 0
pin VAR BYTE
pin = 0
'blinky var byte
'datavar var byte
'adcvar var byte
'init var byte[8] 'create an array to store inital values from photocells
'adcvar = 0
'blinky = 0
'datavar = 0

'pause 500'run through all eight inputs on the multiplexer and store their ADC values
'for datavar = 0 to 7
'portb = datavar
'adcin 0, init[datavar]
'next

lf con 10 ' line feed charactger in ASCII
cr con 13 ' carriage return character in ASCII

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000010 ' Set PORTA analog and right justify result
Pause 500 ' Wait .5 second

'flash me
while mstime < 3
high portb.6
pause 500
low portb.6
pause 500
mstime = mstime + 1
wend

main:
ADCIN 0, adval ' Read channel 0 to adval
'adval2= adval /4
'Debug "potVar: ", DEC adval,cr,lf ' print it to serial out 'this makes LED dim
'Pause 30 ' Wait.03 second 'this also makes LED dim, so let's take it out

'HPWM Channel,Dutycycle,Frequency
'HPWM 1,adval,2000 ' Send a 50% duty cycle PWM signal at 1kHz
'HPWM 2,adval,2000 ' Send a 50% duty cycle PWM signal at 2kHz

'portb = datavar 'I select which pin on the multiplexer I am listening to
for pin = 0 to 7
portc = pin
'HPWM Channel,Dutycycle,Frequency
'pin, 2000 ' Send a 50% duty cycle PWM signal at 1kHz
HPWM 1,adval,2000 ' Send a 50% duty cycle PWM signal at 2kHz
'adcin 0, adcvar 'get its Adc value compare it to the initial value taken
'if abs (init[datavar] - adcvar) > 10 then 'if the difference is greater than 10
' serout portc.6, N9600, ["Pin# ", #datavar, 13, 10, "Value= ", #adcvar, 13, 10]
'endif 'I debug which pin has had the change and its value
next


GoTo main ' Do it forever

---------------------------------------------------


11/05

'****************************************************************
'* Name : HPWM test to turn on two LEDs.BAS *
'* Author : Hyun Jean Lee *
'* Notice : Copyright (c) 2003 [set under view...options] *
'* : All Rights Reserved *
'* Date : 11/6/03 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
' http://stage.itp.tsoa.nyu.edu/~tigoe/pcomp/examples/pic-adcin-pbpro.shtml
' PicBasic Pro program to display result of
' 10-bit A/D conversion through serial at 9600 baud
'
' Connect analog input to channel-0 (RA0)
INCLUDE "modedefs.bas"

DEFINE DEBUG_REG PORTB ' Set Debug pin port
DEFINE DEBUG_BIT 7 ' Set Debug pin BIT
DEFINE DEBUG_BAUD 9600 ' Set Debug baud rate
DEFINE DEBUG_MODE 1 ' Set Debug mode: 0 = true, 1 = inverted

DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit

'The following DEFINEs specify which timer, 1 or 2,
'to use with PWM channel 2 and PWM channel 3 for the PIC17C7xx devices.
'The default is timer 1 if no DEFINE is specified.
DEFINE HPWM2_TIMER 1 'Hpwm 2 timer select
DEFINE HPWM3_TIMER 1 'Hpwm 3 timer select

' Define ADCIN parameters
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

mstime VAR BYTE
adval VAR WORD ' Create variable to store result
'adval2 VAR WORD
mstime = 0

lf con 10 ' line feed charactger in ASCII
cr con 13 ' carriage return character in ASCII

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000010 ' Set PORTA analog and right justify result
Pause 500 ' Wait .5 second

'flash me
while mstime < 3
high portb.6
pause 500
low portb.6
pause 500
mstime = mstime + 1
wend

main:
ADCIN 0, adval ' Read channel 0 to adval
'adval2= adval /4
'Debug "potVar: ", DEC adval,cr,lf ' print it to serial out 'this makes LED dim
'Pause 30 ' Wait.03 second 'this also makes LED dim, so let's take it out

'HPWM Channel,Dutycycle,Frequency
HPWM 1,adval,2000 ' Send a 50% duty cycle PWM signal at 1kHz
HPWM 2,adval,200 ' Send a 25% duty cycle PWM signal at 2kHz
GoTo main ' Do it forever

------------------------------------------------------------------------

Micheal's page : http://stage.itp.tsoa.nyu.edu/~ms1434/pic/#multi

his code for Multiplexer ADC in using MC14051BCP

Multiplexer ADC in using MC14051BCP

'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [Michael Luck Schneider] *
'* Notice : Copyright (c) 2003 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 10/24/03 *
'* Version : 1.0 *
'* Notes : using the MC14051BCP *
'* : *
'****************************************************************
'this program uses the MC14051BCP Multiplexer/demultiplexer chip found at the NYU computerstore
'there are eight photocells attached to each of the 8 switch pins
'an initial value is taken of each of the eight photocells on startup
'then each of the eight photocells ADC's are read and compared to the initialized value
'if the value has changed by more than 10 I send that info out serially.
'define onint_used 1 'uncomment if using in-line serial programming

define osc 20 'define clock speed
INCLUDE "modedefs.bas"

define ADC_BITS 8 'define 8 bits of ADC
define ADC_CLOCK 3 'define clock as RC = 3
define ADC_SAMPLEUS 50 'adc clock at 50us samples

trisa = %11111111 'set portA as all inputs
adcon1 = %000000010 'set PORTA as all ADC
trisb = %00000000 'set PORTB as all outputs
portb = %00000000 'initialize portb (all off)

blinky var byte
datavar var byte
adcvar var byte
init var byte[8] 'create an array to store inital values from photocells

adcvar = 0
blinky = 0
datavar = 0


pause 500'run through all eight inputs on the multiplexer and store their ADC values
for datavar = 0 to 7
portb = datavar
adcin 0, init[datavar]
next


main:
'blinky
while blinky < 3
high portb.7
pause 120
low portb.7
pause 120
blinky = blinky + 1
wend

for datavar = 0 to 7
portb = datavar 'I select which pin on the multiplexer I am listening to
adcin 0, adcvar 'get its Adc value compare it to the initial value taken
if abs (init[datavar] - adcvar) > 10 then 'if the difference is greater than 10
serout portc.6, N9600, ["Pin# ", #datavar, 13, 10, "Value= ", #adcvar, 13, 10]
endif 'I debug which pin has had the change and its value
next
goto main
top

Addressable Latch in Addressable latch mode and Demultiplexer mode using CD4099

'This is a simple example of an addressable latch used in its addressable latch mode
'this allows for one pin to be addressed while leaving the other pins in the state that
'they were last in. The mode of the addressable latch is chosen by the enable and latch
'pins. With the enable pin low and the latch pin low you can send a digital signal
'high, low, pwm, serail, etc... With the enable pin high the data is held in each
'address and cannot be changed. My adress0 is in portb.0, A1 - portb.1, A2 - portb.2

'define onint_used 1 'use this only with SERIAL PROGRAMMING
define osc 20 'define the clock speed

trisb = %00000000 'set portb as output
trisc = %10000000 'set portc as output except portc.7 for serial Tx
portb = %00000000

blinky var byte
addressVar var byte

enablepin var portc.2 'E
datapin var portc.1
latchpin var portc.0 'CL

blinky = 0

main:
while blinky < 3
portb.7 = 1
pause 120
portb.7 = 0
pause 120
blinky = blinky + 1
wend
for addressVar = 0 to 7
'portb = addressVar 'this works in one line but wastes pins
portb.0 = addressvar.0
portb.1 = addressvar.1
portb.2 = addressvar.2

latchpin = 0
enablepin = 0 'enable addressable latch mode
'for blinky = 0 to 128 'this is for PWM example

for blinky = 6 to 0 step -1
datapin = 0
pause 50
datapin = 1
pause 50
'hpwm 2, blinky * 2, 10000
'pause 10
next

enablepin = 1 'lock down
pause 100

next

for addressVar = 0 to 7 'turn them all off
portb = addressVar
latchpin = 0
enablepin = 0
datapin = 0
enablepin = 1
pause 100

next
goto main
top

This is the demultiplexer mode

'this is a brief example of how to use the addressable latch as a demultiplexer
'this means you can send a digital signal to a specific pin automatically turning
'all the other pins low. Usefull for row column scanning parrallel addressing of
'each pin. Can use many addressable latches sharing the address pins have a seperate
'latch for each one and grounding the enable pin. By bringing the latch high you
'can address each pin, turning the others off. PWM also works.

' define onint_used 1 'use this ONLY IF YOU ARE DOING IN_LINE SERIAL PROGRAMMING
define osc 20 'define the speed of the clock

trisb = %00000000 'set portb as output
trisc = %10000000 'set portc as output except portc.7 for Tx serial

portb = %00000000

blinky var byte 'my blinky variabl
addressVar var byte 'my address for the three
enablepin var portc.2 'E
datapin var portc.1
latchpin var portc.0 'CL

blinky = 0

main:
while blinky < 3
portb.7 = 1
pause 120
portb.7 = 0
pause 120
blinky = blinky + 1
wend
for addressVar = 0 to 7

'portb = addressvar 'can be done in one line but wastes pins
portb.0 = addressVar.0
portb.1 = addressvar.1
portb.2 = addressvar.2
latchpin = 1
enablepin = 0
'for blinky = 0 to 128 'for HPWM

for blinky = 6 to 0 step -1
datapin = 0
pause 50
datapin = 1
pause 50
'hpwm 2, blinky * 2, 10000
'pause 10 'for HPWM
next

pause 100
next

goto main
top