#include "UART.h"
uint8_t HexTable[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
uint8_t DECTable[]={'0','1','2','3','4','5','6','7','8','9'};
void UART_Init(void)
{
UART1_DeInit();
UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TX_ENABLE);
}
void SendChar(uint8_t dat)
{
while(( UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET));
UART1_SendData8(dat);
}
void SendStr(unsigned char *dat)
{
while(*dat!='\0')
{
SendChar(*dat);
dat++;
}
}
void SendHex8(unsigned char dat)
{
SendChar(' ');
SendChar('0');
SendChar('x');
SendChar(HexTable[dat>>4]);
SendChar(HexTable[dat&0x0f]);
SendChar(' ');
}
void SendHex16(uint16_t Data)
{
SendChar(' ');
SendChar('0');
SendChar('x');
SendChar(HexTable[ Data>>12]);
SendChar(HexTable[(Data>>8)&0x000f]);
SendChar(HexTable[(Data>>4)&0x00f]);
SendChar(HexTable[Data&0x000f]);
SendChar(' ');
}
int DEC[5];
int n=4;
void SendDec(int DECData)
{
int temp=DECData;
DEC[0]=temp%10;
DEC[1]=(temp%100-DEC[0])/10;
DEC[2]=(temp%1000-temp%100)/100;
DEC[3]=(temp%10000-temp%1000)/1000;
DEC[4]=temp/10000;
for(;n>=0;n--)
{
if(DEC[n]==0);
else break;
}
for(;n>=0;n--)
{
SendChar(DECTable[DEC[n]]);
}
n=4;
}
评论0