#include
#include
#include
#include
#include
#include
#include
#include
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
//#define PART_TM4C123GH6PM
#define LED_RED GPIO_PIN_1
#define LED_BLUE GPIO_PIN_2
#define LED_GREEN GPIO_PIN_3
void Uart0SendString(unsigned char *pch);
void UartXPrintf(int UartX, char *fmt,...);
int main(void)
{
uint8_t ui8LED = 2;
uint32_t ui32Period;
char uchUart0Buf[50] = {0};
uint32_t ui32SysClock;
uint32_t ui32SysClockPerSec;
uint32_t ui32ADC0Value[4];
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;
uint32_t ui32ADC0TempValue;
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
ui32SysClock = SysCtlClockGet();
ui32SysClockPerSec = ui32SysClock / 3;
SysCtlDelay(ui32SysClockPerSec);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ui32Period = (SysCtlClockGet() / 1) * 2;
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
//UART0
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//有问题 前面说过解决方法
//GPIOPinConfigure(GPIO_PA0_U0RX);
//GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinConfigure(0x00000001);//GPIO_PA0_U0RX
GPIOPinConfigure(0x00000401);//GPIO_PA1_U0TX
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
Uart0SendString("Hello");
//ADC
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
while(1)
{
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
ui32ADC0TempValue = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
Uart0SendString("ADC0=");
UARTCharPut(UART0_BASE, ui32ADC0TempValue/10000+'0');
UARTCharPut(UART0_BASE, ui32ADC0TempValue%10000/1000+'0');
UARTCharPut(UART0_BASE, ui32ADC0TempValue%1000/100+'0');
UARTCharPut(UART0_BASE, ui32ADC0TempValue%100/10+'0');
UARTCharPut(UART0_BASE, ui32ADC0TempValue%10+'0');
Uart0SendString("\r\n");
SysCtlDelay(ui32SysClockPerSec);
}
}
[ 本帖最后由 upc_arm 于 2013-12-5 00:15 编辑 ]
|