REM Test Program, Driving a 7-segment display directly from a Picaxe-14M2 using PortB and PortC
REM June 2026, Jurjen Kranenborg
#Picaxe 14m2
REM Definitions:
REM ------------
REM Main Input/output signals for this project:
SYMBOL Outputs_B = %00111111
SYMBOL Outputs_C = %00000001
LET dirsB = Outputs_B
LET dirsC = Outputs_C
REM Register naming:
SYMBOL number = b0
REM ===================
REM Main Program:
REM Test 7Seg Display: count 0 - 9
REM and toggle the decimal point
REM ===================
DO
FOR number = 0 TO 9
CALL ShowNumber_7Seg
PAUSE 500
TOGGLE Kdp
PAUSE 500
TOGGLE Kdp
NEXT number
LOOP
END
REM Subroutine, variable "number" to be shown
ShowNumber_7Seg:
REM ------------
REM: 7-Seg Display definitions (Common Anode Display)
SYMBOL Kg = C.0
SYMBOL Kf = B.0
SYMBOL Ka = B.1
SYMBOL Kb = B.2
SYMBOL Kc = B.3
SYMBOL Kd = B.4
SYMBOL Ke = B.5
SYMBOL Kdp = C.1
REM ------------
REM EEPROM adresses:
SYMBOL B_7Seg = 0
SYMBOL C_7Seg = 10
REM Define connections portB (6x) and portC (1x) on 14m2 to 7-seg display
REM In this example a CA (Common Anode) display has been used (0=On, 1=Off)
REM Kdp (digital Point) can be manipulated independently from this routine (happens in the main program)
REM Below, B-channel wiring: %00edcbaf:
EEPROM B_7Seg, (%00000000, %00110011, %00001001, %00100001, %00110010) '0-4
EEPROM (%00100100, %00000100, %00110001, %00000000, %00100000) '5-9
REM Below, C-channel wiring: %0000000g:
EEPROM C_7Seg, (%00000001, %00000001, %00000000, %00000000, %00000000) '0-4
EEPROM (%00000000, %00000000, %00000001, %00000000, %00000000) '5-9
SYMBOL j = b1
SYMBOL data_7Seg_B = b2
SYMBOL data_7Seg_C = b2 'identical register for portC as for portB, but separate naming for clarity
SYMBOL acc_C = b3 'accumulator/data manipulation register for port setting
' Read 7-seg connection data from eeprom
' ... first the PortB part
LET j = B_7Seg + number
READ j, data_7Seg_B
' ... and write it to the display:
LET pinsB = data_7Seg_B
' ... then the PortC part, only altering here the 7-seg bit (Kg on C.0), keeping the other output pins' statuses on this port as they were
LET j = C_7Seg + number
READ j, data_7Seg_C
LET acc_C = pinsC AND %11111110 'First read the current status for portC, copy status of all bits (including Kdp) except Kg
' ... and write it to the display:
LET pinsC = acc_C OR data_7Seg_C 'set all output pins again (defined by dirsC settings), now including 7-seg bit Kg
RETURN