Embedded C Help needed!

Hello everyone, I would like to ask a rather easy question about bitwise in embedded PIC microcontrollers. I have [10][32] LED array. In other words it is an LED TOWER which uses constant current led drivers connected in series (2 ics per layer (4 bytes)). I have a function that uses USART communication and addresses all leds.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  void Update_Display(void){
	
		while(!TRMT);			// Wait until transmission register is empty
		
		for (int y = 0; y < LAYERS; y++){
			for (int x = 0; x < BYTES; x++){
			TXREG = LED_Buffer[y][x];
			while (!TRMT);
			}
		}
			
		
		LE = 1;					// Data is loaded to the Output latch
		NOP();	NOP();			
		LE = 0;					}


Now, I want to write a function that would shift a diagonal LEDs across and create the continuous animation. I hope you understand my intention..

I am not entirely sure how to do it, since i want to shift through all 4 bytes [32 leds/layer].

If you need me to provide more code let me know, I appreciate your help in advance.

Similar function that I have written is this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void Switch_Col(char c, char state){
	
	int y;
	
	if (state == ON){
		for (y = 0; y < LAYERS; y++)
			LED_Buffer[y][c/8] |= (1 << c % 8);
	}
	else{
		for (y = 0; y < LAYERS; y++)
			LED_Buffer[y][c/8] &= ~(1 << c % 8);
	}	
	Update_Display();
}


which turns on the column according to the function argument provided.

Thanks a lot!
Switch_Col(...) contains already the solution, almost. Modify it a bit:
1
2
3
4
5
6
7
8
9
void Switch(int col, int row, bool state){
	
	if (state){
			LED_Buffer[row][col/8] |= (1 << col % 8);
	}
	else{
			LED_Buffer[row][col/8] &= ~(1 << col % 8);
	}	
}


To simplify dealing with the leds you may want an 2-d bool array which you modify and display when done using an update function.
coder777, thanks for replying back. Are you suggesting to use another buffer that i could write the animations to and than copy all of those elements to the one that is used by Update_Display() ?
It would make thinks simplier if you'd manipulate the bits only at the moment you need it (line 7 in Update_Display()).

With a 2 dimensional bool array a diagonal would like this:
1
2
3
4
5
for (int y = 0; y < rows; y++){
			for (int x = 0; x < col; x++){
			bool_Buffer[y][x]= (y == x);
			}
		}


It doesn't look like that you need two buffers. On line 7 in Update_Display(), how is it determined which leds are used?
Last edited on
Well, I write the animation to the LED_Buffer[y][x] and than i use Update_Display() to load the output latch and on LE falling edge the corresponding LEDS are set. However, since I have it a byte array rather than bit, makes it awkward to write to it every time.. I would love to simplify it, but don't really know how to go about it.
Topic archived. No new replies allowed.