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

📄 zero.h

📁 用凌阳16位单片机测试输入波形的频率
💻 H
字号:
#ifndef	__ZERO_h__
#define	__ZERO_h__
#define P_Watchdog_Clear 	(volatile unsigned int *)0x7012
#define	P_IOA_Data 				(volatile unsigned int *)0x7000   
#define P_IOA_Buffer 			(volatile unsigned int *)0x7001
#define P_IOA_Dir 				(volatile unsigned int *)0x7002
#define P_IOA_Attrib 			(volatile unsigned int *)0x7003
#define P_IOA_Latch 			(volatile unsigned int *)0x7004
#define P_IOB_Data				(volatile unsigned int *)0x7005  
#define P_IOB_Buffer			(volatile unsigned int *)0x7006   
#define P_IOB_Dir				(volatile unsigned int *)0x7007   
#define P_IOB_Attrib			(volatile unsigned int *)0x7008
#define P_SIO_Data				(volatile unsigned int *)0x701A
#define P_SIO_Addr_Low			(volatile unsigned int *)0x701B
#define P_SIO_Addr_Mid			(volatile unsigned int *)0x701C
#define P_SIO_Addr_High			(volatile unsigned int *)0x701D
#define P_SIO_Ctrl				(volatile unsigned int *)0x701E
#define P_SIO_Start				(volatile unsigned int *)0x701F
#define P_SIO_Stop				(volatile unsigned int *)0x7020 
#define P_ADC					(volatile unsigned int *)0x7014   
#define P_ADC_Ctrl				(volatile unsigned int *)0x7015   
#define P_ADC_MUX_Ctrl			(volatile unsigned int *)0x702B   
#define P_ADC_MUX_Data		(volatile unsigned int *)0x702C   
#define P_DAC2					(volatile unsigned int *)0x7016   
#define P_DAC1					(volatile unsigned int *)0x7017   
#define P_DAC_Ctrl				(volatile unsigned int *)0x702A 
unsigned int i;
unsigned int uiValue,ko;
void Delay()
{									//延时子程序
	 int i;
	for(i=0; i<60; i++){
		*P_Watchdog_Clear=0x0001;	//清WatchDog
	}	
}
void Delay1()
{									//延时子程序
	unsigned int i;
	for(i=0; i<15000; i++){
		*P_Watchdog_Clear=0x0001;	//清WatchDog
	}	
}
void Delay2()
{									//延时子程序
	unsigned int i;
	for(i=0; i<32768; i++){
		*P_Watchdog_Clear=0x0001;	//清WatchDog
	}	
	
	
}

unsigned int key1()   //行扫描 
{unsigned int k1;
*P_IOB_Dir=0xf0ff;
*P_IOB_Attrib=0xf0ff;
*P_IOB_Data=0x0f00;
k1=*P_IOB_Data;

return k1;
}
unsigned int key3()//列扫描,该扫描函数不同于其他单片机书籍常说的扫描法,跟反转法有点象
{
unsigned int k3;
*P_IOB_Dir=0x00ff;
*P_IOB_Attrib=0x00ff;
*P_IOB_Data=0x0000;
k3=*P_IOB_Data;
return k3;
}
unsigned int  KeyFind()//获取键值的函数,返回键值
{
unsigned int w1,w2;
unsigned int KEY;
w1=key1();
w2=key3();
w1=w1&0x0f00;//获取行特征数据
w2=w2&0xf000;//获取列特征数据
KEY=w1|w2;//将行数据和列数据糅合

switch(KEY)        //判断数值                 //把对应的值赋给uiValue
	{
		case 0x0f00:
		  break;
		case 0x8e00:
		  uiValue=0x0000;
		  break;
		case 0x4e00:
		  uiValue=0x0001;
		  break;
		case 0x2e00:
		  uiValue=0x0002;
		 break;
		case 0x1e00:
		  uiValue=0x0003;
		  break;
		case 0x8d00:
		  uiValue=0x0004;
		  break;
		case 0x4d00:
		  uiValue=0x0005;
		  break;
		case 0x2d00:
		  uiValue=0x0006;
		 break;
		case 0x1d00:
		  uiValue=0x0007;
		  break;
	    case 0x8b00:
	    uiValue=0x0008; 
	    break;
	    case 0x4b00:
	      uiValue=0x0009;
	      break;
	    case 0x2b00:
	      uiValue=0x000a;
	      break;
	    case 0x1b00:
	      uiValue=0x000b;
	      break;
	    case 0x8700:
	      uiValue=0x000c;
	      break;
	    case 0x4700:
	      uiValue=0x000d;
	      break;
	    case 0x2700:
	      uiValue=0x000e;
	     break;
	    case 0x1700:
	      uiValue=0x000f;
	     break;
	     	    
	    
}
	if(uiValue==255)  ko=ko;
    else   ko=uiValue;
    return ko;
}

