Scroll text on 4 seven-segment digits
The example use two main libraries: seven_segment.jal for code numbers and letters, and timer0_isr_interval.jal for multitasking simulation. The movie below does not illustrate the last version of the program, so, the "ghost" effect is still obvious. Maybe I'll update the movie some day...
The scrolled text is: "HELLO JOEP AND VASILE _ THIS USE Your LibrArY"
Click on image to zoom
Digit schematic (both digit select and segment select active on 0 logic). Also, on my board(EvB 4.3), the 8 LEDs are active on 0 logic (common anode) but on your board can be common cathode if you want.
Click on image to zoom
The free terminals of the LEDs and transistors are connected to Vcc. I don't know the values of resistors from transistors base and segments (are SMD on my board) but for LEDs you can have values between 330R and 470R. As you can see, no pin has remained free on the FreeJALduino board ([Analog 5] and [AREF] pins are not connected) so, dot segments are left unconnected.
The code:
-- Scroll text on 4 seven_segment digits using
-- FreeJALduino and EvB 4.3 boards.
-- Copyright Vasile Guta Ciucur
-- New BSD License
include freejalduino4
const bit seven_segment_common_anode = true
include seven_segment
include delay
const dword timer0_isr_rate = 1000 -- 1 kHz isr rate
const DELAY_SLOTS = 2 -- one timing for scroll speed and another
-- for blinking LED's
include timer0_isr_interval
-- DECLARATIONS
-- The text displayed: " HELLO JOEP AND VASILE _ THIS USE Your LibrArY "
-- See "seven_segment.jal" library for corresponding codes
const byte text_string[] = { --27 is "Space" character
27,27,27,19,14,21,21,0,27, -- HELLO
28,0,14,23,27, -- JOEP
10,29,13,27, -- And
24,10,16,1,21,14,27, -- UASILE
32,27, -- _
7,19,1,16,27, -- THIS
24,16,14,27, -- USE
4,22,26,18,27, -- Your
21,20,11,18,10,18,4,27,27,27} -- LibrArY
-- the sequence for LED's
const byte leds_sequence[] = {
0,1,3,7,15,31,63,127,255,254,252,248,240,224,192,128,0,; complete sequence
128,192,224,240,248,252,255,127,63,31,15,7,3,1}; and reverse
-- the buffer for the 4 digits - the data contained here is
-- permanently displayed on digits.
var byte digits_buffer[4]
-- indices
var byte ix_text
var byte ix_led
procedure PORTTEXT'put(byte in x) is
var volatile bit x_0 at x:0
var volatile bit x_1 at x:1
var volatile bit x_2 at x:2
var volatile bit x_3 at x:3
var volatile bit x_4 at x:4
var volatile bit x_5 at x:5
var volatile bit x_6 at x:6
D3 = x_0
D4 = x_1
D5 = x_2
D6 = x_3
D7 = x_4
D8 = x_5
D9 = x_6
end procedure
procedure show_digits is
PORTTEXT = seven_from_digit(27)
portA_low = 7 -- 0b0111, digits are selectable with a 0 logic on my board
PORTTEXT = digits_buffer[3]
delay_10us(150)
--
PORTTEXT = seven_from_digit(27)
portA_low = 11 -- 0b1011
PORTTEXT = digits_buffer[2]
delay_10us(150)
--
PORTTEXT = seven_from_digit(27)
portA_low = 13 -- 0b1101
PORTTEXT = digits_buffer[1]
delay_10us(150)
--
PORTTEXT = seven_from_digit(27)
portA_low = 14 -- 0b1110
PORTTEXT = digits_buffer[0]
delay_10us(150)
--
end procedure
procedure update_buffer(byte in id) is
digits_buffer[3] = seven_from_digit(text_string[id])
digits_buffer[2] = seven_from_digit(text_string[id + 1])
digits_buffer[1] = seven_from_digit(text_string[id + 2])
digits_buffer[0] = seven_from_digit(text_string[id + 3])
end procedure
procedure PORTLED'put(byte in x) is
var volatile bit x_0 at x:0
var volatile bit x_1 at x:1
var volatile bit x_2 at x:2
var volatile bit x_3 at x:3
var volatile bit x_4 at x:4
var volatile bit x_5 at x:5
var volatile bit x_6 at x:6
var volatile bit x_7 at x:7
D0 = x_0
D1 = x_1
D2 = x_2
D10 = x_3
D11 = x_4
D12 = x_5
D13 = x_6
D18 = x_7
end procedure
-- START = Ready, Steady, GO!
-- Initializations
timer0_isr_init() -- init timer0 isr
enable_digital_io()
portA_direction = Output
portB_direction = Output
portC_direction = Output
-- digits OFF
portA_low = 0b1111
-- init index
ix_text = 0
ix_led = 0
-- fill the digits buffer
update_buffer(ix_text)
-- start LED sequence
PORTLED = leds_sequence[ix_led]
-- set scroll speed for text
set_delay(0, 300)
-- set scroll speed for LED's
set_delay(1, 100)
forever loop
show_digits
if check_delay(0) then
ix_text = ix_text + 1
if ix_text == 48 then
ix_text = 0
end if
update_buffer(ix_text)
set_delay(0, 300)
end if
if check_delay(1) then
ix_led = ix_led + 1
if ix_led == 31 then
ix_led = 0
end if
PORTLED = leds_sequence[ix_led]
set_delay(1, 100)
end if
end loop