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

📄 arm7279.c

📁 达盛EL-ARM-830
💻 C
字号:
/*
;************************************************************************************************************
;*				        				北京精仪达盛科技有限公司
;*                                     	     研    发    部
;*
;*                                 	     http://www.techshine.com
;*
;*--------------------------------------------- 文件信息 ----------------------------------------------------                                      
;*
;* 文件名称 : ARM7279.c	
;* 文件功能 : 该文件为S3C44B0硬件平台的键盘程序。
;* 补充说明 : 
;*-------------------------------------------- 最新版本信息 -------------------------------------------------
;* 修改作者 : ARM开发小组
;* 修改日期 : 2004/04/25
;* 版本声明 : V1.0.1
;*-------------------------------------------- 历史版本信息 -------------------------------------------------
;* 文件作者 : ARM开发小组
;* 创建日期 : 2004/04/20
;* 版本声明 : v1.0.0
;*-----------------------------------------------------------------------------------------------------------
;*-----------------------------------------------------------------------------------------------------------
;************************************************************************************************************
;*/
#include "keydriver.h"
unsigned char temp;

/******************************** HD7279A的使用原理说明 ***************************************/
/*
--HD7279A的数据是通过CPLD作为与S3C44BO通讯的接口,CPU通过在相应地址上的读写CPLD,即可与HD7279
  进行有效的通讯。由于CPLD是通过CPU的NGCS4选择的,所以向CPLD读写均需要使用NGCS4。下面为具体的
  使用方法。
  
--向地址 0x18000205 里写任意数,表示HD7279A的数据给D0
--从地址 0x18000205 中读任意数,表示数据给HD7279A
--上电复位时,默认为数据给HD7279A
 
--向地址 0x18000206 里写任意数,表示选中HD7279,即CS7279='0'
--从地址 0x18000206 中读任意数,表示禁止HD7279,即CS7279='1'
--上电复位时,默认为禁止HD7279,即CS7279='1'

--向地址 0x18000207 里写任意数,表示时钟电平为高,即CLK7279='1'
--从地址 0x18000207 中读任意数,表示时钟电平为低,即CLK7279='0'
--上电复位时,默认为时钟电平为低,即CLK7279='0'

--向地址 0x18000208 里写任意数,表示数据电平为高,即D7279='1'
--从地址 0x18000208 中读任意数,表示数据电平为低,即D7279='0'
--上电复位时,默认为数据电平为高,即D7279='1'

--当HD7279A输入数据到CPLD上时,CPU通过读取地址0x18000209,就可以把HD7279发送的数据得到。
*/

/******************************** 7279时钟模拟信号 ***************************************/
#define CPLD_BASE	0x18000000
#define clrcs1  	(*(volatile unsigned char *)(CPLD_BASE + 0x6)) = 0x00
#define setcs1    temp = *((volatile unsigned char *)(CPLD_BASE + 0x6))

#define s_clr  	*((volatile unsigned char *)(CPLD_BASE + 0x4)) = 0x05
#define s_set     *((volatile unsigned char *)(CPLD_BASE + 0x4)) = 0x06

#define outfrom_7279    temp = *((volatile unsigned char *)(CPLD_BASE + 0x5))
#define input_7279  *((volatile unsigned char *)(CPLD_BASE + 0x5)) = 0x00
        
#define clrclk    temp = *((volatile unsigned char *)(CPLD_BASE + 0x7))
#define setclk  	*((volatile unsigned char *)(CPLD_BASE + 0x7)) = 0x00
 
#define setdat    *((volatile unsigned char *)(CPLD_BASE + 0x8)) = 0x00
#define clrdat    temp = *((volatile unsigned char *)(CPLD_BASE + 0x8))

#define HD7279_DAT   ((*(volatile unsigned char *)(CPLD_BASE + 0x9)) & 0x1)

unsigned char key_number=0xff;
/*
*************************************************************************************************************
- 函数名称 : void KeyINT_Init(void)
- 函数说明 : 键盘中断的初始化
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void KeyINT_Init(void)
{
    ClearPending(BIT_EINT0);
    rINTMSK  = ~(BIT_EINT0);								//使用外部中断0
    pISR_EINT0 = (int)Key_ISR;
}

/*
*************************************************************************************************************
- 函数名称 : void Key_ISR(void)
- 函数说明 : 键盘中断的服务子程序
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void __irq Key_ISR( void )
{ 
	char i;
	rINTMSK  |= (BIT_EINT0);
    for(i=0;i<100;i++);
  	key_number = read7279(cmd_read);
  	ClearPending(BIT_EINT0);
  	rINTMSK  = ~(BIT_EINT0);
}

/*
*************************************************************************************************************
- 函数名称 : void long_delay(void)
- 函数说明 : 长延时程序
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void long_delay(void)
{ 
	unsigned int i;
   	for (i=0;i<250;i++)
   	{
	}
	
}

/*
*************************************************************************************************************
- 函数名称 : void short_delay(void)
- 函数说明 : 短延时程序
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void short_delay(void)
{ 
	int i;
  	for(i=0;i<150;i++)
  	{
  	}

}

/*
*************************************************************************************************************
- 函数名称 : void send_byte(unsigned char out_byte )
- 函数说明 : 向7279发送一个字节的程序
- 输入参数 : out_byte
- 输出参数 : 无
*************************************************************************************************************
*/
void send_byte(unsigned char out_byte )
{
	unsigned short  i;
	
	clrcs1;
  	long_delay();
  	
  	for (i=0;i<8;i++)
  	{   
  		if (0x80 == (out_byte & 0x80))  
      	{ 
      		setdat;
      	}
      	else
      	{
      		clrdat;
      	}
      	
      	setclk;
      	short_delay();
      	clrclk;
      	short_delay();
      	
      	out_byte <<= 1;
  	}
  	short_delay();
  	clrdat;
  
 }
 
/*
*************************************************************************************************************
- 函数名称 : unsigned char receive_byte (void)
- 函数说明 : 向7279接收一个字节的程序
- 输入参数 : 无
- 输出参数 : in_byte
*************************************************************************************************************
*/
unsigned char receive_byte (void)    
{
   	unsigned char i,in_byte;
   	
   	input_7279;
   	long_delay();

    for(i=0;i<8;i++)
    {
    	setclk;
     	short_delay();
    	in_byte <<= 1;

    	if (HD7279_DAT)
    	{ 
    		in_byte |= 1;
    	}
    	
   	 	clrclk;
    	short_delay();
    }
    
    clrdat;
    outfrom_7279;
    short_delay();
    return(in_byte);
}
 
/*
*************************************************************************************************************
- 函数名称 : unsigned char read7279(unsigned char comand)
- 函数说明 : 读键盘指令程序
- 输入参数 : 无
- 输出参数 : in_byte
*************************************************************************************************************
*/    
unsigned char read7279(unsigned char comand)
{
  	send_byte(comand);
   	return (receive_byte());
}

/*
*************************************************************************************************************
- 函数名称 : void write7279 (unsigned char cmd, unsigned char dat)
- 函数说明 : 写键盘指令程序
- 输入参数 : 无
- 输出参数 : in_byte
*************************************************************************************************************
*/   
void write7279 (unsigned char cmd, unsigned char dat)
{
	send_byte(cmd);
 	send_byte(dat);
}

/*
*************************************************************************************************************
*-													结束文件                                               -*
*************************************************************************************************************
*/
    



⌨️ 快捷键说明

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