scrolling led matrix

Status
Not open for further replies.

MrDEB

Well-Known Member
I have a clunky code that works BUT feel that this posted code may work better. My present clunky code has too mant spaces etc. In this posted code it uses a buffer to store the const arrays but it won't compile.
Any explanation as to how this posted code works as I have tried to understand what is going on but can't figure out how the const arrays are xfered from the Display_buffer to Data bus.(see draw data sub) the compile error is in this _ Data_Bus = Display_Out XOR $11111111 DIM Display_Out AS BYTE ' CONST array data DIM Display_Buffer(8) AS BYTE ' data to send to matrix DIM Data_Bus AS portb ' data that matrix displays DIM Colum_start AS WORD ' cathodes DIM Anode_Data AS PORTC ' Anodes DIM x AS BYTE DIM y AS BYTE DIM Speed AS BYTE //SUB ROUTINES SUB Load_Buffer() FOR x = 0 TO 96 ' 120 / 8 = 15 Display_Buffer(x) = Sentence_Data(x) NEXT END SUB SUB Draw_Data() FOR x = Colum_start TO (Colum_start+7) ' COLUMS ON PORT b counter Display_Out = Display_Buffer(x) ' const data Data_Bus = Display_Out XOR$11111111 ' inverts the CONST array data at the port
Display_Buffer(x) = Sentence_Data(x)
Data_Bus = Sentence_Data XOR %11111111 ' reverse the data bits
Data_Bus = 0 ' data bus
Data_Bus.bits(7 - (x- Colum_start)) = 1 ' cycle the anodes from 0 to 7
Data_Bus = 0
display_out = 1
DELAYMS(10)
display_out= 0

NEXT

END SUB

SUB Scroll_Text()
IF Speed <> 0 THEN
DEC(Speed)
ELSE
Speed = 6
Colum_start = Colum_start + 1
IF Colum_start + 8 = 96 THEN ' # of elements in CONST array Colum Start is Cathodes on portb
Colum_start = 0
END IF
END IF
END SUB

SetAllDigital // Make all Pins digital I/O's
TRISC = %00000000 // Make PORTD all outputs
TRISB = %00000000 // Make PORTB all outputs
y = 0
Speed = 50
Colum_start = 0
WHILE true

Draw_Data()
FOR y = 0 TO 20
Draw_Data()
NEXT
Scroll_Text()
WEND

MrDEB

Well-Known Member
Ah yes I corrected and now it compiles but the matrix is blank??

Dr_Doggy

Well-Known Member
Load_Buffer() is where the data imports to Display_Buffer(x) from Sentence_Data(x)

Sentence_Data(x) is likely where you put what you want to see on display(or aka the buffer that doesnt draw as you are editing)... i do not see it even declared yet

MrDEB

Well-Known Member
Thanks will look at that as well as I don't find where the anodes are enabled.

Dr_Doggy

Well-Known Member
EDIT: AH yes, Anode_Data is missing

also this snipit may need additional modification if hardware is different

what is your hardware like, do you follow the same, ie cathode on portB annode on portC?

Dr_Doggy

Well-Known Member
for debug purposes i would change this routine temporarially, then we can see the mismatch better in output:

FOR x = 0 TO 96 ' 120 / 8 = 15
Display_Buffer(x) = (x)
NEXT
END SUB

Dr_Doggy

Well-Known Member
notice this aswell in the SUB Draw_Data():
Data_Bus.bits(7 - (x- Colum_start)) = 1 ' cycle the anodes from 0 to 7

could it be another typo!?
maybe try:
Anode_Data.bits(7 - (x- Colum_start)) = 1 ' cycle the anodes from 0 to 7

MrDEB

Well-Known Member
I have a somewhat working display but I think I am running into a program memory issue as the display cycles once just fine then starts jumbling text then just freezes text. Am using 658 program bytes and 50 variables on a 24K20 pic.
two const arrays with 106 bytes each.
That's what I am thinking is wrong.

Dr_Doggy

Well-Known Member
I also wonder if display_buffer and sentence_data are declaired wrong,
note in the draw loop x goes up to 96 , but arrrays are declaired for only 8 bytes
try:
DIM Display_Buffer(96) AS BYTE ' data to send to matrix
DIM Display_Buffer(96) AS BYTE ' data to send to matrix

....actually how many columns are in your array?

.... to me sounds like a buffer alignment issue, but it could be memory, idk if swordfish would catch that error or not..

MrDEB

