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

📄 system.h

📁 在arm上模拟数字示波器
💻 H
字号:
/*
;**************************************************************
;*				   北京达盛科技有限公司
;*                    研    发    部
;*
;*             	http://www.techshine.com
;*************************************************************/

#include "..\..\Startup44B0\inc\44blib.h"
#include "..\..\Startup44B0\inc\target.h"
#include "..\..\Startup44B0\inc\44b.h"

//以下是编译器用到的宏定义
#define uchar       unsigned char
#define uint16      unsigned int
#define ulong       unsigned long
#define true        1
#define false       0
#define UCHAR       unsigned char
#define UINT16      unsigned int
#define ULONG       unsigned long
#define TRUE        1
#define FALSE       0

//以下是系统用到的宏定义
//注意:CPU挂箱上CPLD模块下方的跳线(拨码)开关只有
//右边第二个(CS2)在"ON"位置,其它都在"OFF"位置
#define CS0         0x0ac00800
#define CS1         0x0ac00600
#define CS2         0x0ac00400
#define CS3         0x0ac00200


//一下使应用程序可能用到的函数定义
void delay(unsigned int time)
  {
   unsigned int i;
   for(i=0;i<time;i++);
  }
  
//键盘与显示公共函数

/***********************
所用函数圆形声明
************************/
void __irq Key_ISR(void);
unsigned char read7279(unsigned char comand);

//--------------- HD7279A 指令 -----------------------------
	#define CMD_RESET    0xa4     //复位
	#define CMD_TEST     0xbf     //测试
	#define RTL_UNCYL    0xa1     //左移
	#define RTR_UNCYL    0xa0     //右移
	#define RTL_CYCLE    0xa3     //循环左移
	#define RTR_CYCLE    0xa2     //循环右移
	#define DECODE0      0x80     //下载数据按方式0译码 
	#define DECODE1      0xc8     //下载数据按方式1译码
	#define UNDECODE     0x90     //下载数据但不译码
	#define BLINKCTL     0x88     //闪烁控制
	#define ACTCTL       0x98     //消隐控制
	#define SEGON        0xe0     //段点亮
	#define SEGOFF       0xc0     //段关闭
	#define CMD_READ     0x15     //读键盘数据   

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

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

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

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

/******************************** 7279时钟模拟信号 ***************************************/

	#define clrcs1     	(*(volatile unsigned char *)0xA000006) = 0x00
	#define setcs1      temp = (*(volatile unsigned char*)0xA000006)

	#define clrclk     	temp = (*(volatile unsigned char*)0x0A000007)
	#define setclk     	(*(volatile unsigned char*)0x0A000007) = 0x00

	#define setdat     	(*(volatile unsigned char*)0x0A000008) = 0x00
	#define clrdat     	temp = (*(volatile unsigned char*)0x0A000008)
	
	#define  outfrom_7279   	temp = (*(volatile unsigned char*)0x0A000005)
	#define  input_7279   	(*(volatile unsigned char*)0x0A000005) = 0x00
	
	#define  HD7279_DAT   	(*(volatile unsigned char*)0x0A000009)&0x01

unsigned char key_number=0xff;
/*
*************************************************************************************************************
- 函数名称 : void KeyINT_Init(void)
- 函数说明 : 键盘中断的初始化
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void KeyINT_Init(void)													             
{
     if ((rINTPND & BIT_EINT2))
    {
    	rI_ISPC = BIT_EINT2;
    }
    rINTMSK  = ~(BIT_GLOBAL|BIT_EINT2);								//使用外部中断4
    pISR_EINT2 = (int)Key_ISR;
    
}

/*
*************************************************************************************************************
- 函数名称 : void Key_ISR(void)
- 函数说明 : 键盘中断的服务子程序
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void __irq Key_ISR( void )
{ 
		char i;

    	for(i=0;i<100;i++);
  		key_number = read7279(CMD_READ);
  		rI_ISPC = BIT_EINT2;
}

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

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


//--------------------------------------------------------------------
// 函数名称 : void RST7279(void)             
// 函数说明 : 接收一个字节 8BIT,高位在前 
// 输入参数 : 接收到的数据在全局变量rece_buff中
// 输出参数 : 无
//-------------------------------------------------------------------- 
void RST7279(void) 
 {
    send_byte(CMD_RESET);     //复位指令
    delay(2500);        //25ms延迟 --复位延迟
 }

//--------------------------------------------------------------------
// 函数名称 : void TEST7279(void)             
// 函数说明 : 测试7279的LED显示功能 
// 输入参数 : 无
// 输出参数 : 无
//-------------------------------------------------------------------- 
void TEST7279(void)
 {
   RST7279();
   send_byte(CMD_TEST);    //测试指令
   delay(100000);           //延时100ms
   delay(100000);
   delay(100000);
   delay(100000);
   delay(100000);
   delay(100000);
   RST7279();
 } 

//--------------------------------------------------------------------
// 函数名称 : void DISP7279(void)             
// 函数说明 : 测试7279的LED显示功能 
// 输入参数 : 无
// 输出参数 : 无
//-------------------------------------------------------------------- 
void DISP7279(uchar shiftmode,uchar decodemode,uchar dispdata)
   { 
     send_byte(shiftmode);  //数据左移指令
     send_byte(decodemode);
     if(dispdata !=0xff)
       {
        dispdata = dispdata & 0xf;
        send_byte(dispdata);
       }
     delay(60000);//延时60ms
     delay(60000);
     delay(60000);
    }

⌨️ 快捷键说明

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