Hello, I tested the Phil code is ok, very good code. I changed the Phil code to not shifting number on display because the original code is shifting when increase any number. On below code is the new change but it add a intercalary digit among all digit.
This code is a counter, start 0 to 255, this counter is ok but with intercalary digit in all display.
'************************************************* ***************
'* Name : TM1640_by_Phil.BAS *
'* Author : Phil (Sherbrook) *
'* Notice : Copyright (c) 2013 Phil (Sherbrook) *
'* : All Rights Reserved *
'* Date : 23/8/2013 *
'* Version : 1.0 *
'* Notes : http://www.picbasic.co.uk/forum/ *
'* : showthread.php?t=18239 *
'************************************************* ***************
' PIC18F2550 @ 48mHz with USB bootloader
DEFINE OSC 48
Define RESET_ORG 1000h
dat_com_inc var byte 'Display command for auto inc address
dat_com_fix var byte 'Display command for fixed address
dis_com_off var byte 'Display command OFF
dis_com_on var byte 'Display command ON
address var byte 'Display address
brightness var byte 'Brightness value (0 - 7)
dat var byte 'Data to send to TM1640
digit var byte '7 seg display (0 - 15)
n var byte 'Counter
Number var byte 'Number to write
seed var byte ' Cont 0 to 255
seedTmp var byte ' Save last Seed Number
vDigite00 var byte
vDigite01 var byte
vDigite02 var byte
vDigite03 var byte
vDigite04 var byte
vDigite05 var byte
vDigite06 var byte
vDigite07 var byte
vDigite08 var byte
vDigite09 var byte
vDigite10 var byte
vDigite11 var byte
vDigite12 var byte
vDigite13 var byte
vDigite14 var byte
vDigite15 var byte
dat_com_inc = %01000000 'Data command ADDRESS auto + 1 - 64
dat_com_fix = %01000100 'Data command FIXED address - 68
dis_com_off = %10000000 'Switch display OFF - 128
dis_com_on = %10001000 'Switch display ON - 136
brightness = %00000000 'Display brightness (0 = MIN 7 = MAX) - 3
address = %11000000 'Display ADDRESS $00 - 192
din var LATB.1
sclk var LATB.0
LED1 var PORTA.5
TRISC = %00111000 'Input/Output config Pin
LATC = 0
TRISB = %11111100 'Input/Output config Pin
din = 1 'Data pin HIGH to start
sclk = 1 'Clock pin HIGH to start
seed = 0
'----------------- DIGITS ---------------------------------------
vDigite00 = 16
vDigite01 = 16
vDigite02 = 16
vDigite03 = 16
vDigite04 = 16
vDigite05 = 16 ' Blank Digit
vDigite06 = 16
vDigite07 = 16
vDigite08 = 16
vDigite09 = 16
vDigite10 = 16 ' Blank Digit
vDigite11 = 16
vDigite12 = 16
'vDigite13 = 0
'vDigite14 = 0
'vDigite15 = 0
'---------- Start of program ------------------------------------
main:
gosub CMDSENDDIGIT
toggle led1
pause 20
seed = seed + 1
goto main:
'----------------------------------------------------------------
COMMAND:
din = 0 ': PAUSE 1 'Start transmission
sclk = 0 ': PAUSEUS 10
SHIFTOUT din,sclk,0,[dat] 'Mode 0 - LSB first, Clock idle low
'PAUSEUS 10
sclk = 0
'PAUSEUS 10
din = 0 'End transmission
'PAUSE 10
RETURN
CMDSENDDIGIT:
FOR n = 0 to 15 'Print 16 characters
gosub CMDNUMBER
dat = address + (n+1) 'Set address to 1st 7seg display
GOSUB COMMAND 'Do it
din = 0 ': PAUSE 1
sclk = 0 ': PAUSEUS 10 'Start transmission process
Lookup number,[$3F,$6,$5B,$4F,$66,$6D,$7D,$7,$7F,$67,$77,$7C,$58, $5E,$79,$71,0],dat
SHIFTOUT din,sclk,0,[dat] 'Print message
NEXT
'PAUSEUS 10' :
sclk = 1
'PAUSEUS 10' :
din = 1 'End transmission process
' PAUSE 10
dat = dis_com_on + brightness 'Set brightness
GOSUB COMMAND
return
CMDNUMBER:
select case n
case 0
number = vDigite00
case 1
number = vDigite01
case 2
number = vDigite02
case 3
number = vDigite03
case 4
number = vDigite04
case 5
number = vDigite05
case 6
number = vDigite06
case 7
number = vDigite07
case 8
number = vDigite08
case 9
number = vDigite09
case 10
number = vDigite10
case 11
number = vDigite11
case 12
number = vDigite12
case 13
'number = vDigite13
number = seed DIG 2
case 14
'number = vDigite14
number = seed DIG 1
case 15
'number = vDigite15
number = seed DIG 0
end select
return
end
'----------------------------------------------------------------
See the below picture for better understanding.
Regards,
Bookmarks