void SIO_OUT(unsigned int DATA)
{
unsigned int i;
*P_SIO_Start=1;           		// 启动写模式
	*P_SIO_Data=DATA;            		// A7~A0 = 0
	// 等待SIO空闲
    i=*P_SIO_Start;
	i&=0x0080;
	while(i)
	{
	    i=*P_SIO_Start;
		i&=0x0080;
		*P_Watchdog_Clear=0x0001;
	}
 	*P_SIO_Stop=1;     				
 
}
void chushi()//液晶显示初始化
{

	*P_IOB_Dir = 0x00FF;
	*P_IOB_Attrib = 0x00FF;
    *P_IOB_Data=0x0000;	
	// 对SPR4096进行Mass Erase
	*P_SIO_Ctrl=0x00d1;  // clk=	CPUclk/8, 8位地址
		
    *P_SIO_Start=1;           		// 启动写模式
	*P_SIO_Data=0;            		// A7~A0 = 0
	// 等待SIO空闲
    i=*P_SIO_Start;
	i&=0x0080;
	while(i)
	{
	    i=*P_SIO_Start;
		i&=0x0080;
	}
 	*P_SIO_Stop=1;     				
 	i=0x7ff;						// 延时
	while(i--);
*P_IOB_Buffer=0x0040;
SIO_OUT(0x0001);//清屏
*P_IOB_Buffer=0x0000;
Delay1();//1.53ms
*P_IOB_Buffer=0x0040;

SIO_OUT(0x0038);//功能设置 ;
*P_IOB_Buffer=0x0000;
Delay();
*P_IOB_Buffer=0x0040;

SIO_OUT(0x000c);//开显示
*P_IOB_Buffer=0x0000;
Delay();//39us
*P_IOB_Buffer=0x0040;

SIO_OUT(0x0006);//输入模式设置
*P_IOB_Buffer=0x0000;
Delay();//39us
*P_IOB_Buffer=0x0040;

}
void xianshi(unsigned int s1)//显示函数
{
  SIO_OUT(s1);
*P_IOB_Buffer=0x0010;
  Delay();//39us
 *P_IOB_Buffer=0x0040;
}
void qp()//清屏函数
{
*P_IOB_Buffer=0x0040;
SIO_OUT(0x0001);//清屏
*P_IOB_Buffer=0x0000;
Delay1();//1.53ms
*P_IOB_Buffer=0x0040;
}
void Address1()//地址设置函数
{
SIO_OUT(0x0080);//显示位置
*P_IOB_Buffer=0x0000;
Delay();//39us
*P_IOB_Buffer=0x0040;

}
void Address2()//地址设置函数
{
SIO_OUT(0x00c0);//显示位置
*P_IOB_Buffer=0x0000;
Delay();//39us
*P_IOB_Buffer=0x0040;

}
void Set_Address(unsigned int offset)//地址设置函数
{
SIO_OUT(0x0080+offset);//显示位置
*P_IOB_Buffer=0x0000;
Delay();//39us
*P_IOB_Buffer=0x0040;

}

/*参考:
	*P_ADC_MUX_Ctrl=0x0002;				//LINE_IN-------IOA0
	*P_ADC_Ctrl= 0x0039;					//ADC enable 
	uiData=*P_ADC_MUX_Data;				//ADC start
         *P_DAC_Ctrl=0x0000;                            //DAC latch direct1
*/

#endif

⌨️ 快捷键说明

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