Count-up 2 display 7 segment

giac77

New Member
Hello!
To understand the operation of the PIC, I tried to implement a
counter with a display double but I can not get see well the numbers.
I use Picaxe 28x1 for make it.

Where is the error?
Thanks. Bye Giacomo

Code:
let b0 = 0
let b1 = 0

let pins =%00000000

low portc 7
low portc 6
low portc 5
low portc 4


main:

'if portc pin0 = 1 then goto incrementa

for b2 = 0 to 99
	let b2 = b2+1
		gosub contare
			pause 500
		gosub visualizza
next b2

end

contare:
let b0 = b0 + 1
if b0 > 9 then let b0 = 0
b1 = b1 +1
end if
if b1 > 9 then let b1 = 0
end if
return



incrementa:

if b0 > 9 then goto decina
let b0 = b0+1

goto main

decina:
let b0 = 0
let b1 = b1 +1
if b1>9 then goto azzero

goto main


azzero:
let b0 = 0
let b1 = 0

goto main






visualizza:

gosub decine
pause 2
gosub unita
pause 2

return




unita:
high portc 7
high portc 6
low portc 5
high portc 4

if b0 = 0 then goto zero
if b0 = 1 then goto uno
if b0 = 2 then goto due
if b0 = 3 then goto tre
if b0 = 4 then goto quattro
if b0 = 5 then goto cinque
if b0 = 6 then goto sei
if b0 = 7 then goto sette
if b0 = 8 then goto otto
if b0 = 9 then goto nove


zero:

high 0
high 1
high 2
high 3
high 4
high 5
low 6

return

spento:

low 0
low 1
low 2
low 3
low 4
low 5
low 6

return

uno:

low 0
high 1
high 2
low 3
low 4
low 5
low 6

return

due:
high 0
high 1
low 2
high 3
high 4
low 5
high 6

return

tre:
high 0
high 1
high 2
high 3
low 4
low 5
high 6

return

quattro:
low 0
high 1
high 2
low 3
low 4
high 5
high 6

return

cinque:
high 0
low 1
high 2
high 3
low 4
high 5
high 6

return

sei:
high 0
low 1
high 2
high 3
high 4
high 5
high 6

return

sette:

high 0
high 1
high 2
low 3
low 4
low 5
low 6

return


otto:
high 0
high 1
high 2
high 3
high 4
high 5
high 6

return

nove:

high 0
high 1
high 2
high 3
low 4
high 5
high 6

return

decine:
high portc 7
low portc 6
high portc 5
high portc 4

if b1 = 0 then goto zero1
if b1 = 1 then goto uno1
if b1 = 2 then goto due1
if b1 = 3 then goto tre1
if b1 = 4 then goto quattro1
if b1 = 5 then goto cinque1
if b1 = 6 then goto sei1
if b1 = 7 then goto sette1
if b1 = 8 then goto otto1
if b1 = 9 then goto nove1


zero1:

high 0
high 1
high 2
high 3
high 4
high 5
low 6

return

spento1:

low 0
low 1
low 2
low 3
low 4
low 5
low 6

return

uno1:

low 0
high 1
high 2
low 3
low 4
low 5
low 6

return

due1:
high 0
high 1
low 2
high 3
high 4
low 5
high 6

return

tre1:
high 0
high 1
high 2
high 3
low 4
low 5
high 6

return

quattro1:
low 0
high 1
high 2
low 3
low 4
high 5
high 6

return

cinque1:
high 0
low 1
high 2
high 3
low 4
high 5
high 6

return

sei1:
high 0
low 1
high 2
high 3
high 4
high 5
high 6

return

sette1:

high 0
high 1
high 2
low 3
low 4
low 5
low 6

return


otto1:
high 0
high 1
high 2
high 3
high 4
high 5
high 6

return

nove1:

high 0
high 1
high 2
high 3
low 4
high 5
high 6

return

another testing..


Code:
for b2 = 0 to 99
	let b2 = b2+1
		gosub contare
                        for b5= 1 to 125       '1sec pause cicle 125x8ms =1sec
		            gosub visualizza
                        next b5
next b2

.
.

visualizza:

gosub decine
pause 4                         '4ms delay between first diplay and second display
gosub unita
pause 4                         '4ms delay between second diplay and first display

return
 

inglewoodpete

Senior Member
Giacomo,