Well-Known Member
here is my new code that I got from a friend. it has 106 bytes per const array. looking at why is it retrieveing the const data every cycle. Tried doing it one time and it won't work. Am going to delete some of the array data.
DIM GreenBuffer(8) AS BYTE
DIM RedBuffer(8) AS BYTE
DIM x AS BYTE
DIM ScrollingTextOffset AS WORD
DIM ScrollingTextSpeed AS BYTE
DIM DefaultScrollingTextSpeed AS BYTE

IF ScrollingTextSpeed <> 0 THEN
DEC(ScrollingTextSpeed)
ELSE
ScrollingTextSpeed = DefaultScrollingTextSpeed
INC(ScrollingTextOffset)
IF ScrollingTextOffset > (BOUND(GreenData) - 8) THEN ' we need to check if we have reached the start of the last eight columns of data that's why we take away 8
ScrollingTextOffset = 0
ENDIF
ENDIF
END SUB

SUB SaveGraphics()
FOR x = 0 TO 7
GreenBuffer(x) = GreenData(x + ScrollingTextOffset)
RedBuffer(x) = RedData(x + ScrollingTextOffset)
NEXT
END SUB

SUB DisplayGraphics()
FOR x = 0 TO 7
GreenLEDs = GreenBuffer(x) XOR %11111111
RedLEDs = RedBuffer(x) XOR %11111111
Anodes.bits(7 - x) = 1
DELAYUS(520)
Anodes.bits(7 - x) = 0
NEXT
END SUB

SetAllDigital

TRISA = %00000000 ' PORTA outputs
TRISB = %00000000 ' PORTB outputs
TRISC = %00000000 ' PORTC outputs
'TRISD = %00000000 ' PORTC outputs
'TRISE = %00000001 ' PORTC outputs except pin 0

// Start Of Program
OSCCON = %01100000 ' Internal oscillator running at 8mHz
'OSCTUNE.bits(6) = 1 ' enable PLL so we can run this thing at 32Mhz

GreenLEDs = %00000000 ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
RedLEDs = %00000000 ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
Anodes = %00000000

ScrollingTextOffset = 0
DefaultScrollingTextSpeed = 45
ScrollingTextSpeed = DefaultScrollingTextSpeed

// Main Loop
WHILE True() // This creates an infinite loop
SaveGraphics
DisplayGraphics
WEND // Loop back to the while loop as long as we havent finished.

Dr_Doggy

Well-Known Member
i doubt it to be mem space error, please elaborate on hardware....
.... how many annodes/cathodes are in your array... how r they wired?

MrDEB

Well-Known Member
in hardware their are 8 anodes and 16 cathodes (8 red and 8 green) using a bi colored 8 x 8 led matrix
in the const arrays I am only addressing the cathodes. the anodes are scanning.
tried eliminating all the greenled references and it still locks up after one cycle.

Dr_Doggy

Well-Known Member
how are cathode arranged ... does it go portb = red, portc = green, or does it go red, green, red, green, red, green, across both ports?

MrDEB

Well-Known Member
PortA = green cathodes
PortB = Red cathodes
PortC = anodes

MrDEB

Well-Known Member
Well I ran same code but with a 18F25K20 (my final assembly has a smd 18F24K20 pic)
it looks like it is running out of memory comparing the two pics. The user ram is way different as is the user ram banks. So now I need to come up with a different code to use less memory.
18F25k20

#const _core = $0012 // processor core #const _ram_banks =$06 // 6 RAM bank(s) used

#variable _maxaccess = $60 // access ram is 96 bytes #variable _maxram =$0600 // 1536 bytes of user RAM

#variable _maxrom = $008000 // 32 KB of program ROM #const _eeprom =$0100 // 256 bytes of EEPROM

#const _eeprom_start = $F00000 // EEPROM start address #const _ports =$03 // 3 available ports

#const _ccp = $01 // 1 CCP module(s) available #const _eccp =$01 // 1 ECCP module(s) available

#const _mssp = $01 // 1 MSSP module(s) available #const _usart =$01 // 1 USART(s) available

#const _adc = $0A // 10 ADC channels available #const _adres =$0A // 10 bit ADC resolution

#const _comparator = $02 // 2 comparator(s) available #const _psp =$00 // Parallel Slave Port (PSP) is NOT supported

#const _can = $00 // onboard CAN is NOT supported #const _usb =$00 // USB is NOT supported

#const _ethernet = $00 // onboard Ethernet is NOT supported #const _flash_write =$01 // FLASH has write capability

18F24K20

#const _core = $0012 // processor core #const _ram_banks =$03 // 3 RAM bank(s) used

#variable _maxaccess = $60 // access ram is 96 bytes #variable _maxram =$0300 // 768 bytes of user RAM

