jayanth.devarayanadurga
Banned
- Joined
- Dec 4, 2012
- Messages
- 4,280
- Helped
- 822
- Reputation
- 1,654
- Reaction score
- 791
- Trophy points
- 1,393
- Location
- Bangalore, India
- Activity points
- 0
For Character 'A'
Matrix is
11000011
10111101
10111101
10111101
10111101
10000001
10111101
10111101
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #define SH_CP RC0_bit #define ST_CP RC1_bit #define DS PORTC.F2 unsigned char matrixData[] = {0x00, 0xFE, 0x21, 0x21, 0x21, 0x21, 0xFE, 0x00, 0x00, 0xFE, 0x21, 0x21, 0x21, 0x21, 0xFE, 0x00, 0x00, 0xFE, 0x21, 0x21, 0x21, 0x21, 0xFE, 0x00}; unsigned int count = 0, repeat = 0, datastored = 0; void Send_Data(){ unsigned int t, num, Flag, Mask, index = 0;; PORTD = 0x01; for(count = num*8;count < (num*8+8);count++){ //sends array elements 0,1,2,3,4,5,6,7 and 8,9,10,11,12,13,14,15 and 16, 17, 18, 19, 20, 21, 22, 23 index = num; //first loop index is 1 then 2, 3, 4, 5, 6, 7, 8, 9, ... for(datastored = 0; datastored < 3; datastored++);{ //loops 0 to 2 (loops three times) Mask = 0x80; //Mask for (t=0; t<8; t++){ //loops 8 times and sends 8 bits of an array element to 74HC595, Character 'A' is sent 3 times //3 * 8 = 24 bits is transferred to 74HC595 if(matrixData[index] & Mask)DS = 0; else if(!(matrixData[index] & Mask))DS = 1; SH_CP = 1; //SH_CP is clocked for every bit Delay_us(10); SH_CP = 0; Mask = Mask >> 1; //Mask is shifted to test next bit. (MSB to LSB) } index = index + 8; //index is incremented 8 times, A1, A1, A1 is sent (elements 0, 8, 16), second loop (elements 1, 9, 17 is sent)... //array is like this... //A0, A1, A2, A3, A4, A5, A6, A7, A0, A1, A2, A3, A4, A5, A6, A7, A0, A1, A2, A3, A4, A5, A6, A7, } //OE = 0; ST_CP = 1; //ST_CP is clocked after transferring 24 bits. Delay_us(10); ST_CP = 0; Delay_ms(2); //display each col 2 ms. //OE = 1; PORTD = PORTD << 1; //PORTD (col) is shifted } } void main(){ TRISC = 0x00; TRISD = 0x00; PORTC = 0x00; PORTD = 0x01; while(1){ Send_Data(); } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #define SH_CP RC0_bit #define ST_CP RC1_bit #define DS PORTC.F2 #define OE PORTC.F3 unsigned char matrixData[] = {0x00, 0xFE, 0x21, 0x21, 0x21, 0x21, 0xFE, 0x00, 0x00, 0xFE, 0x21, 0x21, 0x21, 0x21, 0xFE, 0x00, 0x00, 0xFE, 0x21, 0x21, 0x21, 0x21, 0xFE, 0x00}; unsigned int count = 0, repeat = 0, datastored = 0; void Send_Data(){ unsigned int t, num, Flag, Mask, index = 0;; PORTD = 0x01; for(count = num*8;count < (num*8+8);count++){ //sends array elements 0,1,2,3,4,5,6,7 and 8,9,10,11,12,13,14,15 and 16, 17, 18, 19, 20, 21, 22, 23 index = num; //first loop index is 1 then 2, 3, 4, 5, 6, 7, 8, 9, ... for(datastored = 0; datastored < 3; datastored++);{ //loops 0 to 2 (loops three times) Mask = 0x80; //Mask for (t=0; t<8; t++){ //loops 8 times and sends 8 bits of an array element to 74HC595, Character 'A' is sent 3 times //3 * 8 = 24 bits is transferred to 74HC595 if(matrixData[index] & Mask)DS = 0; else if((matrixData[index] & Mask) == 0)DS = 1; SH_CP = 1; //SH_CP is clocked for every bit Delay_us(10); SH_CP = 0; Mask = Mask >> 1; //Mask is shifted to test next bit. (MSB to LSB) } index = index + 8; //index is incremented 8 times, A1, A1, A1 is sent (elements 0, 8, 16) //array is like this... //A0, A1, A2, A3, A4, A5, A6, A7, A0, A1, A2, A3, A4, A5, A6, A7, A0, A1, A2, A3, A4, A5, A6, A7, } OE = 0; ST_CP = 1; //ST_CP is clocked after transferring 24 bits. Delay_us(10); ST_CP = 0; Delay_ms(2); OE = 1; PORTD = PORTD << 1; //PORTD (col) is shifted } } void main(){ TRISC = 0x00; TRISD = 0x00; PORTC = 0x00; PORTD = 0x00; CMCON = 0x07; while(1){ Send_Data(); } }
The most important thing is that we had to replace (Y mirror) the matrix row and column sides
Hi;Please explain this...
In this case (4 x 8x8 matrix) we have 8 horizontal rows and 4x8=32 vertical columns, right?
I need an example of real matrix. rows are not inverted in your example. so, rows are anodes and columns are cathodes. Right?To avoid the external inverters the matrix property was modified: the default row inverting line {INVERT=A,B,C,D,E,F,G,H} is switched off (commented out using a semicolon).
Yes, my mistake, sorry ...No, we have 3 * 8X8 matrices = 8 rows and 24 columns
No, see the logical levels and the individual leds, the matrix top row is its H pin, tied to PORTD.7I added a delay and saw that row is being scanned that is matrix is scanned from bottom row to top row. (horizontal)
PORTD is controlling the rows and I see that initially PORTD is 0x80, so, bottom row is the starting point for scanning. Right?
No, now (in this DSN) both are anodesI need an example of real matrix. rows are not inverted in your example. so, rows are anodes and columns are cathodes. Right?
Code C - [expand] 1 2 3 4 5 //DS = the corresponding bit: if (value & mask) DS = 0; // inverted !!!!!!!!!!!!! else DS = 1;
There are labels in the DSN: simply place the cursor over a matrix pin while the simulation is off and see the status line.Please add labels to row and columns of matrix and send it to me. I get confused when matrix is flipped and rotated.
Sorry but I don't have more time, this is your task. There are a lot of solutions (even here, on the forum) ...How to scroll?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 /* Using a two-dimensional bitmap array it's more clear I hope. (some more little modifications and verbose comments). */ #define SH_CP LATC0_bit #define ST_CP LATC1_bit #define DS LATC3_bit const char matrixData[][8] = { {// char 'A' = 41h 0b00110000, //top line (row) 0b01111000, 0b11001100, 0b11001100, 0b11111100, 0b11001100, 0b11001100, 0b00000000 }, {// char 'B' = 42h 0b11111100, 0b01100110, 0b01100110, 0b01111100, 0b01100110, 0b01100110, 0b11111100, 0b00000000 }, {// char 'C' = 43h 0b00111100, 0b01100110, 0b11000000, 0b11000000, 0b11000000, 0b01100110, 0b00111100, 0b00000000 }}; unsigned char datastored; //for max 255 chars, for larger msg use unsigned int here void Send_Data(){ //display Characters A B and C no scrolling unsigned char bitcnt, value, mask, rows, PortDvalue; PortDvalue = 0x80; //first the top row (matrix H pin) is on, reversed row order: for(rows = 0 ; rows < 8 ; rows++) { // 8 rows (0..7) for( datastored = 0 ; datastored < 3 ; datastored++) { //3 chars (0..2) //get and temporaly store the actual byte: value = matrixData[datastored][rows]; mask = 1; //first the bit 0, reversed column order in DSN for (bitcnt = 0; bitcnt < 8; bitcnt++) { //8 bits (0..7) //DS = the corresponding bit: if (value & mask) DS = 1; else DS = 0; //positive pulse to shift in the bit: SH_CP = 1; SH_CP = 0; mask = mask << 1; //prepare to next bit } } LATD = 0; //lines off to avoid shadows //positive pulse to load the HC595 output regs (store the new col datas): ST_CP = 1; ST_CP = 0; LATD = PortDvalue; //switch on the actual line Delay_ms(1); //time to see it PortDvalue >>= 1; //prepare to next row } } void main(){ //port C and D are outputs and set to zero TRISC = 0x00; TRISD = 0x00; PORTC = 0x00; PORTD = 0x00; while(1) Send_Data(); //infinite loop }
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?