When multiplexing LED displays, it helps to:
* Set outputs quickly
* Extend display time proportion
* Increase LED 'on' current (with care)

To set outputs quickly, try the following
Code:
Select Case b0
Case 0
   Pins = %01111111
Case 1
   Pins = %00000110
.
.
Case 9
   Pins = %01101111
Else
   Pins = %00000000
EndSelect
Use the "SetFreq m8" command to speed up execution.

The maximum LED current depends on your circuit. Each PICAXE output pin is limited to about 20mA or 100mA for the whole chip. You should have a buffer transistor to drive the common pin of each display. The segment drive resistors (on outputs 0-7) should be set to drive 20mA per segment if connected directly.

Peter
 

giac77

New Member
The maximum LED current depends on your circuit. Each PICAXE output pin is limited to about 20mA or 100mA for the whole chip. You should have a buffer transistor to drive the common pin of each display. The segment drive resistors (on outputs 0-7) should be set to drive 20mA per segment if connected directly.
oh yes! I use a I.C ULN2803 for drive the display and 4 transistor PNP for drive the anode.
 

giac77

New Member
Hi!
I changed some things but the number is not displayed correctly.
I have to change the delay times of the display?

could you give me a hand ? thanks!
bye Giacomo


'*********************************
'* test display - count-up 0-99 *
'*********************************

'--------------------------
'SETTING
'--------------------------

setfreq m8

let b0 = 0
let b1 = 0
let b2 = 0

let pins = %00000000

low portc 7
low portc 6
low portc 5
low portc 4


'--------------------------
'START PROGR
'--------------------------

main:

'if portc pin0 = 1 then goto incrementa

for b2 = 0 to 189

gosub contare
for b3 = 1 to 40 '40cicli da 30ms = 1,2sec di pausa
gosub visualizza 'visualizza il numero sul Display
next b3

next b2

let pins = %00000000
end



contare:

let b0 = b0 + 1
if b0 > 9 then let b0 = 0
b1 = b1 +1
end if
if b1 > 9 then let b1 = 0
end if
return



'---------------------------------
'- VISUALIZZA CIFRE -
'---------------------------------


visualizza:

gosub decine
pause 15 'pausa di 15ms
gosub unita
pause 15 'pausa di 15ms

return


'----------------------------------
'- VISUALIZZA UNITA -
'----------------------------------


unita:

high portc 7
high portc 6
low portc 5
high portc 4


select case b0

case 0
LET PINS = %00111111

case 1
LET PINS = %00000110

case 2
LET PINS = %01011011

case 3
LET PINS = %01001111

case 4
LET PINS = %01100110

case 5
LET PINS = %01101101

case 6
LET PINS = %01111101

case 7
LET PINS = %00000111

case 8
LET PINS = %01111111

case 9
LET PINS = %01101111



endselect
return

'-----------------------------------
'- VISUALIZZA DECINE -
'-----------------------------------


decine:

high portc 7
low portc 6
high portc 5
high portc 4


select case b1

case 0
LET PINS = %00111111

case 1
LET PINS = %00000110

case 2
LET PINS = %01011011

case 3
LET PINS = %01001111

case 4
LET PINS = %01100110

case 5
LET PINS = %01101101

case 6
LET PINS = %01111101

case 7
LET PINS = %00000111

case 8
LET PINS = %01111111

case 9
LET PINS = %01101111

Else
Pins = %00000000

endselect
return
 

Mycroft2152

Senior Member
The crystal ball is a little cloudy tonight.

Please explain "the number is not displayed correctly"

Does the program run correctly in the simulator?
 

inglewoodpete

Senior Member
Hi again Giacomo,

You don't say what the problem is. Do the digits change each 1.2 seconds? You have set the speed to 8MHz. This will halve the time for all commands: "Pause 15" will delay for 7.5mS.

Are the segments wrong?

I have made a small change to your code. I have put the segment configuration into a subroutine. This removes the duplication of code used to set the sements for the 10's and 1's digits.

Code:
'*********************************
'* test display - count-up 0-99 *
'*********************************

'--------------------------
'SETTING
'--------------------------

setfreq m8

let b0 = 0
let b1 = 0
let b2 = 0

let pins = %00000000

low portc 7
low portc 6
low portc 5
low portc 4


'--------------------------
'START PROGR
'--------------------------

main:

'if portc pin0 = 1 then goto incrementa

