Code:
'======= FUSES ====================================================================================
' PIC 16F690 Fuses
' Internal oscillator (activate OSCCON register)
@ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
@ ERRORLEVEL -306
@ ERRORLEVEL -202
'-------------------------------------------------------------------------------
' Registers 76543210
OPTION_REG = %10000000 'PORT A&B Pull-Ups disabled (look WPUA & WPUB)
OSCCON = %01110000 'Internal RC set to 8Mhz
ANSEL = %00000000 'Analog inputs Channels 0 to 7
ANSELH = %00000000 'Analog inputs Channels 8 to 11
WPUA = %00000000 'Weak pull-ups
WPUB = %00000000 'Weak pull-ups
ADCON0 = %00000000 'A/D Module (OFF)
CM1CON0 = %00000000 'Comparator1 Module (OFF)
CM2CON0 = %00000000 'Comparator2 Module (OFF)
INTCON = %00000000 'INTerrupts CONtrol
TRISA = %00000000 'Set Input/Output (0 to 5)
PORTA = %00000000 'Ports High/Low (0 to 5)
TRISB = %00000000 'Set Input/Output (4 to 7)
PORTB = %00000000 'Ports High/Low (4 to 7)
TRISC = %00000000 'Set Input/Output (0 to 7)
PORTC = %00000000 'Ports High/Low (0 to 7)
' ====== DEFINES ==================================================================================
define OSC 8
DEFINE NO_CLRWDT 1
' ====== VARIABLES ================================================================================
ADDRESS var word ' display's address
DATAREG var word ' display's data register
Y VAR BYTE ' just a counter
X var BYTE ' horizontal scroll steps counter
DES VAR BYTE
ScrollSpeed var word ' pause time
Letter_Cnt VAR BYTE ' caracter to be displayed
CLK VAR PORTB.4 ' connected to module's CLK
LOAD VAR PORTB.5 ' connected to module's CS
DAT VAR PORTB.6 ' connected to module's DIN
' ====== INITIALIZE ===============================================================================
low clk
low dat
low load 'CS
ScrollSpeed = 400
Letter_Cnt = 1
' ====== MAX7219 SETUP ============================================================================
ADDRESS = $0C : DATAREG = $01 : gosub MaxWrite ' SHUTDOWN=0, NORMAL OPERATION=1
ADDRESS = $09 : DATAREG = $00 : gosub MaxWrite ' DECODE-MODE, NO DECODE
ADDRESS = $0A : DATAREG = $00 : gosub MaxWrite ' LEDS INTENSITY MIN=0, MAX=F
ADDRESS = $0B : DATAREG = $07 : gosub MaxWrite ' NUMBER OF DISPLAYED LINES
ADDRESS = $0F : DATAREG = $00 : gosub MaxWrite ' DISPLAY-TEST (0=OFF, 1=ON)
GOSUB CLEAR_ALL
' ====== PROGRAM ==================================================================================
INIT:
'FOR Letter_Cnt = 1 to 2
' FOR Y = 0 TO 7
' IF Letter_Cnt = 1 THEN lookup y,[ 0, 36, 36, 60, 36, 36, 24, 0],datareg ' A
' IF Letter_Cnt = 2 THEN lookup y,[ 0, 28, 36, 36, 28, 36, 28, 0],datareg ' B
' ADDRESS = Y + 1
' GOSUB MAXWRITE
' PAUSE 10
' NEXT Y
' PAUSE ScrollSpeed
'NEXT Letter_Cnt
'GOTO INIT
des = 0
for x = 0 to 6
for y = 0 to 6
lookup y,[ 0, 36, 36, 60, 36, 36, 24, 0],datareg ' A
address = y+1
datareg = datareg >> des
gosub maxwrite
pause 10
next y
pause ScrollSpeed
des = des + 1
next x
des = 0
for x = 0 to 6
for y = 0 to 6
lookup y,[ 0, 28, 36, 36, 28, 36, 28, 0],datareg ' B
address = y+1
datareg = datareg >> des
gosub maxwrite
pause 10
next y
pause ScrollSpeed
des = des + 1
next x
GOSUB CLEAR_ALL
GOTO INIT
END
' ====== SUBROUTINES ==============================================================================
MaxWrite:
shiftout DAT,CLK,1,[ADDRESS,DATAREG] 'Shift out the data to the 'MAX7219 'first the address, then data.
pulsout LOAD,1 'load the data into the MAX7219
PAUSE 10
return
CLEAR_ALL:
for Y = 1 to 7 'write $0F (blank) to all digits
ADDRESS = Y
DATAREG = $00
gosub MaxWrite
next Y
return
'Letter A single dots (HEX 0024243c24241800)
' 0, 36, 36, 60, 36, 36, 24, 0
'Letter B single dots (HEX 001c24241c241c00)
' 0, 28, 36, 36, 28, 36, 28, 0
'Letter C single dots (HEX 0018240404241800)
' 0, 24, 36, 4, 4, 36, 24, 0
Bookmarks