#include <stdint.h>
#include <stdbool.h>
#include "tm4c123gh6pm.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "sysctl.h"
#include "interrupt.h"
#include "gpio.h"
#include "timer.h"
#include "Uarts.h"
void main(void)
{
/*
* 系统时钟配置
*/
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
/*
* 功能模块启动
*/
/* 串口模块启动 对应中断启动 */
Uart_Init_0();
IntMasterEnable();
IntEnable(INT_UART0);
UARTIntEnable(UART0_BASE,UART_INT_TX);
/* LED对应GPIO启动 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
/*
* 发送_测试代码
*/
Uart_Send_0("123\r\n",5); //通过串口打印123
while(UARTBusy(UART0_BASE) == false); //判断是否已经完全发完
}
/////////////////////////////////////////////
串口设置
/////////////////////////////////////////////
#include "Uarts.h"
/*
* 初始化
* 基础打印
*/
void Uart_Init_0()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //配置PA0和PA1为串口0引脚
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8\
| UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
}
bool Uart_Send_0(const uint8_t *pucBuffer, uint32_t ulCount) //串口0发送函数
{
while(ulCount--)
{
if( UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++) == false )
{
return false;
}
}
return true;
}
void printfu(const uint8_t *pucBuffer)
{
while(*pucBuffer!='\0')
{
UARTCharPut(UART0_BASE, *pucBuffer);
*pucBuffer++;
}
}
void hexadecimal_16print(uint32_t origin)
{
uint32_t Value[8];
unsigned char Change[8];
int i;
printfu("0x");
for(i = 7 ; i >= 0 ; i -- )
{
Value = (origin >> (i*4) ) & ( 0x0000000f );
if( Value < 10)
{
Change = Value +'0';
}
else
{
Change = Value - 10 + 'A';
}
UARTCharPut(UART0_BASE, Change);
}
printfu("\r\n");
}
|