#variable _maxrom = $004000 // 16 KB of program ROM #const _eeprom =$0100 // 256 bytes of EEPROM

#const _eeprom_start = $F00000 // EEPROM start address #const _ports =$03 // 3 available ports

#const _ccp = $01 // 1 CCP module(s) available #const _eccp =$01 // 1 ECCP module(s) available

#const _mssp = $01 // 1 MSSP module(s) available #const _usart =$01 // 1 USART(s) available

#const _adc = $0A // 10 ADC channels available #const _adres =$0A // 10 bit ADC resolution

#const _comparator = $02 // 2 comparator(s) available #const _psp =$00 // Parallel Slave Port (PSP) is NOT supported

#const _can = $00 // onboard CAN is NOT supported #const _usb =$00 // USB is NOT supported

#const _ethernet = $00 // onboard Ethernet is NOT supported #const _flash_write =$01 // FLASH has write capability

Dr_Doggy

Well-Known Member
Ill admit I still dont think its a mem prob, not that i researched it, but i was able to drive 5x5x5x3 matrix with lots of features from an 18f4620, which may or may not be smaller!!

going back to the first code , i like it better since its working better! for now lets ignore the green

Code:
' IF THIS FIRST LINE DOESNT WORK TRY THE SECOND, OR DELETE AND REPLACE ALL NAMES WITH VALUE
DIM Column_Length AS BYTE = 96 ' cathodes
DIM Column_Length = 96 AS BYTE  ' cathodes

DIM Colum_start AS BYTE ' cathodes
DIM Display_Out AS BYTE ' CONST array data
DIM Sentence_Data( Column_Length) AS BYTE ' SAFE PLACE TO WRITE data to send to matrix
DIM Display_Buffer( Column_Length) AS BYTE ' BACKBUFFER to matrix

DIM Anode_Data AS PORTC ' Anodes
DIM Data_Bus AS portb ' red cathodes

DIM x AS BYTE
DIM y AS BYTE
DIM Speed AS BYTE
DIM Speed_Counter AS BYTE

//SUB ROUTINES

' do you know how to read binary, the columns will output the count as such
FOR x = 0 TO Column_Length' 120 / 8 = 15
Display_Buffer(x) = (x)  'Sentence_Data(x)
NEXT
END SUB

SUB Draw_Data()
porta = 0 '     lets ignore the green
FOR x = Colum_start TO (Colum_start+7) ' COLUMS ON PORT b counter
Display_Out = Display_Buffer(x) ' const data
Data_Bus = Display_Out XOR \$11111111 ' inverts the CONST array data at the port  SETS UP PORTB

' WHAT ARE THESE 2 LINES ?? LOOKS LIKE A REPEAT OF THE LAST, MAY NEED DELETING
'Display_Buffer(x) = Sentence_Data(x)
'Data_Bus = Sentence_Data XOR %11111111 ' reverse the data bits

Anode_Data = 1
FOR Y = 1 TO 8 ' ROWS ON PORT A counter

' ONLY USE ONE OF THESE 3 LINES, NOT SURE WHICH WILL WORK FOR SF
'Anode_Data = 1 <<Y ' Anodes ' cycle the anodes from 0 to 7
'Anode_Data = 2^Y' Anodes ' cycle the anodes from 0 to 7
Anode_Data = Anode_Data * 2 ' Anodes ' cycle the anodes from 0 to 7

DELAYMS(50)       ' ADJUST THIS TO BALANCE BETWEEN BRIGHTNESS AND FLICKER
NEXT ' Y

NEXT 'X

END SUB

'SUB Scroll_Text()
'IF Speed <> 0 THEN
'DEC(Speed)
'ELSE
'Speed = 6
'Colum_start = Colum_start + 1
'IF Colum_start + 8 = Column_Length THEN ' # of elements in CONST array Colum Start is Cathodes on portb
'Colum_start = 0
'END IF
'END IF
'END SUB

SetAllDigital // Make all Pins digital I/O's
TRISC = %00000000 // Make PORTD all outputs
TRISB = %00000000 // Make PORTB all outputs
TRISA= %00000000 // Make PORTB all outputs
y = 0
Speed = 10
WHILE true

FOR Colum_start = 0 TO Column_Length - 8
FOR Speed_Counter = 0 TO Speed
Draw_Data()

NEXT   'Speed_Counter
NEXT    'Colum_start
WEND

MrDEB

Well-Known Member
Last night I loaded a compiled version of the first code and going to give it a whirl. Will look at your suggestion and try it as well
Thanks

Status
Not open for further replies.