kranenborg
Senior Member
The small but powerful PICAXE-14M2 only has 6 pins on port B and C, so both ports must be used for a simple direct (non-multiplexed) 7-Seg display connection.
The following subroutine allows this (6 leds on Port B, 1 led on port C) whilst respecting the input/output functions on the remaining lines of Port C.
In this way also a small 14M2 can be used in small, low-component count projects requiring both a 7-seg display as well as several other input/output/interrupt lines!
Subroutine code:
The following subroutine allows this (6 leds on Port B, 1 led on port C) whilst respecting the input/output functions on the remaining lines of Port C.
In this way also a small 14M2 can be used in small, low-component count projects requiring both a 7-seg display as well as several other input/output/interrupt lines!
Subroutine code:
Code:
REM Declarations/definitions needed in Main Program:
REM ===========================
REM 7-Seg Display definitions:
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
SYMBOL B_7Seg = 0 'EEPROM locations for Port B display data (numbers 0 - 10)
SYMBOL C_7Seg = 11 'EEPROM locations for Port C display data (numbers 0 - 10)
REM Output line definitions (for display part only, alter Outputs_C if more output connections are needed):
SYMBOL Outputs_B = %00111111
SYMBOL Outputs_C = %00000001 'Currenty only display led Kg defined as output, add here more if needed
LET dirsB = Outputs_B
LET dirsC = Outputs_C
REM Register naming:
SYMBOL number = b0
REM ===========================
ShowNumber_7Seg:
REM ************************************************************************
REM Subroutine to use a 7-seg LED-display with a Picaxe-14M2, this requires
REM both full Port B (all 6 pins) and 1 pin of Port C
REM but does not sacrifice/influence other input/output connections on port C!
REM (by respecting the settings for dirs.C, SETINT etc. etc.).
REM ************************************************************************
REM
REM How this subroutine works:
REM - First writes 6 out of the 7 segments on Port B (Port B has only 6 elements on 14M2)
REM - Reads the full input /output status of Port C
REM - Sets the status of the 7th segment (Kg) appropriately on Port C
REM - Writes full Port C, including 7th segment bit, so that the latter is mapped properly on Port C
REM Use of this subroutine:
REM 1. Put the value to be shown in a byte variable "number" (a value of 10 means "display off")
REM 2. Call the subroutine!
REM
REM --> In this example a CA (Common Anode) display has been used (0=ON, 1=OFF in the EEPROM data),
REM for a CC (Common Cathode) display just reverse 0/1
REM Note that the Decimal Point (Kdp) can be manipulated independently from this routine (HIGH/LOW/TOGGLE etc.)
REM
REM Hardware connection definition between picaxe and 7-seg display
REM Below data defines the hardware digit connection scheme for Channel B: element seq. %00edcbaf:
EEPROM B_7Seg, (%00000000, %00110011, %00001001, %00100001, %00110010) '0-4
EEPROM (%00100100, %00000100, %00110001, %00000000, %00100000) '5-9
EEPROM (%00111111) '10 (= display off)
REM Below data defines the hardware digit connection scheme for Channel C - element g only: %0000000g:
EEPROM C_7Seg, (%00000001, %00000001, %00000000, %00000000, %00000000) '0-4
EEPROM (%00000000, %00000000, %00000001, %00000000, %00000000) '5-9
EEPROM (%00000001) '10 (= display off)
REM Register definitions:
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 ' look up EEPOROM address of 7-seg coding for the number
READ j, data_7Seg_B ' and read it
LET pinsB = data_7Seg_B ' and set it
' ... then the PortC part, only altering here the 7-seg bit, keeping the other output pins' statuses
LET j = C_7Seg + number
READ j, data_7Seg_C
' ... and write it to the display:
LET acc_C = pinsC AND %11111110 'First read the current status for portC, copy status of all bits (including Kdp) except Kg
LET pinsC = acc_C OR data_7Seg_C 'set all output pins again (defined by dirsC settings), now including 7-seg bit Kg
RETURN
Last edited: