(永辉电子DSP 的板子 )
扭动滑动变阻器 改变电压
代码:
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include <bsp_includes.h>
#if (TFTLCD_TEST == 1)
uchar class[]= {"班级 :"};
uchar Name[]= {"姓名: "};
uchar student_ID[]={"学号: "};
uchar Str1[] = {"题目: 数字电压表测试 "};//方向的提示语句
uchar Str2[] = {"电压: "};
#endif
#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
Uint16 SampleTable[BUF_SIZE];
float Vin=0;
float mm=1;
float m1=1;
int a1;
int a2;
int a3;
int a4;
//函数入口
void main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EINT;
ERTM;
InitXintf();
InitSpiaGpio();
int temp;
Uint16 i;
Uint32 Sum=0;
/*初始化系统*/
InitSysCtrl();
// Specific clock setting for this example:
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK=1;//ADC
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/(2*ADC_MODCLK)=15MHZ
EDIS;
/*初始化GPIO;*/
//InitSpiaGpio();
/* 关中断 */
DINT;
IER = 0x0000;
IFR = 0x0000;
/* 初始化PIE控制寄存器 */
InitPieCtrl();
/* 初始化PIE参数表 */
InitPieVectTable();
// 步骤 4.初始化片内外设:
InitAdc(); // For this example, init the ADC
///初始化SPI
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// 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 = 0x0; //通道选择ADCAIN0
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // 设置为连续运行
AdcRegs.ADCMAXCONV.bit.MAX_CONV1=0x0;
// 采样表清0
for (i=0; i<BUF_SIZE; i++)
{
SampleTable[i] = 0;
}
// 软件启动SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
i=0;
//TFTLCD实验
#if (TFTLCD_TEST == 1)
ILI9325_Init(); //TFT初始化
//显示字符
LCD_PutString(37, 20,Str1, BLUE,WHITE);
LCD_PutString(37, 40,class, WHITE,RED);
LCD_PutString(37, 60,Name, WHITE,RED);
LCD_PutString(37, 80,student_ID, RED,WHITE);
LCD_PutString(37, 100,Str2, WHITE,RED);
#endif
while (1)
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0)
{
} // 等待中断
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[i++] =((AdcRegs.ADCRESULT0>>4) );
if(i>(BUF_SIZE-1))
{
for(i=0;i<BUF_SIZE;i++)
{
mm+=SampleTable[i];
}
mm=mm/2048/1000;
a4=(int)(mm*100);
a1=a4/100;
a2=a4%100/10;
a3=a4%10;
uchar kk[5];
kk[0]=a1+48;
kk[2]=a2+48;
kk[1]='.';
kk[3]=a3+48;
kk[4]=0;
LCD_PutString(100, 100,kk, WHITE,RED);
mm=0;
i=0;
}
}
}