for b2 = 0 to 189

   gosub contare
   for b3 = 1 to 40      '40cicli da 30ms = 1,2sec di pausa
      gosub visualizza      'visualizza il numero sul Display
   next b3

next b2

let pins = %00000000
end



contare:

let b0 = b0 + 1
if b0 > 9 then
   let b0 = 0
   b1 = b1 + 1
end if
if b1 > 9 then
   let b1 = 0
end if
return



'---------------------------------
'- VISUALIZZA CIFRE -
'---------------------------------


visualizza:

gosub decine
pause 15     'pausa di 15ms
gosub unita
pause 15     'pausa di 15ms

return


'----------------------------------
'- VISUALIZZA UNITA -
'----------------------------------


unita:

high portc 7
high portc 6
low portc 5
high portc 4

b4 = b0
GoSub SetSegments
return                        'Edit: I have added this command

'-----------------------------------
'- VISUALIZZA DECINE -
'-----------------------------------


decine:

high portc 7
low portc 6
high portc 5
high portc 4

b3 = b0
GoSub SetSegments
return

'-----------------------------------
'- (display the segments) -
'-----------------------------------


SetSegments:   'Switch segments for b2 values 0 to 9 
Select Case b4
Case 0
   LET PINS = %00111111
Case 1
   LET PINS = %00000110
Case 2
   LET PINS = %01011011
Case 3
   LET PINS = %01001111
case 4
   LET PINS = %01100110
Case 5
   LET PINS = %01101101
Case 6
   LET PINS = %01111101
Case 7
   LET PINS = %00000111
Case 8
   LET PINS = %01111111
Case 9
   LET PINS = %01101111
Else
   Pins = %00000000
EndSelect
Return
Simplified code for 1 digit:
Code:
'*********************************
'* test display - count-up 0-9 *
'*********************************

'--------------------------
'SETTING
'--------------------------

setfreq m8

let b0 = 0
let b1 = 0
let b2 = 0

let pins = %00000000

low portc 7
low portc 6
low portc 5
low portc 4


'--------------------------
'START PROGR
'--------------------------

main:

for b4 = 0 to 9

   for b3 = 1 to 40      '40cicli da 30ms = 1,2sec di pausa
      gosub visualizza      'visualizza il numero sul Display
   next b3

next b4

let pins = %00000000
Pause 5000
Goto main		'Repeat



'---------------------------------
'- VISUALIZZA CIFRE -
'---------------------------------


visualizza:

gosub unita
pause 15     'pausa di 15ms

return


'----------------------------------
'- VISUALIZZA UNITA -
'----------------------------------


unita:

high portc 7
high portc 6
low portc 5
high portc 4

GoSub SetSegments
Return


'-----------------------------------
'- (display the segments) -
'-----------------------------------


SetSegments:   'Switch segments for b2 values 0 to 9 
Select Case b4
Case 0
   LET PINS = %00111111
Case 1
   LET PINS = %00000110
Case 2
   LET PINS = %01011011
Case 3
   LET PINS = %01001111
case 4
   LET PINS = %01100110
Case 5
   LET PINS = %01101101
Case 6
   LET PINS = %01111101
Case 7
   LET PINS = %00000111
Case 8
   LET PINS = %01111111
Case 9
   LET PINS = %01101111
Else
   Pins = %00000000
EndSelect
Return
 
Last edited:

giac77

New Member
I can not see well the segments of the display: number for number but I see all segments turned on and is almost impossible to distinguish the numbers shown. If I change the delay time and I increased it, I can see perfectly well the number but only one of two numbers.
I want to get a count up of a second for second because I need to understand how it works to create a countdown for my canon camera :)
 

giac77

New Member
'*********************************
'* test display - count-up 0-9 *
'*********************************

'--------------------------
'SETTING
'--------------------------

setfreq m8

let b0 = 0
let b1 = 0
let b2 = 0

let pins = %00000000

low portc 7
low portc 6
low portc 5
low portc 4


'--------------------------
'START PROGR
'--------------------------

main:

for b4 = 0 to 9

for b3 = 1 to 40 '40cicli da 30ms = 1,2sec di pausa
gosub visualizza 'visualizza il numero sul Display
next b3

next b4

let pins = %00000000
Pause 5000
Goto main 'Repeat



'---------------------------------
'- VISUALIZZA CIFRE -
'---------------------------------


