The link for the video is here -
http://www.youtube.com/watch?v=S2ARe1bBN-0
I can't post the whole code as theres alot of animation data but I will try my best.
Code: Select all
// Name of Program
Program PacMan_animation // useful for documentation purposes
// Device and Clock
Device = 18F4685 // Tell the compiler what chip we are using
Clock = 20 // Tell the compiler what we will be setting the clock to (Mhz)
Config MCLRE = ON
// default fuses...
Config
OSC = HS,
FCMEN = OFF,
IESO = OFF,
PWRT = ON,
BOREN = BOACTIVE,
WDT = OFF,
WDTPS = 128,
PBADEN = OFF,
DEBUG = OFF,
XINST = OFF,
LVP = OFF,
STVREN = ON
// Modules
Include "Utils.bas" // Include this file when we compile so that we can use keywords like "SetAllDigital"
// Const Arrays
// Anodes if we are using ULN2803 Chips (common-cathode Darlington transistor array.)
Const Anode_data(8) As Byte = (%10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001)
// Setup ALL our PORTS
Dim E_ALL_74573 As PORTC.6 ' setup ALL 74573 enable pins
Dim L_RedB0_74573 As PORTC.4 ' setup our RED CATHODE 74573 latch pin
Dim L_RedB1_74573 As PORTC.0 ' setup our RED CATHODE 74573 latch pin
Dim L_RedB2_74573 As PORTC.1 ' setup our RED CATHODE 74573 latch pin
Dim L_GreenB0_74573 As PORTC.2 ' setup our GREEN CATHODE 74573 latch pin
Dim L_GreenB1_74573 As PORTC.3 ' setup our GREEN CATHODE 74573 latch pin
Dim L_GreenB2_74573 As PORTC.5 ' setup our GREEN CATHODE 74573 latch pin
Dim L_AnodeR0_74573 As PORTE.0 ' setup our ANODE 74573 latch pin
Dim L_AnodeR1_74573 As PORTE.1 ' setup our ANODE 74573 latch pin
Dim L_AnodeR2_74573 As PORTE.2 ' setup our ANODE 74573 latch pin
Dim Anode_port As PORTB ' Anode DATA PORT
Dim Graphic_port As PORTD ' Graphic DATA PORT (green and red)
' when latch pin = high then data can be latched, when latch pin = low data cannot be stored
' when enable pin = high outputs OFF, when enable pin = low outputs ON
Then lastly I define all my PORT BITS which control all my 'D' type Latch 74573's. Im using nine 74573's in total, 3 to control all the GREEN cathodes and 3 to control all the RED cathodes and 3 to control all the Anodes, and then set PORTB as my Anode control bus and PORTD as my graphic (cathode) bus, I could have used just one port for all my data bus.
Code: Select all
// Variable Declarations
Dim x As Byte
Dim t As Word
Dim counter As Word
Dim block_0_green(8) As Byte
Dim block_0_red(8) As Byte
Dim block_1_green(8) As Byte
Dim block_1_red(8) As Byte
Dim block_2_green(8) As Byte
Dim block_2_red(8) As Byte
Dim block_3_green(8) As Byte
Dim block_3_red(8) As Byte
Dim block_4_green(8) As Byte
Dim block_4_red(8) As Byte
Dim block_5_green(8) As Byte
Dim block_5_red(8) As Byte
Dim block_6_green(8) As Byte
Dim block_6_red(8) As Byte
Dim block_7_green(8) As Byte
Dim block_7_red(8) As Byte
Dim block_8_green(8) As Byte
Dim block_8_red(8) As Byte
Dim display_step As Word
Code: Select all
// Subroutines ====
Sub update_ram_data()
Select display_step
Case 0
block_0_red(0) = $00
block_0_red(1) = $00
block_0_red(2) = $00
block_0_red(3) = $00
block_0_red(4) = $00
block_0_red(5) = $00
block_0_red(6) = $00
block_0_red(7) = $00
block_0_green(0) = $00
block_0_green(1) = $00
block_0_green(2) = $00
block_0_green(3) = $00
block_0_green(4) = $00
block_0_green(5) = $00
block_0_green(6) = $00
block_0_green(7) = $00
block_1_red(0) = $00
block_1_red(1) = $00
block_1_red(2) = $00
block_1_red(3) = $00
block_1_red(4) = $00
block_1_red(5) = $00
block_1_red(6) = $00
block_1_red(7) = $00
block_1_green(0) = $00
block_1_green(1) = $00
block_1_green(2) = $00
block_1_green(3) = $00
block_1_green(4) = $00
block_1_green(5) = $00
block_1_green(6) = $00
block_1_green(7) = $00
block_2_red(0) = $00
block_2_red(1) = $00
block_2_red(2) = $00
block_2_red(3) = $00
block_2_red(4) = $00
block_2_red(5) = $00
block_2_red(6) = $00
block_2_red(7) = $00
block_2_green(0) = $00
block_2_green(1) = $00
block_2_green(2) = $00
block_2_green(3) = $00
block_2_green(4) = $00
block_2_green(5) = $00
block_2_green(6) = $00
block_2_green(7) = $00
block_3_red(0) = $00
block_3_red(1) = $00
block_3_red(2) = $00
block_3_red(3) = $00
block_3_red(4) = $00
block_3_red(5) = $00
block_3_red(6) = $00
block_3_red(7) = $00
block_3_green(0) = $00
block_3_green(1) = $00
block_3_green(2) = $00
block_3_green(3) = $00
block_3_green(4) = $00
block_3_green(5) = $00
block_3_green(6) = $00
block_3_green(7) = $00
block_4_red(0) = $00
block_4_red(1) = $00
block_4_red(2) = $00
block_4_red(3) = $00
block_4_red(4) = $00
block_4_red(5) = $00
block_4_red(6) = $00
block_4_red(7) = $00
block_4_green(0) = $00
block_4_green(1) = $00
block_4_green(2) = $00
block_4_green(3) = $01
block_4_green(4) = $01
block_4_green(5) = $00
block_4_green(6) = $00
block_4_green(7) = $00
block_5_red(0) = $00
block_5_red(1) = $00
block_5_red(2) = $00
block_5_red(3) = $00
block_5_red(4) = $00
block_5_red(5) = $00
block_5_red(6) = $00
block_5_red(7) = $00
block_5_green(0) = $00
block_5_green(1) = $00
block_5_green(2) = $00
block_5_green(3) = $b6
block_5_green(4) = $b6
block_5_green(5) = $00
block_5_green(6) = $00
block_5_green(7) = $00
block_6_red(0) = $00
block_6_red(1) = $00
block_6_red(2) = $00
block_6_red(3) = $00
block_6_red(4) = $00
block_6_red(5) = $00
block_6_red(6) = $00
block_6_red(7) = $00
block_6_green(0) = $00
block_6_green(1) = $00
block_6_green(2) = $00
block_6_green(3) = $00
block_6_green(4) = $00
block_6_green(5) = $00
block_6_green(6) = $00
block_6_green(7) = $00
block_7_red(0) = $00
block_7_red(1) = $00
block_7_red(2) = $00
block_7_red(3) = $00
block_7_red(4) = $00
block_7_red(5) = $00
block_7_red(6) = $00
block_7_red(7) = $00
block_7_green(0) = $00
block_7_green(1) = $00
block_7_green(2) = $00
block_7_green(3) = $00
block_7_green(4) = $00
block_7_green(5) = $00
block_7_green(6) = $00
block_7_green(7) = $00
block_8_red(0) = $00
block_8_red(1) = $00
block_8_red(2) = $00
block_8_red(3) = $00
block_8_red(4) = $00
block_8_red(5) = $00
block_8_red(6) = $00
block_8_red(7) = $00
block_8_green(0) = $00
block_8_green(1) = $00
block_8_green(2) = $00
block_8_green(3) = $00
block_8_green(4) = $00
block_8_green(5) = $00
block_8_green(6) = $00
block_8_green(7) = $00
Code: Select all
Case 1
block_0_red(3) = $80
block_0_red(4) = $80
block_0_green(3) = $80
block_0_green(4) = $80
block_6_red(3) = $80
block_6_red(4) = $80
block_6_green(3) = $80
block_6_green(4) = $80
Case 2
block_0_red(2) = $80
block_0_red(3) = $e0
block_0_red(4) = $e0
block_0_red(5) = $c0
block_0_red(6) = $80
block_0_green(2) = $80
block_0_green(3) = $e0
block_0_green(4) = $e0
block_0_green(5) = $c0
block_0_green(6) = $80
block_6_red(1) = $80
block_6_red(2) = $c0
block_6_red(3) = $e0
block_6_red(4) = $e0
block_6_red(5) = $80
block_6_green(1) = $80
block_6_green(2) = $c0
block_6_green(3) = $e0
block_6_green(4) = $e0
block_6_green(5) = $80
Code: Select all
Case 64
block_2_green(5) = %00000000
block_2_green(6) = %00000000
block_2_green(7) = %00000000
block_5_green(0) = %00000000
block_5_green(1) = %00000001
block_5_green(2) = %00000001
block_5_green(3) = %00000001
block_5_green(4) = %00000001
block_5_green(5) = %00000001
block_5_green(6) = %00000001
block_5_green(7) = %00000001
block_8_green(0) = %00000001
block_8_green(1) = %00000001
block_8_green(2) = %00000001
block_8_green(3) = %00000001
block_8_green(4) = %00000001
block_8_green(5) = %00000001
block_8_green(6) = %00000001
EndSelect
// this is our count of frames
// increment by 1
display_step = display_step + 1
// if we get to end, reset to 0
If display_step = 64 Then ' change the number of steps
display_step = 0
EndIf
High (E_ALL_74573) ' makes enable pin high (all outputs OFF)
Code: Select all
For t = 0 To 150 // t = time delay
For x = 0 To 7
//===================================================================================
' red data
High (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_0_red(x)
Low (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_3_red(x)
Low (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_6_red(x)
Low (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
//===================================================================================
' green data
High (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_0_green(x)
Low (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_3_green(x)
Low (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_6_green(x)
Low (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
//===================================================================================
' anodes data
High (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
Anode_port = Anode_data (x)
Low (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
High (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
High (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
Anode_port = $00
Low (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
Low (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
//===================================================================================
' Enable our Matrix
Low (E_ALL_74573) ' makes enable pin low (all outputs ON)
DelayUS(400)
High (E_ALL_74573) ' makes enable pin high (all outputs OFF)
' we now clear our Anode data to stop graphic ghosting
High (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
Anode_port = $00
Low (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
//===================================================================================
' red data
High (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_1_red(x)
Low (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_4_red(x)
Low (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_7_red(x)
Low (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
//===================================================================================
' green data
High (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_1_green(x)
Low (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_4_green(x)
Low (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_7_green(x)
Low (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
//===================================================================================
' anodes data
High (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
High (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
Anode_port = $00
Low (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
Low (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
High (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
Anode_port = Anode_data (x)
Low (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
//===================================================================================
' Enable our Matrix
Low (E_ALL_74573) ' makes enable pin low (all outputs ON)
DelayUS(400)
High (E_ALL_74573) ' makes enable pin high (all outputs OFF)
' we now clear our Anode data to stop graphic ghosting
High (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
Anode_port = $00
Low (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
//===================================================================================
' red data
High (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_2_red(x)
Low (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_5_red(x)
Low (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
Graphic_port = block_8_red(x)
Low (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
//===================================================================================
' green data
High (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_2_green(x)
Low (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_5_green(x)
Low (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
Graphic_port = block_8_green(x)
Low (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
//===================================================================================
' anodes data
Anode_port = Anode_data (x)
High (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
Low (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
Anode_port = $00
High (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
High (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
Low (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
Low (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
//===================================================================================
' Enable our Matrix
Low (E_ALL_74573) ' makes enable pin low (all outputs ON)
DelayUS(400)
High (E_ALL_74573) ' makes enable pin high (all outputs OFF)
' we now clear our Anode data to stop graphic ghosting
High (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
Anode_port = $00
Low (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
Next
Inc(t)
Next
End Sub
Code: Select all
// Set Ports
SetAllDigital // Make all Pins digital I/O's
TRISA = %11111111 // Make PORTA all inputs
TRISB = %00000000 // Make PORTB all outputs
TRISC = %00000000 // Make PORTC all outputs
TRISD = %00000000 // Make PORTD all outputs
TRISE = %00000000 // Make PORTE all outputs
PORTB = $00 ' clear all ports
PORTC = $00
PORTD = $00
PORTE = $00
// this clears all data in all 74573 data latches
High (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
High (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
High (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
High (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
High (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
High (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
// and this makes all outputs off
High (E_ALL_74573) ' makes enable pin high (all outputs OFF)
' make sure all our data latches are closed
Low (L_RedB0_74573) ' setup our RED CATHODE 74573 latch pin
Low (L_RedB1_74573) ' setup our RED CATHODE 74573 latch pin
Low (L_RedB2_74573) ' setup our RED CATHODE 74573 latch pin
Low (L_GreenB0_74573) ' setup our GREEN CATHODE 74573 latch pin
Low (L_GreenB1_74573) ' setup our GREEN CATHODE 74573 latch pin
Low (L_GreenB2_74573) ' setup our GREEN CATHODE 74573 latch pin
Low (L_AnodeR0_74573) ' setup our ANODE 74573 latch pin
Low (L_AnodeR1_74573) ' setup our ANODE 74573 latch pin
Low (L_AnodeR2_74573) ' setup our ANODE 74573 latch pin
// Initialize Variables
counter = 0
display_step = 0
// Main Program
While True()
update_ram_data
Wend
// end of program.
End
If you have any questions then just ask.