LED matrix scrolling direction problem  - Page 1
Forum section: electronics / projects

author: NASK
author_rank: Contributor
timestamp: June 03, 2019, 09:54:10 am
content: plz help me to solve this coding problem.I need to scroll LED matrix display to this direction "<--- " but it is working on up direction (U+2195) ,hear i have attach my code with proteus simulation which i used. plz any one could help me to modify this code work <--- direction .( I have used PIC 16f887 & MPLABX)#define _XTAL_FREQ 8000000#include <stdio.h>#include <stdlib.h>#include <xc.h>#include <math.h>#define SRCLK RD0#define SER RD1#define RCLK RD2#define REST RD4#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)#pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)#pragma config BOREN = ON // Brown Out Reset Selection bits (BOR enabled)#pragma config IESO = ON // Internal External Switchover bit (Internal/External Switchover mode is enabled)#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)#pragma config LVP = ON // Low Voltage Programming Enable bit (RB3/PGM pin has PGM function, low voltage programming enabled)// CONFIG2#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)void clock (void){RD3=1;RD3=0;}void reset (void){ REST =1; REST =0; }void serial_data_inn(unsigned long temp);void LED_ON (unsigned int k);void LED_SHIFT(unsigned char shiftt[]);char Array;int L=15; unsigned long F;unsigned int scroll_LED;unsigned long scroll_LED2;int main(){TRISD=0;PORTD=0;const unsigned char lETTER_E[]={{0b00000000,0b11111110,0b10010010,0b10010010,0b10010010,0b10010010,0b00000000,0b00000000},//E{0b00000000,0b11111110,0b00000010,0b00000010,0b00000010,0b00000010,0b00000000,0b00000000},//L{0b00000000,0b11111110,0b10010010,0b10010010,0b10010010,0b10010010,0b00000000,0b00000000},//E{0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000010,0b00000000,0b00000000},//C{0b00000000,0b01000000,0b01000000,0b01111110,0b01000000,0b01000000,0b00000000,0b00000000},//T{0b00000000,0b11111111,0b10001000,0b10001100,0b10001010,0b01110001,0b00000000,0b00000000},//R{0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b00111100,0b00000000,0b00000000},//O{0b00000000,0b01111110,0b00100000,0b00010000,0b00001000,0b00000100,0b01111110,0b00000000},//N{0b00000000,0b10000001,0b10000001,0b11111111,0b10000001,0b10000001,0b00000000,0b00000000},//I{0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000010,0b00000000,0b00000000},//C{0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},//ZERO{0b00000000,0b11111110,0b00000010,0b00000010,0b00000010,0b00000010,0b00000000,0b00000000},//L{0b00000000,0b01111110,0b10001000,0b10001000,0b10001000,0b10001000,0b01111110,0b00000000},//A{0b00000000,0b01111111,0b01001001,0b01001001,0b01001001,0b01001001,0b00110110,0b00000000},//B{0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000}//ZERO};while(1){LED_SHIFT(lETTER_E);}}void serial_data_inn(unsigned long temp ){unsigned long Mask = 0x0001;for (int i=0;i<32;i++){F = temp & Mask;SRCLK =0;if (F != 0){SER=1; }else {SER=0; }SRCLK =1;Mask = Mask << 1;}RCLK=1;RCLK=0;}/*void LED_ON (unsigned int k){char c=0 ;for (int i=0;i<16;i++){Array=0;}while (k != 0){Array = k & 0x01;k =k >>1;c++;}}*/void LED_SHIFT(unsigned char shiftt[]){for (unsigned char a=0;a<L;a++){for(char k=0;k<8;k++){for(unsigned char j=0; j<8;j++) {scroll_LED2=scroll_LED2 << 1 | (shiftt>>((8-1)-k*1) ) ;}for(int b=0;b <5; b++){for (int i=0;i<8;i++){serial_data_inn(scroll_LED2);__delay_us(2000);serial_data_inn(0b00000000000000000000000000000000);clock();}reset();}}if (a>(L -1)){for(char d=0;d<8;d++){ scroll_LED2=0 ;} }}}

