hello friends I'm doing a 8x8 LED matrix with LPC1768 and when I compile I get an error that I can not solve also leave some warnings but I did not care much. could help me? I leave the whole project in keil
many thanks Ciernes
sorry the file is this: www.mediafire.com/.../matrix_test.rar
Lol - wouldn't it be simpler to post the error message, and the relevant source code lines around that error message, together with any required data/type declarations?
if the code is right but something along with several header files sorry
sorry for my bad English, I mean that the code is long
The code may be long, but there are seldom many code lines involved where the compiler complain.
In the end, it's an iterative process to fix the compilation errors, and then start testing the code and fix any logic bugs.
matrix.c
#include "lpc17xx.h" #include "matrix.h" #include "matrix_font.h" #include "string.h" #include "timer.h" #define SPACE_LENGTH 1 #define SPEED 250 #define MAXIMUM_LENGTH 32 void Matrix_Init(void); void Matrix_Update(void); void Matrix_Drawhorizontalline (uint8_t x, uint8_t y, uint8_t length); void Matrix_Drawverticalline (uint8_t x, uint8_t y, uint8_t length); void Matrix_NewFrame(uint8_t array[8]); void Matrix_Clear(void); void Matrix_MoveUP(void); void Matrix_MoveDOWN(void); void Matrix_MoveRIGTH(void); void Matrix_MoveLEFT(void); void Matrix_PutChar(unsigned char string); void Matrix_PutString(unsigned char *string); void Matrix_Start(void); void Matrix_Stop(void); /* Variables to save the display status */ uint8_t matrix[7]; uint8_t buffer[7]; uint8_t nextline = 0; /* Variables for put string function */ uint8_t print_string_status = 0; uint8_t current_character = 0; uint8_t current_collom = 0; uint8_t string_length = 0; uint8_t character_buffer[MAXIMUM_LENGTH]; void Matrix_Init(void) { Matrix_Clear(); /* Set direction for anode pins */ LPC_GPIO1->FIODIR |= (0x0F << 20); LPC_GPIO1->FIODIR |= (0x0F << 28); /* Set direction for cathode pins */ LPC_GPIO0->FIODIR |= (0x03 << 10); LPC_GPIO0->FIODIR |= (0x03 << 19); LPC_GPIO2->FIODIR |= (0x39 << 8); /* Clear anode pins */ LPC_GPIO1->FIOCLR |= (0x0F << 20); LPC_GPIO1->FIOCLR |= (0x0F << 28); /* Set cathode pins */ LPC_GPIO0->FIOSET |= (0x03 << 10); LPC_GPIO0->FIOSET |= (0x03 << 19); LPC_GPIO2->FIOSET |= (0x39 << 8); /* Timer1 init */ LPC_SC->PCONP |= (0x1 << 2); LPC_TIM1->IR = 0x0F; LPC_TIM1->PR = 12000; LPC_TIM1->MCR = 0x01; NVIC_EnableIRQ(TIMER1_IRQn); LPC_GPIO1->FIODIR |= (0x01 << 18); } void Matrix_Update (void) { uint32_t buffer; switch (nextline) { case 0: /* Row 0 */ buffer = matrix[7]; LPC_GPIO0->FIOCLR |= (0x01 << 10); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 1; return; case 1: /* Row 1 */ buffer = matrix[6]; LPC_GPIO0->FIOCLR |= (0x01 << 11); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 2; return; case 2: /* Row 2 */ buffer = matrix[5]; LPC_GPIO0->FIOCLR |= (0x01 << 19); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 3; return; case 3: /* Row 3 */ buffer = matrix[4]; LPC_GPIO0->FIOCLR |= (0x01 << 20); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 4; return; case 4: /* Row 4 */ buffer = matrix[3]; LPC_GPIO2->FIOCLR |= (0x01 << 8); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 5; break; case 5: /* Row 5 */ buffer = matrix[2]; LPC_GPIO2->FIOCLR |= (0x01 << 11); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 6; return; case 6: /* Row 6 */ buffer = matrix[1]; LPC_GPIO2->FIOCLR |= (0x01 << 12); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 7; break; case 7: /* Row 7 */ buffer = matrix[0]; LPC_GPIO2->FIOCLR |= (0x01 << 13); LPC_GPIO1->FIOSET |= ((buffer & 0x0F) << 20); LPC_GPIO1->FIOSET |= ((buffer & 0xF0) << 24); nextline = 0; return; default: break; } }
void Matrix_Drawhorizontalline (uint8_t x, uint8_t y, uint8_t length) { uint8_t i = 0; uint8_t var = 0; for (i = 0; i < length; ++i) { var |= (1 << i); } matrix[(7 - y)] = (var << x); } void Matrix_Drawverticalline (uint8_t x, uint8_t y, uint8_t length) { uint8_t i = 0; for (i = 0; i < length; ++i) { matrix[(y + (7 - i))] |= (1 << x); } } void Matrix_NewFrame(uint8_t array[8]) { matrix[0] = array[0]; matrix[1] = array[1]; matrix[2] = array[2]; matrix[3] = array[3]; matrix[4] = array[4]; matrix[5] = array[5]; matrix[6] = array[6]; matrix[7] = array[7]; } void Matrix_Clear(void) { uint8_t i; for(i = 0; i < 8; i++) { matrix[i] = 0; } } void Matrix_MoveUP(void) { uint8_t i; for (i = 0; i < 8; ++i) { buffer[i] = matrix[i]; } matrix[0] = buffer[1]; matrix[1] = buffer[2]; matrix[2] = buffer[3]; matrix[3] = buffer[4]; matrix[4] = buffer[5]; matrix[5] = buffer[6]; matrix[6] = buffer[7]; matrix[7] = buffer[0]; } void Matrix_MoveDOWN(void) { uint8_t i; for (i = 0; i < 8; ++i) { buffer[i] = matrix[i]; } matrix[0] = buffer[7]; matrix[1] = buffer[0]; matrix[2] = buffer[1]; matrix[3] = buffer[2]; matrix[4] = buffer[3]; matrix[5] = buffer[4]; matrix[6] = buffer[5]; matrix[7] = buffer[6]; } void Matrix_MoveRIGTH(void) { uint8_t i; uint8_t buffer; for (i = 0; i < 8; ++i) { buffer = (matrix[i] & 0x80); matrix[i] = (matrix[i] << 1); matrix[i] |= (buffer >> 7); } } void Matrix_MoveLEFT(void) { uint8_t i; uint8_t buffer; for (i = 0; i < 8; ++i) { buffer = (matrix[i] & 0x01); matrix[i] = (matrix[i] >> 1); matrix[i] |= (buffer << 7); } } void Matrix_PutChar(unsigned char string) { Matrix_NewFrame(ascii[string]); } void Matrix_PutString(unsigned char *string) { uint8_t buffer; uint8_t counter; switch (print_string_status) { case 0: character_buffer[0] = 0; string_length = 0; while(*string != '\0') { character_buffer[string_length] = *string; string_length++; string++; } LPC_TIM1->TCR = 0x02; LPC_TIM1->TCR = 0x00; LPC_TIM1->MCR = 0x19; LPC_TIM1->MR0 = 2; LPC_TIM1->MR1 = SPEED; LPC_TIM1->TCR = 0x01; Matrix_Clear(); print_string_status = 1; current_character = 0; current_collom = 2; break; case 1: buffer = character_buffer[current_character]; for (counter = 0; counter < 8; ++counter) { matrix[counter] = (matrix[counter] >> 1); matrix[counter] &= ~(1 << 7); matrix[counter] |= ((ascii[buffer][counter] & (1 << current_collom)) << (7 - current_collom)); } if(current_collom == (character_length[buffer] + SPACE_LENGTH + 1)) { current_character++; current_collom = 2; } else { current_collom++; } if(current_collom == (character_length[buffer] + 2) && current_character == string_length) { print_string_status = 0; /*RESET TIMER TO ORIGINAL SETTINGS. */ LPC_TIM1->TCR = 0x02; LPC_TIM1->TCR = 0x00; LPC_TIM1->MCR = 0x01; LPC_TIM1->MR0 = 2; LPC_TIM1->MR1 = SPEED; LPC_TIM1->TCR = 0x01; } break; default: break; } } void Matrix_Start(void) { LPC_TIM1->MR0 = 2; //Delay time of 2ms LPC_TIM1->TCR = 0x01; /* start timer */ } void Matrix_Stop(void) { LPC_GPIO1->FIOCLR |= (0xF0F << 20); LPC_GPIO0->FIOSET |= (0x603 << 10); LPC_GPIO2->FIOSET |= (0x39 << 8); LPC_TIM1->TCR = 0x02; LPC_TIM1->TCR = 0; } void TIMER1_IRQHandler (void) { if(LPC_TIM1->IR == 0x01) { LPC_TIM1->IR = 0x01; LPC_TIM1->PC = 0; LPC_TIM1->MR0 += 2; LPC_GPIO1->FIOCLR |= (0xF0F << 20); LPC_GPIO0->FIOSET |= (0x603 << 10); LPC_GPIO2->FIOSET |= (0x39 << 8); Matrix_Update(); } else { LPC_TIM1->IR = 0x02; LPC_TIM1->TCR = 0x02; LPC_TIM1->TCR = 0x00; LPC_TIM1->MR0 = 2; LPC_GPIO1->FIOCLR |= (0xF0F << 20); LPC_GPIO0->FIOSET |= (0x603 << 10); LPC_GPIO2->FIOSET |= (0x39 << 8); Matrix_PutString(" "); LPC_TIM1->TCR = 0x01; } }
matrix.h
void Matrix_Init(void); void Matrix_Update (void); void Matrix_Drawhorizontalline (uint8_t x, uint8_t y, uint8_t length); void Matrix_Drawverticalline (uint8_t x, uint8_t y, uint8_t length); void Matrix_NewFrame(uint8_t array[8]); void Matrix_Clear(void); void Matrix_MoveUP(void); void Matrix_MoveDOWN(void); void Matrix_MoveRIGTH(void); void Matrix_MoveLEFT(void); void Matrix_PutChar(unsigned char string); void Matrix_PutString(unsigned char *string); void Matrix_Start(void); void Matrix_Stop(void);
matrix_font.c
#include "lpc17xx.h" const uint8_t ascii[][8] = 77 I do not write. It is very long /* Array to define the width of a character */ const uint8_t character_length[128] = I do not write. It is very long
matrix_font.h
const uint8_t ascii[100][8]; const uint8_t character_length[100];
main.c
#include "lpc17xx.h" #include "matrix.h" #include "matrix_font.h" #include "timer.h" int main(void) { uint8_t smiley[] = {0x3C,0x42,0xA5,0x81,0xA5,0x99,0x42,0x3C}; uint8_t dinges[] = {0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81}; TimerInit(3,5000); Matrix_Init(); Matrix_Drawhorizontalline(0,2,8); Matrix_Drawhorizontalline(0,5,8); Matrix_Drawverticalline(2,0,8); Matrix_Drawverticalline(5,0,8); Matrix_Start(); delayMs(0,1000); Matrix_NewFrame(smiley); delayMs(0,1000); Matrix_PutChar('3'); delayMs(0,1000); Matrix_PutChar('2'); delayMs(0,1000); Matrix_PutChar('1'); delayMs(0,1000); Matrix_PutString("HELLO WORLD! \0"); delayMs(3,8000); Matrix_NewFrame(dinges); while(1) { Matrix_MoveLEFT(); delayMs(0,100); } }
build compilation
Build target 'Target 1' compiling matrix.c... matrix.c(74): warning: #61-D: integer operation result is out of range matrix.c(74): warning: #68-D: integer conversion resulted in a change of sign matrix.c(83): warning: #61-D: integer operation result is out of range matrix.c(83): warning: #68-D: integer conversion resulted in a change of sign matrix.c(108): warning: #175-D: subscript out of range matrix.c(229): warning: #175-D: subscript out of range matrix.c(256): warning: #175-D: subscript out of range matrix.c(257): warning: #175-D: subscript out of range matrix.c(268): warning: #175-D: subscript out of range matrix.c(275): warning: #175-D: subscript out of range matrix.c(304): error: #167: argument of type "const uint8_t *" is incompatible with parameter of type "uint8_t *" matrix.c(390): warning: #61-D: integer operation result is out of range matrix.c(390): warning: #68-D: integer conversion resulted in a change of sign matrix.c(406): warning: #61-D: integer operation result is out of range matrix.c(406): warning: #68-D: integer conversion resulted in a change of sign matrix.c(420): warning: #61-D: integer operation result is out of range matrix.c(420): warning: #68-D: integer conversion resulted in a change of sign ".\matriztest.axf" - 1 Errors, 16 Warning(s). Target not created
Why didn't you just post: 1) The error messages 2) The source code lines around where the error happened. 3) The variable and type declarations relevant for these source code lines?
Full source code isn't relevant when you get a compilation error.
Especially since the compiler error message normally tells quite well what is wrong.
So - the difference between you and me is that your editor will show you the line numbers matching your error messages.
I can't see that from your post.
None of the error messages seems to be related to any big error earlier in the code but relate to errors on the specific lines the compiler said.
So why not work through the list and correct them one-by-one.
Remember that you have 31 bits available in a signed 32-bit integer before you change the sign of the value. Like:
LPC_GPIO1->FIOCLR |= (0x0F << 28);
Index out of range? Isn't that error message giving you a clear indication of what the compiler finds wrong?
And the error message about const/non-const pointer?
the specific errors are:
summarizing
matrix.c(304): error: #167: argument of type "const uint8_t *" is incompatible with parameter of type "uint8_t *" #167: Matrix_NewFrame(ascii[string]); matrix.c(74): warning: #61-D: integer operation result is out of range #61-d: LPC_GPIO1->FIODIR |= (0x0F << 28); matrix.c(74): warning: #68-D: integer conversion resulted in a change of sign #68-d: LPC_GPIO1->FIODIR |= (0x0F << 28); matrix.c(108): warning: #175-D: subscript out of range #175-d: buffer = matrix[7];
So why do you not then spend some time and think about each error:
uint8_t matrix[7];
Now many elements does this array have? 7? And their indices? 0, 1, 2, 3, 4, 5, 6. So would it then be allowed to use the index 7? Wouldn't that reference the 8th element?
I already pointed in my previous post to your 0x0F << 28, and mentioned the issues with changing sign. So why not consider using an unsigned number then? Like 0x0Fu or (unsigned)0x0F?
Your problem with:
Matrix_NewFrame(ascii[string]);
Matrix_NewFrame() takes an array as a parameter. You haven't shown us what ascii is, except that you treat it as if it can be indexed. But is really ascii really a variable of a type that can be indexed like that and the indexed value will represent an array of 8 uint8_t?
One of the big problems with programming is that you are required to think for every single line of source code you write.