visualizza:

gosub unita
pause 15 'pausa di 15ms

return


'----------------------------------
'- VISUALIZZA UNITA -
'----------------------------------


unita:

high portc 7
high portc 6
low portc 5
high portc 4

GoSub SetSegments
Return


'-----------------------------------
'- (display the segments) -
'-----------------------------------


SetSegments: 'Switch segments for b2 values 0 to 9
Select Case b4
Case 0
LET PINS = %00111111
Case 1
LET PINS = %00000110
Case 2
LET PINS = %01011011
Case 3
LET PINS = %01001111
case 4
LET PINS = %01100110
Case 5
LET PINS = %01101101
Case 6
LET PINS = %01111101
Case 7
LET PINS = %00000111
Case 8
LET PINS = %01111111
Case 9
LET PINS = %01101111
Else
Pins = %00000000
EndSelect
Return
I see perfectly the numbers!
Now, to see both numbers? My problem is here.
 

giac77

New Member
The big problem was that the numbers were not displayed correctly.
So, I have added an instruction to shut down all outputs that drive the displays. See below:

'*********************************
'* test display - count-up 0-999 *
'*********************************

'--------------------------
' SETTING
'--------------------------

setfreq m8 'setto la frequenza a 8 MHZ

let b0 = 0
let b1 = 0
let b2 = 0

let pins = %00000000

high portc 7
high portc 6
high portc 5
high portc 4


'--------------------------
' START PROGR
'--------------------------

main:

'if portc pin0 = 1 then goto incrementa


for b6 = 0 to 9
for b5 = 0 to 9
for b4 = 0 to 9

pause 5 'aggiusto il ritardo

for b7 = 1 to 62 '62 loop - 1sec count-up

gosub cent
pause 1

let pins = %00000000 'spengo le uscite per evitare interferenze
pause 1


gosub decine
pause 1

let pins = %00000000 'spengo le uscite per evitare interferenze
pause 1


gosub unita
pause 1

let pins = %00000000 'spengo le uscite per evitare interferenze
pause 1


next b7

next b4
next b5
next b6


let pins = %00000000

low portc 7
low portc 6
low portc 5
low portc 4

pause 1000
let pins = %00000000
pause 1000
let pins = %10101010
pause 1000
let pins = %00000000
pause 1000
let pins = %10101010
pause 1000
let pins = %00000000

goto main









'----------------------------------
'- VISUALIZZA UNITA -
'----------------------------------


unita:

high portc 7
high portc 6
low portc 5
high portc 4


select case b4

case 0
LET PINS = %00111111

case 1
LET PINS = %00000110

case 2
LET PINS = %01011011

case 3
LET PINS = %01001111

case 4
LET PINS = %01100110

case 5
LET PINS = %01101101

case 6
LET PINS = %01111101

case 7
LET PINS = %00000111

case 8
LET PINS = %01111111

case 9
LET PINS = %01101111



endselect
return

'-----------------------------------
'- VISUALIZZA DECINE -
'-----------------------------------


decine:

high portc 7
low portc 6
high portc 5
high portc 4


select case b5

case 0
LET PINS = %00111111

case 1
LET PINS = %00000110

case 2
LET PINS = %01011011

case 3
LET PINS = %01001111

case 4
LET PINS = %01100110

case 5
LET PINS = %01101101

case 6
LET PINS = %01111101

case 7
LET PINS = %00000111

case 8
LET PINS = %01111111

case 9
LET PINS = %01101111

Else
Pins = %00000000

endselect
return


cent:

low portc 7
high portc 6
high portc 5
high portc 4


select case b6

case 0
LET PINS = %00111111

case 1
LET PINS = %00000110

case 2
LET PINS = %01011011

case 3
LET PINS = %01001111

case 4
LET PINS = %01100110

case 5
LET PINS = %01101101

case 6
LET PINS = %01111101

case 7
LET PINS = %00000111

case 8
LET PINS = %01111111

case 9
LET PINS = %01101111

Else
Pins = %00000000

endselect
return
 

inglewoodpete

Senior Member
Hi Giacomo, I have been away for a few days.

Next, try counting 0 - 9 on the other 7-segment display by changing part of the code:

Code:
unita:

high portc 7
Low portc 6    'Temporary test
High portc 5    'Temporary test
high portc 4
Does that make the other 7-segment digit count 0 - 9?
 
Top