📄 example_da.c
字号:
//###########################################################################
//
// FILE: Example_DA.c
//
// TITLE: Example_DA TEST
//
// ASSUMPTIONS:
//
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
// Select the example to compile in. Only one example should be set as 1
// the rest should be set as 0.
#define LED_TIME 10000
void Delay_loop();
void Gpio_select();
void DA_example();
void LedRun();//led测试
Uchar EepromTest(Uchar data,Uint16 addr);
Uint16 Delay_count=100;
Uint16 GportVariable,Input[2],Output[2],HighSpeedIn,HighSpeedOut,DzValue[128];
Uchar i2c_value;
void main(void)
{
/*------------------------------------------------------------------
To use the F2812, F2811 or F2810 Flash API, the following steps
must be followed:
1. Modify Flash281x_API.config.h for your targets operating
conditions.
2. Include Flash281x_API_Library.h in the application.
3. Add the approparite Flash API library to the project.
The user's code is responsible for the following:
4. Initalize the PLL to the proper CPU operating frequency.
5. If required, copy the flash API functions into on-chip zero waitstate
RAM.
6. Initalize the Flash_CPUScaleFactor variable to SCALE_FACTOR
7. Optional: Run the Toggle test to confirm proper frequency configuration
of the API.
8. Optional: Unlock the CSM.
9. Call the API functions: Flash_Erase(), Flash_Program(), Flash_Verify()
The API functions will:
Disable the watchdog
Check the device revision (REVID). This API is for Revision C silicon
Perform the desired operation and return status
------------------------------------------------------------------*/
volatile Uint16 iVol;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize 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 DSP281x_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 DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
InitPieVectTable();
// Enable interrupts required for this example
XIntruptRegs.XINT1CR.bit.ENABLE=1; //enable xint1
XIntruptRegs.XINT1CR.bit.POLARITY=0;// on a falling edge
PieCtrlRegs.PIEIER1.bit.INTx4=1; // PIE Group 1, INT4
IER = 0x001; // Enable CPU INT1
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Step 5. User specific code:
EnableInterrupts();
Gpio_select();//GPIO选择
DA_example();//DA测试1
LedRun();//led测试
}
void Delay_loop()
{
Uint16 j,i,sum;
j=0;
sum=0;
for (i = 0; i < Delay_count; i++) {
for(j=0;j<1;j++)
sum=sum+1;
}
}
void DA_example(void)
{
Uint16 * p_address;
Uint16 ad_value,flag;
p_address=(Uint16 *)0x2000; //DAC 基地址
Delay_count=10;//f=30.30Hz
GpioDataRegs.GPFDAT.bit.GPIOF12=1; // LDAC=1
flag=0; //flag=0 then add falg=1 then substraction
ad_value=0x800;
while(1)
{
if(flag==0)
ad_value++;
else
ad_value--;
if(ad_value>=4095)
{
flag=1;
}
if(ad_value==0)
flag=0;
*p_address=ad_value; // 第一通道
*(p_address+1)=ad_value; //第二通道
*(p_address+2)=ad_value; //第三通道
*(p_address+3)=ad_value; //第四通道
;
;
;
GpioDataRegs.GPFDAT.bit.GPIOF12=0; // LDAC=0
;
;
;
GpioDataRegs.GPFDAT.bit.GPIOF12=1; // LDAC=1
Delay_loop();
}
}
void Gpio_select(void)
{
Uint16 var1;
Uint16 var2;
Uint16 var3;
var1= 0x0000; // sets GPIO Muxs as I/Os
var2= 0xFFFF; // sets GPIO DIR as outputs
var3= 0x0000; // sets the Input qualifier values
EALLOW;
GpioMuxRegs.GPAMUX.all=var1;
GpioMuxRegs.GPBMUX.all=var1;
GpioMuxRegs.GPDMUX.all=var1;
GpioMuxRegs.GPFMUX.all=var1;
GpioMuxRegs.GPEMUX.all=var1;
GpioMuxRegs.GPGMUX.all=var1;
GpioMuxRegs.GPADIR.all=var2; // GPIO PORTs as output
GpioMuxRegs.GPBDIR.all=var2; // GPIO DIR select GPIOs as output
GpioMuxRegs.GPDDIR.all=var2;
GpioMuxRegs.GPEDIR.all=var2;
GpioMuxRegs.GPFDIR.all=var2;
GpioMuxRegs.GPGDIR.all=var2;
GpioMuxRegs.GPAQUAL.all=var3; // Set GPIO input qualifier values
GpioMuxRegs.GPBQUAL.all=var3;
GpioMuxRegs.GPDQUAL.all=var3;
GpioMuxRegs.GPEQUAL.all=var3;
EDIS;
}
Uint32 LedOnTime,LedOffTime;
Uint16 LedFlag=0;
void LedRun(void)
{
for(;;)
{
if((LedOnTime>LED_TIME)){
LedOnTime=0;
LedFlag=0xff;
}
else if(LedFlag==0){
LedOnTime++;
LedOffTime=0;
}
if(LedOffTime>LED_TIME){
LedOffTime=0;
LedFlag=0;
}
else if(LedFlag==0xff){
LedOffTime++;
LedOnTime=0;
}
Delay_loop();
if(LedFlag==0)
GpioDataRegs.GPFDAT.bit.GPIOF12=0; // Select GPIOF12 Output for test
else if(LedFlag==0xff)
GpioDataRegs.GPFDAT.bit.GPIOF12=1; // Select GPIOF12 Output for test
}
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -