/*****************************************************************************
Copyright: 2013
File name: main.c
Description: DSP280x的数模转换设计
Author:
Version: 1.0
Date: 2013.07.23
History: 无
*****************************************************************************/
#include "DSP280x_Device.h"
#include "DSP280x_Examples.h"
unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void init(void)
{
EALLOW;
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO15=0;
GpioCtrlRegs.GPADIR.bit.GPIO15=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO27=0;
GpioCtrlRegs.GPADIR.bit.GPIO27=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO30=0;
GpioCtrlRegs.GPADIR.bit.GPIO30=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO31=0;
GpioCtrlRegs.GPADIR.bit.GPIO31=1;
EDIS;
}
void delay(int k)
{
int i,j;
for(i=0;i<2505;i++)
for(j=k;j>0;j--);
}
void display(unsigned char dua)
{
int k;
for(k=0;k<8;k++)
{
GpioDataRegs.GPADAT.bit.GPIO15=0;
GpioDataRegs.GPADAT.bit.GPIO27=(dua&0x80)>>7;
GpioDataRegs.GPADAT.bit.GPIO15=1;
dua=dua<<1;
}
GpioDataRegs.GPADAT.bit.GPIO31=0;
GpioDataRegs.GPADAT.bit.GPIO31=1;
}
void displaynum(unsigned char num,unsigned char wei)
{
display(num);
display(wei);
}
/*************************************************
Function: AD_init()
Description: 初始化函数
Calls: NULL
Called By: main()
Table Accessed:
Table Updated:
Input:
Output:
Return:
Others:
*************************************************/
void AD_init(void)
{
InitSysCtrl();
InitAdc();
AdcRegs.ADCTRL1.bit.ACQ_PS=0;//ADC的采样窗口时间,较低的采样频率和较大的采样窗口
AdcRegs.ADCTRL1.bit.CPS=0;//核时钟预定标器,等于0,未将时钟进行2分频
AdcRegs.ADCTRL1.bit.SEQ_CASC=1;
AdcRegs.ADCTRL3.bit.ADCCLKPS=10;//ADC内核时钟分频器
AdcRegs.ADCTRL3.bit.SMODE_SEL=0;
AdcRegs.ADCMAXCONV.bit.MAX_CONV1=1;
AdcRegs.ADCCHSELSEQ1.bit.CONV00=0;
// AdcRegs.ADCTRL2.all = 0x2000;//这一条是关键
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
/*************************************************
Function: main()
Description: 主函数
Calls: AD_init()
Called By: NULL
Table Accessed:
Table Updated:
Input:
Output:
Return:
Others:
*************************************************/
void main(void)
{
float adc;
int a,b;
AD_init();
init();
while(1)
{
adc=((float)AdcRegs.ADCRESULT0)*3.0/65520.0;
a=((int)adc);
b=((int)(adc*10))%10;
displaynum(0xef,~table[a]);
delay(10);
displaynum(0xdf,~table[b]);
delay(10);
displaynum(0xbf,~table[a]);
delay(10);
displaynum(0x7f,~table[b]);
delay(10);
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
}