void Send_4Bit_Num(unsigned short num) { UART1_SendByte(num/1000 + 0x30); UART1_SendByte(num%1000/100 + 0x30); UART1_SendByte(num%100/10 + 0x30); UART1_SendByte(num%10 + 0x30); }
//This function is UART0 Receive ISR. This functions is called whenever UART0 receives any data void vsend(void *pvparam) { while(1) { UART1_SendStr(sen_dat); UART1_SendByte(0x00); UART1_SendByte(0xFF); vTaskDelay(1000); } }
void UART1_SendString(unsigned char * data) { do { UART1_SendByte(*data); } while(*++data != '\0'); }
void UART1_SendStr(char *str) { while (*str != '\0') { UART1_SendByte(*str++); // 發送數據 while (!(IFG2 & UTXIFG1)); } }
/******************************************************************************* * 名称: fputc * 功能: 重定向c库函数printf到UART1 * 形参: 无 * 返回: 要打印的字符 * 说明: 由printf调用 ******************************************************************************/ int fputc(int ch, FILE *f) { /* 将Printf内容发往串口 */ UART1_SendByte(ch); return (ch); }
/******************************************************************************************* * 函数名:UART1_SendString() * 参数 :uint8_t *s 指向字符串的指针 * 返回值:void * 描述 :UART1发送字符串函数 *********************************************************************************************/ void UART1_SendString(uint8_t *s) { while(*s) //判断是否到字符串末尾 { UART1_SendByte(*s); //发送指针当前所指的字节 s++; //地址加1 } }
/******************************************************************************************* * 函数名:UART1_Handler() * 参数 :void * 返回值:void * 描述 :UART1中断服务函数 *********************************************************************************************/ void UART1_Handler(void) { uint8_t temp; if((UART1->UART_SR& UART_SR_RXRDY)==1) { //接收数据中断 temp= UART1->UART_RHR&0xff; //接收一个字节 UART1_SendByte(temp); //将接收的数据发回 } }
void Flash_eeprom_readwrite_Test(void) { TestStatus OperationStatus; u32 add, start_add, stop_add =0; u8 WriteBuffer[FLASH_BLOCK_SIZE]; u8 new_value[FLASH_BLOCK_SIZE] = "This is a Flash_eeprom write and read example......\ This is a Flash_eeprom write and read example....---lingguansheng---2012-2-20"; u8 block, i=0 ; /* Fill the buffer in RAM */ for (i = 0; i < FLASH_BLOCK_SIZE; i++) WriteBuffer[i] =new_value[i]; /* Program the block 0*/ block = 0; /* block 0 is first block of Data memory: address is 0x4000 */ FLASH_ProgramBlock(block, FLASH_MEMTYPE_DATA, FLASH_PROGRAMMODE_STANDARD, WriteBuffer); FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA); /* Check the programmed block */ start_add = FLASH_DATA_START_PHYSICAL_ADDRESS; stop_add = FLASH_DATA_START_PHYSICAL_ADDRESS + (u32)FLASH_BLOCK_SIZE; for (add = start_add; add < stop_add; add++) { if (FLASH_ReadByte(add) != new_value[add-start_add]) { /* Error */ OperationStatus = FAILED; /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ while (1); } } for (add = start_add; add < stop_add; add++) { UART1_SendByte(FLASH_ReadByte(add)); Delay(0xffff); } }
void ReadyMeasure(void) { int i; UART1_SendByte(0xC0); for(i=0;i<5;i++) { delay(1000); } UART1_SendByte(0xC1); delay(50); // UART1_SendByte(0X31); UART1_SendByte(0X03); UART1_SendByte(0X00); UART1_SendByte(0X04); UART1_SendByte(0X00); }
/** * @brief Send Data. * @param *Data: Data address. * @param len: Data length. * @retval None */ void UART1_SendString(uint8_t* Data, uint32_t len) { int32_t i=0; for (; i<len; i++) UART1_SendByte(Data[i]); }
/******************************************************************************* * 名称: UART1_SendString * 功能: UART1发送len个字符 * 形参: data -> 指向要发送的字符串 * len -> 要发送的字节数 * 返回: 无 * 说明: 无 ******************************************************************************/ void UART1_SendString(u8* Data,u16 len) { u16 i=0; for(; i < len; i++) UART1_SendByte(Data[i]); /* 循环调用发送一个字符函数 */ }