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

📄 io.c

📁 在KEILC下进行编译的程序,单片机可以进行AD,DA数据采集
💻 C
字号:
#include "fx2.h"
#include "fx2regs.h"
#include "io.h"

//#define OTimer_Macro_1msTH    0xD1    /*CLKOUT(48M)/4,24M晶振,1ms定时器中断定时值*/
//#define OTimer_Macro_1msTL    0x20    /*1ms定时器中断定时值*/
#define OTimer_Macro_1msTH    0xF8    /*CLKOUT(48M)/4,24M晶振,1ms定时器中断定时值*/
//#define OTimer_Macro_1msTH    0x88
#define OTimer_Macro_1msTL    0x30    /*1ms定时器中断定时值*/

//#define OTimer_Macro_1msTH    0xFC    /*CLKOUT(12M)/4,24M晶振,1ms定时器中断定时值*/
//#define OTimer_Macro_1msTL    0x18    /*2ms定时器中断定时值*/

//#define OTimer_Macro_1msTH    0xFE    /*CLKOUT(12M)/4,24M晶振,1ms定时器中断定时值*/
//#define OTimer_Macro_1msTL    0x0C    /*1ms定时器中断定时值*/
char   AD_X;

//char   AD0809;
 int tttttt=0;
void IO_Init()
{
	PORTECFG &= ~WORK_LED;  
//端口E的PE3取反
	PORTECFG &= ~CPLD_RST; 
	/////////////////////////////
//	PORTECFG &= ~LED_TS0 ; 
//	PORTECFG &= ~LED_TS1 ; 
//端口E的PE4取反

	OEE |= WORK_LED;  
	OEE |= CPLD_RST;  

	////////////////
 	 OEE |= LED_TS0;  
	 OEE |= LED_TS1; 
	 OEE |= LED_TS2; 

//端口输出使能
/////////////////////////////
	IOE &= ~CPLD_RST;         //CPLD reset
	IOE |= CPLD_RST;
	IOE &= ~WORK_LED;         //Word Led Light

//	IOE |= WORK_LED;
//	IOE &= ~WORK_LED;  

////////////////////
	IOE &= ~LED_TS0; 
	IOE &= ~LED_TS1; 
    IOE &= ~LED_TS2;
////////////////////
//需要初始化A和C的端口
	PORTACFG=0x00;
	OEA=0xFF;
	IOA|=0x06;//PA2=1;ADPA1=1	
	PORTCCFG=0x00;
	OEC=0x00;
///////////////////////////// add by myself
}

void REG_Init()
{
	CPUCS = 0x10; //48Mhz
	CKCON = (CKCON&(~bmSTRETCH)) | 1; // Set stretch to 0 (after renumeration)	
}

void Sys_Timer0_Init ()   
{
    ET0 = 0; /* Forbid T0 INT */
    TMOD = (TMOD & 0xF0) | 0x01; /*方式1*/
//	CKCON |= 0x08;  //T0M = CLKOUT/4
	CKCON &= 0xF7;  //T0M = CLKOUT/12
    TF0 = 0; /* Reset */
    TH0 = OTimer_Macro_1msTH;       
    TL0 = OTimer_Macro_1msTL;   
    EA = 1 ; /* CPU Open INT */
    ET0 = 1; /* Permit T0 INT */
    PT0 = 0; /* Lower Priority */
    TR0 = 1; /* Start T0 */
    return ;
}



/*
void Sys_Timer1_Init ()    
{
 	TH2  = T1_VALUE ;           // 设置定时器1的初值       
  	TL2  = T1_VALUE; 
	T2CON= 0x04;
    return ;
	}
*/
/*

void  Timer0_Interrupt() interrupt 2//中断1

{
	TH0 = 0x01;       //0xD1 
    TL0 = 0x20;       //0x20
// 定时器1的定时时间是1到2US之间	
	PA7=~PA7;

}
*/
/*
void  Timer1_Interrupt() interrupt 3//中断1



{

	TH0 = 0x33;       //0xD1 
    TL0 = 0x20;       //0x20
	
	PA2=~PA2;

}


*/
/*    
	定时器2的定时时间是1MS左右
   PA2=1;
  
   PA2=0;
   //delay(100);
   PA2=1;//意思是让PA2定时产生一个低电平,经过反向后就是一个AD的启动正脉冲了。
*/




//////////////////////--------------------------------------------------------------
 



/*********************************************
	串口0中断服务程序
*********************************************/

//是不是中断的速度太快了呢?????
//为什么每一个程序中断的都不一样呢?

/*
void Time1_Interrupt() interrupt 3 
{
//TF1 =0;
//	TH1  = 0x00 ; // 设置定时器1的初值       
//	TL1  = 0x10; 
tttttt=tttttt+1;
if(tttttt==20000)
 {
	tttttt=0;
//	PA6=~PA6;
//	PA5=~PA5;
	if(tttttt%2==0)
	{IOA=0x00;}
	if(tttttt%2==1)
	{IOA=0xFF;}
 }

}      
*/

void  Timer0_Interrupt() interrupt 1
{

	TH0 = OTimer_Macro_1msTH;
	TL0 = OTimer_Macro_1msTL;
	PA7=~PA7;
	PA2=0;
	PA2=0;
	PA2=0;
	PA2=0;
	PA2=0;
	PA2=0;

	PA2=1;
//	PA2=~PA2;
	tttttt++;
	if(tttttt>=100)
		{	
		tttttt=0;
		PA5=~PA5;	
		}
}



void ad0809()
{	
//int i;
//while(PA0==0)
//{i++;}

if (PA0==1)
	{	PA1=0;
//		for (i=0; i < 4; i++) ;

		AD_X=IOC;
    	PA1=1;
	}
}

⌨️ 快捷键说明

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