⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad.c

📁 FLASH存储 AD采样 操作FLASH 读取数据
💻 C
字号:
//
//      TMDX ALPHA RELEASE
//      Intended for product evaluation purposes
//
//###########################################################################
//
// FILE:	Example_28xGpio.c
//
// TITLE:	DSP28 Device GPIO test porgram. 
//		All the GPIO PORT pins IOs will toggle forever in an indefinite
//		loop
//
//###########################################################################
//
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  0.56| 06 May 2002 | S.S. | EzDSP Alpha Release
//  0.57| 27 May 2002 | L.H. | No change
//###########################################################################



#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
#include "Flash2812_API_Library.h"
#include "extern_ram.h"


unsigned int Buffer[1];

unsigned int Bu[1];
unsigned int status;
unsigned int *Flash_ptr;
unsigned int Length;
FLASH_ST	ProgStatus;
extern unsigned long Flash_CPUScaleFactor;
FLASH_ST	EraseStatus;
FLASH_ST 	VerifyStatus;
 
 float	a1[2];
 unsigned long address=0;
 float	adclo=0.0;

 int i=0;
// Prototype statements for functions found within this file.
 interrupt void ad(void);

void main(void)
{
	/* 初始化系统控制 */
	InitSysCtrl();

	// Disable and clear all CPU interrupts:
	DINT;
	IER = 0x0000;
	IFR = 0x0000;
	
	/* 初始化PIE控制寄存器 */	
	InitPieCtrl();

	/* 初始化中断矢量表 */
	InitPieVectTable();	
	
	/*初始化外设*/
    //InitPeripherals();
	 InitGpio();
	 
	 //Enable access to emulation space and other protected registers.
	EALLOW;	// This is needed to write to EALLOW protected registers
	PieVectTable.ADCINT=&ad;
	EDIS;   // This is needed to disable write to EALLOW protected registers
    
    /* 打开PASSWORD */
	Unlock();

   Flash_CPUScaleFactor = SCALE_FACTOR;//if delect this then *檫除 * will fail//	
	/* 檫除 */
   status = Flash_Erase(SECTORE,&EraseStatus);
	if(status != STATUS_SUCCESS)
	{
		while(1);
	}
	// Enable INT14 which is connected to CPU-Timer 2
    IER |= M_INT1;//////???????????
    InitAdc();
    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();
	}*/
	//for(;;);
 if(address<=0x200)
	{
    for(;;);
    }
    else
    {
    DINT;
	IER = 0x0000;
	IFR = 0x0000;
	for(;;);
    }
	
} 	


interrupt void ad(void)
{
	IFR=0x0000;
//	PieCtrl.PIEIFR1.all = 0;
	PieCtrl.PIEACK.all=0xffff;
	
	address++;
	
	/* 烧写FLASH */
   Buffer[0] = AdcRegs.RESULT0;
	
	
	Flash_ptr = (unsigned int *)(0x3d8000+address);
	Length = 1;	
	 LED1_ON;
	status = Flash_Program(Flash_ptr,Buffer,Length,&ProgStatus);

	if(status != STATUS_SUCCESS)
	        {
		     while(1);
	        }
    
      LED1_OFF;
	
	/* 校验 */
	status = Flash_Verify(Flash_ptr,Buffer,Length,&VerifyStatus);
	
	if(status != STATUS_SUCCESS)
	{
		while(1);
	}

   	Bu[0] =*Flash_ptr ;


	a1[0]=((float)AdcRegs.RESULT0)*3.0/65520.0+adclo;
	
    AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
	AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
	EINT;
	
}
	
 

 
 

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -