{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 8/4/2014 *
* Version : 1.0 *
* Notes : new revision by starting over and addressing the registers. *
* : *
*****************************************************************************
}
DEVICE = 18F2420
CLOCK = 20
INCLUDE "shift.bas"
INCLUDE "utils.bas"
INCLUDE "convert.bas"
' INCLUDE "DS18B20.bas"
INCLUDE "Utils.bas"
include "convert.bas"
//PIN DESCRIPTION
DIM Load_pin AS PORTC.5 // LATCH
DIM Data_pin AS PORTC.4 // DATA
DIM Clock_pin AS PORTC.3 // CLOCK
//DIM X AS BYTE
//DIM index AS WORD
DIM Display_Reg AS BYTE //register settings
DIM Display_Data AS BYTE // Data to be displayed
DIM Data_out AS WORD // Data for additional matrix (4)
{
// define max7219 registers
byte max7219_reg_noop = 0x00;
byte max7219_reg_digit0 = 0x01;
byte max7219_reg_digit1 = 0x02;
byte max7219_reg_digit2 = 0x03;
byte max7219_reg_digit3 = 0x04;
byte max7219_reg_digit4 = 0x05;
byte max7219_reg_digit5 = 0x06;
byte max7219_reg_digit6 = 0x07;
byte max7219_reg_digit7 = 0x08;
byte max7219_reg_decodeMode = 0x09;
byte max7219_reg_intensity = 0x0a;
byte max7219_reg_scanLimit = 0x0b;
byte max7219_reg_shutdown = 0x0c;
byte max7219_reg_displayTest = 0x0f;
}
//DIM Options(16) AS BYTE
//DIM I AS WORD
SUB Write_Matrix ()
Load_pin = 0
Data_out =256*Display_Reg+ Display_Data
shift.out (MSB_first,Data_out,16)
Load_pin =1
END SUB
PUBLIC SUB InitLed()
Display_Reg = 9 // decode
Display_Data = 0 //all
Write_Matrix // write to matrix
Display_Reg = 10 //intensity
Display_Data = 15 //max
Write_Matrix
Display_Reg = 11 //scan limit
Display_Data = 2
Write_Matrix
Display_Reg = 12 //shut down
Display_Data = 1
Write_Matrix
END SUB
PUBLIC SUB clear_display()
DIM I AS INTEGER
FOR I = 1 TO 3
Display_Reg = I
Display_Data = 0
Write_Matrix
NEXT
END SUB
public sub TestMode(Test as boolean)
if test = true then
Display_data = 1
Display_reg = %1111
write_matrix
else
Display_data = 0
Display_reg = %1111
write_matrix
end if
end sub
// PROGRAM CODE SET UP
setalldigital
shift.setoutput(Data_pin)
shift.setclock(clock_pin)
output(load_pin)
load_pin = 0
InitLed
Display_data = 1
Display_reg = %1111
write_matrix
delayms(500)
Display_data = 0
Display_reg = %1111
write_matrix
//InitLED 'sets up the registers
WHILE 1 = 1
Display_Reg = 1
Display_Data = %11111111
Write_Matrix
Display_Reg = 2
Display_Data = %00000111
Write_Matrix
Display_Reg = 3
Display_Data = %00000100
Write_Matrix
Display_Reg = 4
Display_Data= %00001000
Write_Matrix
Display_Reg = 5
Display_Data = %00010000
Write_Matrix
Display_Reg = 6
Display_Data= %00100000
Write_Matrix
Display_Reg = 7
Display_Data = %01000000
Write_Matrix
Display_Reg = 8
Display_Data= %10000000
Write_Matrix
DELAYMS(1000)
clear_display
DELAYMS(1000)
WEND
I changed to 7 because there are 8 leds.Why in the Init routine is the scan limit set to 2? What should it be set to?
we have 8 leds to clear out. I tried with original suggested settings and only some of the leds lit up. Only the first 3 colums.Why in the clear_display routine is I = 3? What should it be?
DEVICE = 18F2420
CLOCK = 20
INCLUDE "shift.bas"
INCLUDE "utils.bas"
INCLUDE "convert.bas"
' INCLUDE "DS18B20.bas"
INCLUDE "Utils.bas"
include "convert.bas"
//PIN DESCRIPTION
DIM Load_pin AS PORTC.5 // LATCH
DIM Data_pin AS PORTC.4 // DATA
DIM Clock_pin AS PORTC.3 // CLOCK
DIM X AS BYTE
//DIM index AS WORD
DIM Display_Reg AS BYTE //register settings
DIM Display_Data AS BYTE // Data to be displayed
DIM Data_out AS WORD // Data for additional matrix (4)
{
// define max7219 registers
byte max7219_reg_noop = 0x00;
byte max7219_reg_digit0 = 0x01;
byte max7219_reg_digit1 = 0x02;
byte max7219_reg_digit2 = 0x03;
byte max7219_reg_digit3 = 0x04;
byte max7219_reg_digit4 = 0x05;
byte max7219_reg_digit5 = 0x06;
byte max7219_reg_digit6 = 0x07;
byte max7219_reg_digit7 = 0x08;
byte max7219_reg_decodeMode = 0x09;
byte max7219_reg_intensity = 0x0a;
byte max7219_reg_scanLimit = 0x0b;
byte max7219_reg_shutdown = 0x0c;
byte max7219_reg_displayTest = 0x0f;
}
//DIM Options(16) AS BYTE
//DIM I AS WORD
SUB Write_Matrix ()
Load_pin = 0
Data_out =256*Display_Reg+ Display_Data
shift.out (MSB_first,Data_out,16)
Load_pin =1
END SUB
PUBLIC SUB InitLed()
Display_Reg = 9 // decode
Display_Data = 0 //all
Write_Matrix // write to matrix
Display_Reg = 10 //intensity
Display_Data = 8 //max
Write_Matrix
Display_Reg = 11 //scan limit
Display_Data = 7 // to scan entire matrix
Write_Matrix
Display_Reg = 12 //shut down
Display_Data = 1
Write_Matrix
END SUB
PUBLIC SUB clear_display()
DIM I AS INTEGER
FOR I = 1 TO 8 // for 8 colums
Display_Reg = I
Display_Data = 0
Write_Matrix
NEXT
END SUB
public sub TestMode(Test as boolean)
if test = true then
Display_data = 1
Display_reg = %1111
write_matrix
else
Display_data = 0
Display_reg = %1111
write_matrix
end if
end sub
// PROGRAM CODE SET UP
setalldigital
shift.setoutput(Data_pin)
shift.setclock(clock_pin)
output(load_pin)
load_pin = 0
InitLed
Display_data = 1
Display_reg = %1111
write_matrix
delayms(500)
Display_data = 0
Display_reg = %1111
write_matrix
//InitLED 'sets up the registers
WHILE 1 = 1
for x = 1 to 8
Display_Reg = x
Display_Data = %11111111
Write_Matrix
delayms(500)
DELAYMS(10)
clear_display
DELAYMS(10)
next
WEND
.... Have to change the scan limit for number of Max7219/matrix displays.....
shift.out (MSB_first,Data_out1,data_out2,32)
{
Sub WriteLED ()
LoadPin = 0
Data_Out = 256*LED_Reg + LED_Data
Shift.Out (MSB_FIRST, Data_Out, 16)
LoadPin = 1
End Sub
}
Sub WriteLED (Unit As Byte)
'This subroutine supports 4 MAX7219s in series
'Unit 1 is the first in the string, 4 is the last
LoadPin = 0
Select unit
Case = 1
data_out = 256* 0 + LED_Data ' no op
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 4
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 3
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 2
Data_Out = 256*LED_Reg + LED_Data 'data to unit 1
Shift.Out (MSB_FIRST, Data_Out, 16)
Case = 2
data_out = 256* 0 + LED_Data ' no op
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 4
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 3
Data_Out = 256*LED_Reg + LED_Data 'data to unit 2
Shift.Out (MSB_FIRST, Data_Out, 16)
data_out = 256* 0 + LED_Data ' no op
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 1
Case = 3
data_out = 256* 0 + LED_Data ' no op
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 4
Data_Out = 256*LED_Reg + LED_Data 'data to unit 3
Shift.Out (MSB_FIRST, Data_Out, 16)
data_out = 256* 0 + LED_Data ' no op
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 2
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 1
Case = 4
Data_Out = 256*LED_Reg + LED_Data 'data to unit 4
Shift.Out (MSB_FIRST, Data_Out, 16)
data_out = 256* 0 + LED_Data ' no op
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 3
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 2
Shift.Out (MSB_FIRST, Data_Out, 16) 'no op unit 1
End Select
LoadPin = 1
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?