Multiplexing 7 seg displays

ajcgkm

New Member
Hi been a while but finally got round to doing something. Taken a few days and a lot of head banging but finally got the picaxe to multiplex a 4511 and two 7 seg displays. I used two npn transistors to switch displays and 4 pins to send data to 4511 that in turn outs data to the displays. Each display can be controlled individualy via buttons (thats how I need it ) the vid is on you tube if you fancy a look.


https://www.youtube.com/watch?v=zau0TlHLsWQ

Will get round to doing a schematic shortly and post. :D
 

westaust55

Moderator
You just have to convert the head banging into bit-banging ;)

I cannot see youtube videos (blocked) at my current location but well done on posting about your endeavours.

Can I suggest that in addition to the schematic that you also post your PICAXE program code so that others have the full project available should someone wish to emulate your feat at a future time.
 

ajcgkm

New Member
thanks for that and I usually post the code along with the schematic and here are both
I hope that it can be easily understood.
Note if you want to attach more 7 seg displays the code will have to be modified by using transistors to supply them with enough power.

enjoy and have fun.
picaxe multiplex.jpg

Please note I forgot to include the 10k resistors on pins 15 to 18 on the picaxe. If these are not included the 4511 does weird things so put up a new image with them included. So sorry :eek:

Code:
'* picaxe18m2 multiplex program By A.J,Cartwright 5/2/13
'* two 7 seg displays multiplexed via a cmos 4511
'* using the pinsC to send data to cmos 4511
'* using B pins to switch displays and receive button inputs
'* multiplexing is simply having a number of displays turn on and off individually
'* in this example just two 7 seg displays are used
'* to change the displays output or to add a countdown or countup facility
'* this program is just to show the multiplexing as simply as possible
'* the display_units and display_tens may seems long but it should be easy to follow
'* for the newcomer. 
'* learn the basics start simple then improve code efficency when everything works

setfreq m8		'set frequency to 8mhz speed things up a bit

symbol tens =b0	'tens storage variable
symbol units = b1	'units storage variable
symbol flag =b2
symbol pressed =b3

let tens =0		'can pre load the tens value here or set at 0
let units =0	'can pre load the units value here or set at 0
let flag =0		'used to choose which display to show
let pressed =0


main:
  if pinB.7 = 1 then 	' reset routine this only gets done if button pressed
   do while pinB.7 =1	' reset button pressed 
    gosub display_units ' these act like interups
    gosub display_tens  ' othewise display flashes between button presses
   loop
   units =0
   tens =0
  end if
'**********************************************
  if pinB.3 = 1 then 	' units down routine this only gets done if button pressed
   do while pinB.3 =1	' units down button pressed
    gosub display_units ' these act like interups
    gosub display_tens  ' othewise display flashes between button presses
   loop
   units = units -1	' subtract 1 from units
   if units =255 then	' test if units has gone below 0 (note no negative numbers so
    units = 9		' no -1) it goes to 255.So set to 9 here
   end if
  end if
 '*********************************************
  if pinB.2 = 1 then 	' units up routine
   do while pinB.2 =1	' units up button pressed
    gosub display_units ' these act like interups
    gosub display_tens  ' othewise display flashes between button presses
   loop
   units = units +1	' add 1 to units
   if units >9 then	' if units more than 9 change to 0
    units = 0
   end if
  end if
 '*********************************************
  if pinB.4 = 1 then 	' tens down routine this only gets done if button pressed
   do while pinB.4 =1	' tens down button pressed
    gosub display_units ' these act like interups
    gosub display_tens  ' othewise display flashes between button presses
   loop
   tens = tens -1		' subtract 1 from tens
   if tens =255 then	' test if tens has gone below 0 (note no negative numbers so
    tens = 9		' no -1) it goes to 255.So set to 9 here
   end if
  end if
 '*********************************************
  if pinB.5 = 1 then 	' tens up routine this only gets done if button pressed
   do while pinB.5 =1	' tens down button pressed
    gosub display_units ' these act like interups
    gosub display_tens  ' othewise display flashes between button presses
   loop
   tens = tens +1		' add 1 to tens
   if tens >9 then	'if tens more than 9 change to 0
    tens = 0
   end if
  end if
 '*********************************************
 if flag =0 then gosub display_units	'this displays the units if flag is equal to 0
 if flag =1 then gosub display_tens		' this displays the tens if flag is equal to 1
goto main ' end of main program

end 'end of main program code

'****************************************************

display_units:
select case units
 case 0
  let dirsC = %00000000 ' display 0 
  let pinsC = %00000000
 case 1
  let dirsC = %00000010 ' display 1 
  let pinsC = %00000010
 case 2
  let dirsC = %00000001 ' display 2
  let pinsC = %00000001
 case 3
  let dirsC = %00000011 ' display 3
  let pinsC = %00000011
 case 4
  let dirsC = %10000000 ' display 4
  let pinsC = %10000000
 case 5
  let dirsC = %10000010 ' display 5
  let pinsC = %10000010
 case 6
  let dirsC = %10000001 ' display 6
  let pinsC = %10000001
 case 7
  let dirsC = %10000011 ' display 7
  let pinsC = %10000011
 case 8
  let dirsC = %01000000 ' display 8
  let pinsC = %01000000
 case 9
  let dirsC = %01000010 ' display 9
  let pinsC = %01000010
 end select
 high B.0 'turn on units 7 seg display
 pause 5  'short delay 	
 low B.0  'turn off the uits display
 let dirsC =%00000000 'switch c pins low
 flag =1 'set flag to 1 so that, in main program display_tens will get processed
return 
 
display_tens: 
 select case tens
 case 0
  let dirsC = %00000000 ' display 0 
  let pinsC = %00000000
 case 1
  let dirsC = %00000010 ' display 1
  let pinsC = %00000010
 case 2
  let dirsC = %00000001 ' display 2
  let pinsC = %00000001
 case 3
  let dirsC = %00000011 ' display 3
  let pinsC = %00000011
 case 4
  let dirsC = %10000000 ' display 4
  let pinsC = %10000000
 case 5
  let dirsC = %10000010 ' display 5
  let pinsC = %10000010
 case 6
  let dirsC = %10000001 ' display 6
  let pinsC = %10000001
 case 7
  let dirsC = %10000011 ' display 7
  let pinsC = %10000011
 case 8
  let dirsC = %01000000 ' display 8
  let pinsC = %01000000
 case 9
  let dirsC = %01000010 ' display 9
  let pinsC = %01000010
 end select
 high B.1 'turn on tens 7 seg display
 pause 5  ' short delay
 low B.1  'turn off the tens display
 let dirsC =%00000000 ' switch c pins low
 flag =0  'set flag to 0 so that, in main program display_units will get processed
return
 

Attachments

Last edited:

ajcgkm

New Member
many thanks for that westaust55, I found this site to be very friendly and without it I would have been left scratching my head. So this is my way of saying thanks to everyone who has contributed on this site.
 
Top