TA的每日心情 | 郁闷 2012-10-29 10:59 |
---|
签到天数: 9 天 连续签到: 1 天 [LV.3]偶尔看看II
|
本帖最后由 spring 于 2013-1-9 12:47 编辑
LM4F Launchpad之AD
今天上班才发现自己弄好的没有上传,今天最后一天征文了,获不获奖不重要,主要是分享一下,相互交流,同时也表示对爱板网的支持
可能有些地方没有考虑全面,做的还不够好,欢迎大家随时来拍砖,
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "utils/uartstdio.h"
void InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);
}
int main(void)
{
unsigned long ulADC0_Value[1];
unsigned long ulTemp_ValueC;
unsigned long ulTemp_ValueF;
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
InitConsole();
UARTprintf("ADC ->\n");
UARTprintf(" Type: Internal Temperature Sensor\n");
UARTprintf(" Samples: One\n");
UARTprintf(" Update Rate: 250ms\n");
UARTprintf(" Input Pin: Internal temperature sensor\n\n");
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE |ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 3);
while(1)
{
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value);
// ulTemp_ValueC = ((1475 * 1023) - (2250 * ulADC0_Value[0])) / 10230;
ulTemp_ValueC = ((1475 * 4095) - (2250 * ulADC0_Value[0])) / 40950;
ulTemp_ValueF = ((ulTemp_ValueC * 9) + 160) / 5;
UARTprintf("Temperature = %3d*C or %3d*F\r", ulTemp_ValueC,ulTemp_ValueF);
SysCtlDelay(SysCtlClockGet() / 12);
}
}
操作图及程序.doc
(432.5 KB, 下载次数: 38)
|
|