Fujiko
Thành Viên PIF
Em có viết (copy và sửa) 1 đoạn code chuyển đổi ADC, hiển thị UART. Khi chạy tầm 10p, rút ra thì thấy kit khá nóng nóng, "ấm ấm" .
Như vậy có sao không ac? Lúc trước xài con MSP430 thì nó mát lạnh. Hay do con Tiva C này có xung clock cao hơn nhiều so với con MSP430???
Đây là code em xài.
//Tặng ac nụ hôn nồng thắm ":*"
Như vậy có sao không ac? Lúc trước xài con MSP430 thì nó mát lạnh. Hay do con Tiva C này có xung clock cao hơn nhiều so với con MSP430???
Đây là code em xài.
//Tặng ac nụ hôn nồng thắm ":*"
Code:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/uart.h"
#include "driverlib/gpio.h"
int main( void)
{
//uint32_tulADC0Value[6];
uint32_t ulADC0Value[8];
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;
SysCtlClockSet (SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //Enable UART Peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //Enable Port A Peripheral
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
//Configure UART; Baud Rate Set to 115200, WLEN (Word length/No. of Data Bits) set to 8, One Stop Bits, Parity None
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); //PA0 - U0RX, PA1 = U0TX
UARTFIFOEnable(UART0_BASE); // UART FIFO Buffer Enable
UARTEnable(UART0_BASE); //Enable UART
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);
//PE3-2-1-0 la chan ADC Input
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0); //Sequencer Step 0: Samples Channel PE3
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1); //Sequencer Step 1: Samples Channel PE2
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2); //Sequencer Step 2: Samples Channel PE1
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3); //Sequencer Step 3: Samples Channel PE0
/* ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
ADCSequenceStepConfigure (ADC0_BASE, 1, 1, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
*/
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_TS); //Sequencer Step 4: Samples Temperature Sensor
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_TS); //Sequencer Step 5: Samples Temperature Sensor
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_TS); //Sequencer Step 6: Samples Temperature Sensor
ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
//Final Sequencer Step also Samples and enables Interrupt and we are telling the sequencer that this is the last step
ADCSequenceEnable(ADC0_BASE, 0); //Enable ADC Sequence
while (1)
{
ADCIntClear(ADC0_BASE, 0);
ADCProcessorTrigger(ADC0_BASE, 0);
while (!ADCIntStatus (ADC0_BASE, 0, false))
{
}
ADCSequenceDataGet (ADC0_BASE, 0, ulADC0Value);
ui32TempAvg = (ulADC0Value[4] +ulADC0Value[5] +ulADC0Value[6] +ulADC0Value[7] + 2)/4;
ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
char x[4], y[4], z[4], w[4], a[4]; //Character arrays for storing ADC Data for TX
a[3] =ui32TempAvg%10 + 48;
ui32TempAvg =ui32TempAvg/10 ;
a[2] =ui32TempAvg%10 + 48;
ui32TempAvg =ui32TempAvg/10 ;
a[1] =ui32TempAvg%10 + 48;
a[0] =ui32TempAvg/10 + 48;
x[3] = ulADC0Value[0]%10 + 48;
ulADC0Value[0] = ulADC0Value[0]/10 ;
x[2] = ulADC0Value[0]%10 + 48;
ulADC0Value[0] = ulADC0Value[0]/10 ;
x[1] = ulADC0Value[0]%10 + 48;
x[0] = ulADC0Value[0]/10 + 48;
y[3] = ulADC0Value[1]%10 + 48;
ulADC0Value[1] = ulADC0Value[1]/10 ;
y[2] = ulADC0Value[1]%10 + 48;
ulADC0Value[1] = ulADC0Value[1]/10 ;
y[1] = ulADC0Value[1]%10 + 48;
y[0] = ulADC0Value[1]/10 + 48;
z[3] = ulADC0Value[2]%10 + 48;
ulADC0Value[2] = ulADC0Value[2]/10 ;
z[2] = ulADC0Value[2]%10 + 48;
ulADC0Value[2] = ulADC0Value[2]/10 ;
z[1] = ulADC0Value[2]%10 + 48;
z[0] = ulADC0Value[2]/10 + 48;
w[3] = ulADC0Value[3]%10 + 48;
ulADC0Value[3] = ulADC0Value[3]/10 ;
w[2] = ulADC0Value[3]%10 + 48;
ulADC0Value[3] = ulADC0Value[3]/10 ;
w[1] = ulADC0Value[3]%10 + 48;
w[0] = ulADC0Value[3]/10 + 48;
UARTCharPutNonBlocking(UART0_BASE, x[0]); // Put Character in UART Transmit Buffer
UARTCharPutNonBlocking(UART0_BASE, x[1]);
UARTCharPutNonBlocking(UART0_BASE, x[2]);
UARTCharPutNonBlocking(UART0_BASE, x[3]);
UARTCharPutNonBlocking(UART0_BASE, ' ');
SysCtlDelay(10000);
UARTCharPutNonBlocking(UART0_BASE, y[0]);
UARTCharPutNonBlocking(UART0_BASE, y[1]);
UARTCharPutNonBlocking(UART0_BASE, y[2]);
UARTCharPutNonBlocking(UART0_BASE, y[3]);
UARTCharPutNonBlocking(UART0_BASE, ' ');
SysCtlDelay(10000);
UARTCharPutNonBlocking(UART0_BASE, z[0]);
UARTCharPutNonBlocking(UART0_BASE, z[1]);
UARTCharPutNonBlocking(UART0_BASE, z[2]);
UARTCharPutNonBlocking(UART0_BASE, z[3]);
UARTCharPutNonBlocking(UART0_BASE, ' ');
SysCtlDelay(10000);
UARTCharPutNonBlocking(UART0_BASE, w[0]);
UARTCharPutNonBlocking(UART0_BASE, w[1]);
UARTCharPutNonBlocking(UART0_BASE, w[2]);
UARTCharPutNonBlocking(UART0_BASE, w[3]);
UARTCharPutNonBlocking(UART0_BASE, ' ');
SysCtlDelay(10000);
UARTCharPutNonBlocking(UART0_BASE, a[0]);
UARTCharPutNonBlocking(UART0_BASE, a[1]);
UARTCharPutNonBlocking(UART0_BASE, a[2]);
UARTCharPutNonBlocking(UART0_BASE, a[3]);
UARTCharPutNonBlocking(UART0_BASE, ' ');
UARTCharPutNonBlocking(UART0_BASE, '\n');
SysCtlDelay(2000000);
}
}