dsp28335
采集程序如下
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
/********************************宏定义数码管位选 IO 接口*******************************************/
#define SET_BIT4GpioDataRegs.GPCSET.bit.GPIO70 = 1 //与外设板 8_LEDS 端子的 IO70 对应
#define RST_BIT4GpioDataRegs.GPCCLEAR.bit.GPIO70 = 1//与外设板 8_LEDS 端子的 IO70 对应
#define SET_BIT3 GpioDataRegs.GPCSET.bit.GPIO71 = 1//与外设板 8_LEDS 端子的 IO71 对应
#define RST_BIT3GpioDataRegs.GPCCLEAR.bit.GPIO71 = 1//与外设板 8_LEDS 端子的 IO71 对应
#define SET_BIT2 GpioDataRegs.GPCSET.bit.GPIO72 = 1//与外设板 8_LEDS 端子的 IO72 对应
#define RST_BIT2GpioDataRegs.GPCCLEAR.bit.GPIO72 = 1//与外设板 8_LEDS 端子的 IO72 对应
#define SET_BIT1 GpioDataRegs.GPCSET.bit.GPIO73 = 1//与外设板 8_LEDS 端子的 IO73 对应
#define RST_BIT1GpioDataRegs.GPCCLEAR.bit.GPIO73 = 1//与外设板 8_LEDS 端子的 IO73 对应
/*****************************************************************************************************/
/*********************************************函数申明************************************************/
void delay(Uint32 t);
void DisData_Trans(Uint16 data);
void Sellect_Bit(Uint16 i);
void Init_LEDS_Gpio(void);
//void delay(Uint32 t);
/*****************************************************************************************************/
/************************************定义相关变量*********************************************/
unsigned char msg[10]={0xC0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//段码:0~9
unsigned char DisData_Bit[4] = {0};//存放拆分后的四位数字
Uint16 DisData = 0;//显示的数字
Uint16 Loop = 0;
/****************函数声明*******************/
void delay_loop(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
static void Lookup_TAB(Uint16 data,const Uint16 *TABLE,Uint16 *aptr);
//void error(void);
//extern void CharDisplay(Uint16 s, Uint16 LedBuffer[]);
/***************全局变量定义****************/
Uint16 LedBuffer[2];
Uint16 showdata;
// ADC start parameters
#define ADC_MODCLK 0x5 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*4) = 15MHz
// for 60 MHz devices: HSPCLK = 60/(2*4) = 7.5 MHz
#define ADC_CKPS 0x1 // ADC module clock = HSPCLK/2*ADC_CKPS = 15MHz/(1*2) = 7.5MHz
#define ADC_SHCLK 0xf // S/H width in ADC module periods = 16 ADC clocks
#define AVG 100 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 2048 // Sample buffer size
// Global variable for this example
Uint16 SampleTable[BUF_SIZE];
static const Uint16 NTCTAB[101] ={3768 ,3760 ,3752 ,3744 ,3736 ,3727 ,3718 ,3708 ,3698 ,3688 ,
3677 ,3666 ,3655 ,3643 ,3631 ,3618 ,3605 ,3591 ,3577 ,3563 ,3548 ,3532 ,3516 ,
3500 ,3483 ,3466 ,3448 ,3430 ,3411 ,3392 ,3372 ,3351 ,3330 ,3309 ,3287 ,3266,
3243 ,3219 ,3195 ,3171 ,3146 ,3121 ,3095 ,3069 ,3042 ,3015 ,2987 ,2960 ,2931 ,
2902 ,2873 ,2844 ,2814 ,2784 ,2754 ,2723 ,2692 ,2661 ,2629 ,2597 ,2565 ,2533 ,
2500 ,2468 ,2436 ,2403 ,2370 ,2337 ,2304 ,2271 ,2238 ,2205 ,2172 ,2141 ,2108 ,
2074 ,2041 ,2008 ,1976 ,1944 ,1912 ,1880 ,1848 ,1817 ,1785 ,1755 ,1724 ,1693 ,
1663 ,1634 ,1604 ,1574 ,1546 ,1517 ,1488 ,1460 ,1433 ,1406 ,1380 ,1353 ,1327 };
main()
{
Uint16 i;
Uint32 Sum=0;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP280x_SysCtrl.c file.
InitSysCtrl();
// Specific clock setting for this example:
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK;// HSPCLK = SYSCLKOUT/(2*ADC_MODCLK)=15MHZ
EDIS;
// Step 2. Initialize GPIO:
// This example function is found in the DSP280x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// 次函数在DSP280x_Spi.c文件里面
InitSpiaGpio(); //开发板使用SPIa
Init_LEDS_Gpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP280x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP280x_DefaultIsr.c.
// This function is found in DSP280x_PieVect.c.
InitPieVectTable();
// 步骤 4.初始化片内外设:
InitAdc(); // For this example, init the ADC
spi_fifo_init(); // 初始化Spi的FIFO
spi_init(); // 初始化SPI
// Specific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;//设置采样窗口时间:(15+1)*ADCCLK
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;//ADC内核时钟分频:HSPCLK/2=6.25MHZ
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1选择级联模式
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x1; //通道选择ADCAIN1
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // 设置为连续运行
// Step 5.用户指定代码,使能中断:
// 采样表清0
for (i=0; i<BUF_SIZE; i++)
{
SampleTable[i] = 0;
}
//关数码管;
spi_xmit(0xFFFF);
//延迟
delay_loop();
// 软件启动SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
// 取ADC数据并写入采样数据表
for(;;)
{
for (i=0; i<AVG; i++)
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // 等待中断
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[i] =(AdcRegs.ADCRESULT0>>4);
}
//对采样的100个值求平均滤波
for (i=0;i<AVG;i++)
{
Sum+=SampleTable[i];
Sum=Sum/2;
}
//超过最大温度或低于最小温度时的处理;
Uint16 Array[3];
if(Sum < NTCTAB[0]) //?Beyond Lowest Temperature
{
if(Sum > NTCTAB[100]) //?Beyond Highest Temperature
{
Lookup_TAB(Sum,NTCTAB,Array); //Lookup data
showdata=Array[0];
}
else showdata = 8888; //mark Underflow
}
else showdata = 9999; //mark Overflow
for(i=0;i<100;i++)
{
DisData_Trans(showdata);//拆分四位数
for(Loop=0;Loop<4;Loop++)//分别显示四位
{
Sellect_Bit(Loop); //选择要扫描的数码管位
if(Loop==1) //第二位数字后加小数点
spi_xmit(msg[DisData_Bit[Loop]]+0x80);
else
spi_xmit(msg[DisData_Bit[Loop]]);//串行输出要显示的数字
delay(25000);//延时配合人眼反应时间
}
}
}
}
//延迟函数
void delay_loop()
{
long i;
for (i = 0; i < 4500000; i++) {}
}
//初始化SPI函数
void spi_init()
{
SpiaRegs.SPICCR.all =0x004F;// SPI软件复位, 极性位为1(下降沿发送数据), 每次移
//进和移出16位字长度;禁止SPI内部回送(LOOKBACK)功能;
SpiaRegs.SPICTL.all =0x0006; // 使能主机模式,正常相位,使能主机发送,禁止接收
//溢出中断,禁止SPI中断;
SpiaRegs.SPIBRR =0x007F;//SPI波特率=25M/128=195.3KHZ;
SpiaRegs.SPICCR.all =0x00CF;//停止SPI软件复位准备接收或发送;禁止回送模式;
SpiaRegs.SPIPRI.bit.FREE = 1; // 自由运行
}
//发送SPI数据
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF=a;
}
//初始化SPI FIFO
void spi_fifo_init()
{
SpiaRegs.SPIFFTX.all=0xE040;//使能FIFO;清除发送中断标志位;禁止FIFO发送中断;
//发送中断级别定义为0;
SpiaRegs.SPIFFRX.all=0x204f;//清除FF溢出标志位;清除溢出接受中断标志位;禁止
//FF接受中断;接受中断级别为16;
SpiaRegs.SPIFFCT.all=0x0;//SPITXBUF到移位寄存器传送不延迟;
}
2017年06月03日 00点06分
3