📄 ad.c
字号:
// A/D 转换实验
#include <stdio.h>
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
unsigned int a2=0;
float a1,adclo=0.0;
unsigned int n1,n2;
unsigned int Discode[16]={0x3F,0x06,0x5B,0x4F,
0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,
0x39,0x3E,0x79,0x71
};// 0-9及A-F的显示代码
// Prototype statements for functions found within this file.
interrupt void ad(void);
void Gpio_select(void);
void Display(void);
void delay_loop(void);
void main(void)
{
InitSysCtrl();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
Gpio_select();
GpioDataRegs.GPADAT.all=0x00FF;
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.ADCINT=&ad;
EDIS; // This is needed to disable write to EALLOW protected registers
InitAdc();
// Enable INT14 which is connected to CPU-Timer 2:
IER |= M_INT1;
//KickDog();
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
while(AdcRegs.ADC_ST_FLAG.bit.SEQ1_BSY==0)
{
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
for(;;)
{
KickDog();
}
}
interrupt void ad(void)
{
IFR=0x0000;
// PieCtrl.PIEIFR1.all = 0;
PieCtrl.PIEACK.all=0xffff;
a2++;
a1=((float)AdcRegs.RESULT0)*3.0/65520.0+adclo;
n1=(int)(a1/0.03)%10;
n2=(int)(a1/0.3);
if(n2==10) n2=9;
if(n2==9 && (a1/0.03)==100) n1=9;
Display();
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
EINT;
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.all=0x0000;
GpioMuxRegs.GPDMUX.all=0x0000;
GpioMuxRegs.GPADIR.all=0xC7FF; // GPIO PORTs as output
GpioMuxRegs.GPDDIR.all=0xC7FF;
GpioMuxRegs.GPAQUAL.all=0x0000; // Set GPIO input qualifier values
GpioMuxRegs.GPDQUAL.all=0x0000;
EDIS;
}
void Display()
{
GpioDataRegs.GPADAT.all =Discode[n2];
GpioDataRegs.GPDDAT.bit.GPIOD1=1;
delay_loop();
GpioDataRegs.GPDDAT.bit.GPIOD1=0;
GpioDataRegs.GPADAT.all =Discode[n1];
GpioDataRegs.GPDDAT.bit.GPIOD0=1;
delay_loop();
GpioDataRegs.GPDDAT.bit.GPIOD0=0;
}
void delay_loop()
{
short k;
for(k=0;k<1000;k++) {}
}
//===========================================================================
// End Of The Program.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -