void SND_Stop() { UART_SendByte(UART_2, 0x7e); UART_SendByte(UART_2, 0x02); UART_SendByte(UART_2, 0x0e); UART_SendByte(UART_2, 0xef); }
void SND_Play() { UART_SendByte(UART_2, 0x7e); UART_SendByte(UART_2, 0x01); UART_SendByte(UART_2, 0x0e); UART_SendByte(UART_2, 0xef); }
static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; char *ptr; ptr = (char*)buffer; if (dev->flag & RT_DEVICE_FLAG_STREAM) { /* stream mode */ while (size) { if (*ptr == '\n') { while (!(uart->UART->LSR & UART_LSR_THRE)); UART_SendByte( uart->UART,'\r'); } while (!(uart->UART->LSR & UART_LSR_THRE)); UART_SendByte( uart->UART,*ptr); ptr ++; size --; } } else { UART_Send( uart->UART, (uint8_t *)buffer, size, BLOCKING); } return (rt_size_t) ptr - (rt_size_t) buffer; }
//void SND_Play() //{ // UART_SendByte(UART_0, 0x7e); // UART_SendByte(UART_0, 0x01); // UART_SendByte(UART_0, 0x0e); // UART_SendByte(UART_0, 0xef); //} void SND_Init() { UART_SendByte(UART_0, 0x7e); UART_SendByte(UART_0, 0x03); UART_SendByte(UART_0, 0x33); UART_SendByte(UART_0, 0x04); UART_SendByte(UART_0, 0xef); }
/** * Function send via UART characters terminating * data sending to modem. */ static void GSM_TerminateDataSending(void) { while(UART_CheckBusy(UARTx)); UART_SendByte(UARTx, 0x1A); while(UART_CheckBusy(UARTx)); UART_SendByte(UARTx, 0x0D); while(UART_CheckBusy(UARTx)); UART_SendByte(UARTx, 0x0A); while(UART_CheckBusy(UARTx)); }
/*------------------------------------------------ 发送一个字符串 ------------------------------------------------*/ void UART_SendStr(unsigned char *s) { UART_SendByte('\r'); UART_SendByte('\n'); while(*s!='\0')// \0 表示字符串结束标志, //通过检测是否字符串末尾 { UART_SendByte(*s); s++; } }
/*********************************************************************//** * @brief Send a block of data via UART peripheral * @param[in] UARTx Selected UART peripheral used to send data, should be: * - LPC_UART0: UART0 peripheral * - LPC_UART1: UART1 peripheral * - LPC_UART2: UART2 peripheral * - LPC_UART3: UART3 peripheral * @param[in] txbuf Pointer to Transmit buffer * @param[in] buflen Length of Transmit buffer * @param[in] flag Flag used in UART transfer, should be * NONE_BLOCKING or BLOCKING * @return Number of bytes sent. * * Note: when using UART in BLOCKING mode, a time-out condition is used * via defined symbol UART_BLOCKING_TIMEOUT. **********************************************************************/ uint32_t UART_Send(LPC_UART_TypeDef *UARTx, uint8_t *txbuf, uint32_t buflen, TRANSFER_BLOCK_Type flag) { uint32_t bToSend, bSent, timeOut, fifo_cnt; uint8_t *pChar = txbuf; bToSend = buflen; // blocking mode if (flag == BLOCKING) { bSent = 0; while (bToSend){ timeOut = UART_BLOCKING_TIMEOUT; // Wait for THR empty with timeout while (!(UARTx->LSR & UART_LSR_THRE)) { if (timeOut == 0) break; timeOut--; } // Time out! if(timeOut == 0) break; fifo_cnt = UART_TX_FIFO_SIZE; while (fifo_cnt && bToSend) { UART_SendByte(UARTx, (*pChar++)); fifo_cnt--; bToSend--; bSent++; } while (!(UARTx->LSR & UART_LSR_THRE)) { if (timeOut == 0) break; timeOut--; } } } // None blocking mode else { bSent = 0; while (bToSend) { if (!(UARTx->LSR & UART_LSR_THRE)){ break; } fifo_cnt = UART_TX_FIFO_SIZE; while (fifo_cnt && bToSend) { UART_SendByte(UARTx, (*pChar++)); bToSend--; fifo_cnt--; bSent++; } } } return bSent; }
void uart_send_32_Hex(char Data){ if(Data >= 0x10){ uart_send_32_Hex(Data/0x10); uart_send_32_Hex(Data%0x10); } else{ if(Data < 0xA){ UART_SendByte(DBG_UART, Data+'0'); } else{ UART_SendByte(DBG_UART, ((Data-0x0A)+'A')); } } }
/** * @brief 串口 printf 函数, 使用时必须以'\n'结尾,默认使用串口0发送 * @param s 待发送字符串 */ void PrintStr(u8 *s) { while(*s != '\0') { UART_SendByte(UART_0,*s++); } }
void UARTPutChar(LPC_UART_TypeDef *UARTx,uint8 ch) { #if 0 U0THR = pBuf[i]; while( (U0LSR&0x20)==0 ); LPC_UartWrite(uartPortNr, &ch, 1, 0); #endif { uint32_t timeOut; timeOut = UART_BLOCKING_TIMEOUT; // Wait for THR empty with timeout while (!(UARTx->LSR & UART_LSR_THRE)) { if (timeOut == 0) break; timeOut--; } // Time out! if(timeOut == 0){ innerDeadNoOutput(); } UART_SendByte(UARTx, ch); } }
/*====================================================================================================*/ void UART_SendData( NRF_UART_Type *UARTx, int8_t *SendData, uint16_t DataLen ) { do { UART_SendByte(UARTx, SendData); SendData++; } while(--DataLen); }
/*====================================================================================================*/ void RS232_SendStr( u8 *pWord ) { while(*pWord != '\0') { UART_SendByte(USARTx, *pWord); pWord++; } }
/*====================================================================================================*/ void UART_SendData( USART_TypeDef *USARTx, int8_t *SendData, uint16_t DataLen ) { do { UART_SendByte(USARTx, SendData); SendData++; } while(--DataLen); }
void RS232_Send_Char(char *str,int count,unsigned char com) { for(int i=0;i<count;i++) { UART_SendByte(*str++,com); // 發送數據 } }
/*====================================================================================================*/ void RS232_SendStr( int8_t *pWord ) { while(*pWord != '\0') { UART_SendByte(USARTx, pWord); pWord++; } }
void sio_putstr(char *cptr) { uint8_t byteSend = 0; Disable_global_interrupt(); if( checkIfFifoEmpty & (!checkIfDataToSend) ) { // nothing in queue data can be transmited directly // to uart FIFO resetFifo; while( (*cptr!='\0') & (byteSend < UART_TX_FIFO_SIZE) ) { UART_SendByte(SERIAL_USART, (*cptr++) ); byteSend++; } } //FIFO full save data in buffer while(*cptr) { uartDataToSend.txbuf[uartDataToSend.lastPtr++] = (*cptr++); byteSend = 0xff; } if(byteSend == 0xff) { uartDataToSend.txbuf[uartDataToSend.lastPtr] = '\0'; } Enable_global_interrupt(); return; }
/** * @brief 串口发送字符串函数 * @param NumberTypeDef 串口号 @ref UART_NumberTypeDef * @param str 字符串指针 * @param u16length 发送长度 */ void UART_SendStr(UART_NumberTypeDef NumberTypeDef, u8 *str, u16 u16length) { u16 i = 0; for(i=0; i<u16length; i++) { UART_SendByte(NumberTypeDef, *(str+i)); } }
__interrupt void UART1_RX_ISR(void) { u8 u8data = 0; /*接收到的数据存起来*/ u8data = U1RXBUF; /*将接收到的数据再发送出去*/ UART_SendByte(UART_1, u8data); }
/*====================================================================================================*/ void UART_SendData( u8 *SendData, u16 DataLen ) { do { UART_SendByte(*SendData); SendData++; DataLen--; } while(DataLen); }
/* 函数原型:void Send_result(unsigned char* buff,unsigned char num) 参数说明:USARTx:串口编号: USART1 USART2 buff:发送的内容buffer num:发送内容长度 功能描述:串口发数据 返回状态:无 备注: 无 */ void Send_Uart_result(USART_TypeDef* USARTx,unsigned char* buff,unsigned char num) { unsigned char i; for(i=0;i<num;i++) { UART_SendByte(USARTx,buff[i]); } }
/** * @brief This function send a command to 95HF device over UART bus * @param *pData : pointer on data to send to the 95HF device * @retval None */ static void drv95HF_SendUARTCommand(uc8 *pData) { if(pData[0] == ECHO) /* send Echo */ UART_SendByte(RFTRANS_95HF_UART, ECHO); else /* send the buffer over UART */ UART_SendBuffer(RFTRANS_95HF_UART, pData, pData[RFTRANS_95HF_LENGTH_OFFSET] + RFTRANS_95HF_DATA_OFFSET); }
void UART_SendStr(char *str,unsigned char com) { while (*str != '\0') { UART_SendByte(*str++,com); // 發送數據 } // UART_COM1_RX_count=0; // UART_COM2_RX_count=0; // 20110310修改 發送命令後清除BUFF內資料 // UART_COM3_RX_count=0; }
void GSM_SendSMS(uint8_t* number, uint8_t* data) { //NVIC_DisableIRQ(UART1_IRQn); GSM_SerialSendString("AT+CMGF=1\r"); delay_ms(100);//while(!OKFlag); GSM_SerialSendString("at+CMGS=\""); GSM_SerialSendString(number); GSM_SerialSendString("\"\r"); promptReceived=0; //while(!sendDataFlag); promptReceived=0; GSM_SerialSendString(data); while(UART_CheckBusy(UARTx)); UART_SendByte(UARTx, 0x1A); while(UART_CheckBusy(UARTx)); UART_SendByte(UARTx, 0x0D); while(UART_CheckBusy(UARTx)); UART_SendByte(UARTx, 0x0A); NVIC_EnableIRQ(UART1_IRQn); }
/*====================================================================================================*/ void Serial_SendNum( StringType type, uint8_t lens, int32_t sendNum ) { char tmpStr[32] = {0}; char *pWord = tmpStr; num2Str(type, lens, tmpStr, sendNum); while(*pWord != '\0') { UART_SendByte(UARTx, (uint8_t*)pWord++); } }
/*------------------------------------------------ 发送一个ASCII码 ------------------------------------------------*/ void UART_SendASCII(U8 bDat) { U8 i; U8 bTmpDat[2]; bTmpDat[0] = bDat >> 4; // High 4 bit bTmpDat[1] = bDat & 0x0F; // Low 4 bit for(i = 0; i < 2; i++) { if (bTmpDat[i] < 10) { UART_SendByte(48 + bTmpDat[i]); } else { UART_SendByte(65 + bTmpDat[i] - 10); } } }
/*====================================================================================================*/ void RS232_SendNum( StrType Type, uint8_t NumLen, int32_t SendData ) { char TrData[32] = {0}; char *pWord = TrData; Str_NumToChar(Type, NumLen, TrData, SendData); while(*pWord != '\0') { UART_SendByte(UARTx, (uint8_t*)pWord++); } }
/*====================================================================================================*/ void RS232_SendNum( StrType Type, uint8_t NumLen, int32_t SendData ) { int8_t TrData[32] = {0}; int8_t *pWord = TrData; Str_NumToChar(Type, NumLen, TrData, SendData); while(*pWord != '\0') { UART_SendByte(USARTx, pWord); pWord++; } }
/*====================================================================================================*/ void RS232_SendNum( u8 Type, u8 NumLen, s32 SendData ) { u8 TrData[32] = {0}; u8 *pWord = TrData; Str_NumToChar(Type, NumLen, TrData, SendData); while(*pWord != '\0') { UART_SendByte(USARTx, *pWord); pWord++; } }
BOOL xMBMasterPortSerialPutByte(RS485_NUM RS485_X,CHAR ucByte) { switch(RS485_X) { case RS485_1: UART_SendByte(LPC_UART0,ucByte); break; case RS485_2: UART_SendByte(LPC_UART2,ucByte); break; case RS485_3: UART_SendByte(LPC_UART3,ucByte); break; case RS485_4: UART_SendByte((LPC_UART_TypeDef *)LPC_UART4,ucByte); break; default: return FALSE; } return TRUE; }
void UART_PrintfU4(u08 Data){ /* Send 4-bit hex value */ u08 Character = Data&0x0f; if (Character>9) { Character+='A'-10; } else { Character+='0'; } UART_SendByte(Character); }