author: Psi
author_rank: Super Contributor
timestamp: June 03, 2019, 10:18:51 am
content: Have indented and added to code block, Will have a look at code nowCode:#define _XTAL_FREQ 8000000#include <stdio.h>#include <stdlib.h>#include <xc.h>#include <math.h>#define SRCLK RD0#define SER RD1#define RCLK RD2#define REST RD4#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)#pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)#pragma config BOREN = ON // Brown Out Reset Selection bits (BOR enabled)#pragma config IESO = ON // Internal External Switchover bit (Internal/External Switchover mode is enabled)#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)#pragma config LVP = ON // Low Voltage Programming Enable bit (RB3/PGM pin has PGM function, low voltage programming enabled)// CONFIG2#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)void clock (void){RD3=1;RD3=0;}void reset (void){ REST =1; REST =0; }void serial_data_inn(unsigned long temp);void LED_ON (unsigned int k);void LED_SHIFT(unsigned char shiftt[]);char Array;int L=15; unsigned long F;unsigned int scroll_LED;unsigned long scroll_LED2;int main(){TRISD=0;PORTD=0;const unsigned char lETTER_E[]={{0b00000000,0b11111110,0b10010010,0b10010010,0b10010010,0b10010010,0b00000000,0b00000000},//E{0b00000000,0b11111110,0b00000010,0b00000010,0b00000010,0b00000010,0b00000000,0b00000000},//L{0b00000000,0b11111110,0b10010010,0b10010010,0b10010010,0b10010010,0b00000000,0b00000000},//E{0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000010,0b00000000,0b00000000},//C{0b00000000,0b01000000,0b01000000,0b01111110,0b01000000,0b01000000,0b00000000,0b00000000},//T{0b00000000,0b11111111,0b10001000,0b10001100,0b10001010,0b01110001,0b00000000,0b00000000},//R{0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b00111100,0b00000000,0b00000000},//O{0b00000000,0b01111110,0b00100000,0b00010000,0b00001000,0b00000100,0b01111110,0b00000000},//N{0b00000000,0b10000001,0b10000001,0b11111111,0b10000001,0b10000001,0b00000000,0b00000000},//I{0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000010,0b00000000,0b00000000},//C{0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},//ZERO{0b00000000,0b11111110,0b00000010,0b00000010,0b00000010,0b00000010,0b00000000,0b00000000},//L{0b00000000,0b01111110,0b10001000,0b10001000,0b10001000,0b10001000,0b01111110,0b00000000},//A{0b00000000,0b01111111,0b01001001,0b01001001,0b01001001,0b01001001,0b00110110,0b00000000},//B{0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000}//ZERO};while(1){LED_SHIFT(lETTER_E);}}void serial_data_inn(unsigned long temp ){unsigned long Mask = 0x0001;for (int i=0;i<32;i++){F = temp & Mask;SRCLK =0;if (F != 0){SER=1;} else {SER=0;}SRCLK =1;Mask = Mask << 1;}RCLK=1;RCLK=0;}void LED_SHIFT(unsigned char shiftt[]){for (unsigned char a=0;a<L;a++){for(char k=0;k<8;k++){for(unsigned char j=0; j<8;j++){scroll_LED2=scroll_LED2 << 1 | (shiftt>>((8-1)-k*1) ) ;}for(int b=0;b <5; b++){for (int i=0;i<8;i++){serial_data_inn(scroll_LED2);__delay_us(2000);serial_data_inn(0b00000000000000000000000000000000);clock();}reset();}}if (a>(L -1)){for(char d=0;d<8;d++){scroll_LED2=0 ;}}}}

author: Psi
author_rank: Super Contributor
timestamp: June 03, 2019, 10:55:00 am
content: Out of interest, how large is your total LED array, is it 16 pixels by 8 pixels?The reason you are finding it hard to code this is because you are trying to do 3 things at once in a single function- Write pixel data to the display hardware in the format/order it needs- Convert between how you store your your message (lETTER_E array) and what the display expects- Shift the message data on every function call.This can be quite complex to do all at once. For example, you might need to load font data in from top to bottom, scroll from left to right, and output data to the hardware from bottom left to top right. Or something like that, Super confusing to do it all at once.So, Try to break those into separate functions.First thing to do is create a 2D array with an element for each LED pixel in your LED sign.etcbyte LEDDisplayMem; for a 16x8 led display.A) Write a function to read this array and update the display hardware with whatever is in the array.This function should be called repeatedly to keep the display up to date. All further functions should write data to this array not to the hardware.You might decide to have MyArray[0,0] be the top left of your display to make it easy to visualize the array contents in your head.So MyArray[0,0] = 1; would be top-left led on and MyArray[0,0] = 0; would be off.This may seem like a bit of a waste of memory (using a byte to store 0 or 1) but it will make things easier. You also get provision to store color/shading later if you want.B) Write a function to takes a character, looks up its pixel font data and puts that into the array at a specific starting positionC) Write a function to call function B and assemble all the characters you want in a message at a position you specify.D) Now you can call function C with increasing/decreasing positions in X/Y to scroll in any direction you want.