int main(void) { unsigned char welcome_str[] = "xxyyzz\r\n"; u8 loop = 1; initPA15(); init_USART1(BT_BAUD); init_LIS302DL(); // setPA15On(); // togglePA15(); while(loop){ //Read and print the accelerometer values LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6); printf("%d, %d ,%d\n",Buffer[0],Buffer[2],Buffer[4]); //Send data through the bluetooth communication UARTSend(welcome_str, sizeof(welcome_str)); //Wait some time befor ending the loop Delay(10000000); } /* Disable SPI1 used to drive the MEMS accelerometre */ SPI_Cmd(LIS302DL_SPI, DISABLE); /* Disable the UART connection */ USART_Cmd(USART1, DISABLE); }
int main(void) { u8 loop = 1; char string[256]; //char string1[256]; uint16_t value; uint16_t sizestring; int icase = 0; initPA15(); init_USART1(BT_BAUD); systick_init(); led_Init(); button_init(); UART2_CONFIG(9600);// DMA_CONFIG(); setPA15On(); togglePA15(); while(loop){ //Send data through the bluetooth communication if (GPIOA->IDR & 0x0001) { if (CheckTick(delay_1,500)) { delay_1 = GetTickCount(); USART_puts(USART1, "troi oi 1 2 3 4 5 6 7 8 9 10\n"); led12(); } } if (CheckTick(delay_2,1000)) { delay_2 = GetTickCount(); //led13(); } if (CheckTick(delay_3,5000)) { delay_3 = GetTickCount(); led14(); } if (CheckTick(delay_4,100)) { delay_4 = GetTickCount(); while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET); //while(DMA_GetFlagStatus(DMA1_Stream2,DMA_FLAG_TCIF1) == RESET); value = USART_ReceiveData(USART1); memset(string,0,sizeof(string[0])*256); // Clear all to 0 so string properly represented sprintf(string,"%c",value); //sizestring = sizeof(string); //sprintf(string1,"%c",sizestring); if (string != NULL) { //USART_puts(USART1,string); if (string != NULL) icase = 1; else if (memchr(string, '2', sizeof(string))) icase = 2; else if (memchr(string, '3', sizeof(string))) icase = 3; else if (memchr(string, '4', sizeof(string))) icase = 4; else if (memchr(string, '5', sizeof(string))) icase = 5; //else icase = 6; switch (icase) { case 1: { USART_puts(USART1,string); icase = 0; led15(); } break; case 2: { USART_puts(USART1,"di xuong"); icase = 0; //led14(); } break; case 3: { USART_puts(USART1,"sang trai"); icase = 0; //led13(); } break; case 4: { USART_puts(USART1,"sang phai"); icase = 0; } break; case 5: { USART_puts(USART1,"can bang"); icase = 0; } break; // case 6: // { // //USART_puts(USART1,string); // icase = 0; // } // break; default: break; } //usart_send_string(string); //USART_SendData(USART1,value); } else { //usart_send_string(string); } led15(); } if (CheckTick(delay_5,250)) { delay_5 = GetTickCount(); } /* Disable the UART connection */ //USART_Cmd(USART1, DISABLE); } }