'PIC 16F877A
Define OSC 16 'oscillator 16 MHz, HS mode
adcon1 = 6 'make ports digital I/O
alloff con %11111111 'all cathodes off
allon con %00000000 'all cathodes on
cubeoff con %00001111 'all anodes off
layer0 con %00001110 'layer 0 Floor enabled
layer1 con %00001101 'layer 1 enabled
layer2 con %00001011 'layer 2 enabled
layer3 con %00000111 'layer 3 Top enabled
x var byte 'x,z general variables
z var byte
a var byte [8] 'array variable stores current frame data for LED cathodes
frame var byte 'single frame repetition rate variable
trisb = 0 'portb, pord connects to cathode, portc connects to anode
trisd = 0
trisc = 0
portc = cubeoff 'disable all layers (pnp drivers)
portd = alloff 'initialize all cathode driving ports to off condition
portb = alloff
inout: 'inout pattern - a subset square and outermost square turn on alternately
frame = 24 'set frame repetition rate
a[0] = %11111111 'set initial frame data
a[1] = %11111111
a[2] = %10011111
a[3] = %11111001
a[4] = %10011111
a[5] = %11111001
a[6] = %11111111
a[7] = %11111111
inouti: 'main loop of pattern
gosub frameout 'ouput current frame
for z = 0 to 7 'invert frame data to interchange squares
a[z] = ~a[z]
next z
goto inouti 'go back to main loop
frameout: 'main frame out subroutine
for x = 0 to frame 'display pattern as per set frame repetition rate
portd = a[0] 'set ports connected to cathode pins for Layer 0 frame data
portb = a[1]
portc = layer0 'enable layer 0 anodes
pause 4 'pause for layer on time - set refresh rate to avoid flickering
portc = cubeoff 'disable all layers while changing cathode data from one layer to another
portd = a[2] 'set ports connected to cathode pins for Layer 1 frame data
portb = a[3]
portc = layer1 'enable layer 1 anodes
pause 4 'pause for layer on time - set refresh rate to avoid flickering
portc = cubeoff 'disable all layers while changing cathode data from one layer to another
portd = a[4] 'set ports connected to cathode pins for Layer 2 frame data
portb = a[5]
portc = layer2 'enable layer 2 anodes
pause 4 'pause for layer on time - set refresh rate to avoid flickering
portc = cubeoff 'disable all layers while changing cathode data from one layer to another
portd = a[6] 'set ports connected to cathode pins for Layer 3 frame data
portb = a[7]
portc = layer3 'enable layer 3 anodes
pause 4 'pause for layer on time - set refresh rate to avoid flickering
portc = cubeoff 'disable layers while changing cathode data from one layer to another
next x
return 'return to main program
end