#include <reg51.h>
/*--------------------------------------------
调用方式:自行I/O 口定义﹫2001/05/12
函数说明:私有函数,各接口定义
--------------------------------------------*/
sbit HD7279_CS=P1^4; // HD7279_CS--P1.4
sbit HD7279_CLK=P1^5; // HD7279_CLK-- P1.5
sbit HD7279_DATA=P1^6; // HD7279_DATA-- P1.2
sbit HD7279_KEY =P1^7; // HD7279_KEY-- P1.3
/*--------------------------------------------
调用方式: HD7279A 各指令定义﹫2001/05/12
函数说明:私有函数,接口定义
--------------------------------------------*
/#define HD7279_RESET 0xa4 //复位
#define HD7279_TEST 0xbf //测试
#define HD7279_RLC 0xa3 //循环左移
#define HD7279_RRC 0xa2 //循环右移
#define HD7279_RL 0xa1 //左移
#define HD7279_RR 0xa0 //右移
#define HD7279_DECODE0 0x80 //译码方式0
#define HD7279_DECODE1 0xc8 //译码方式1
#define HD7279_UNDECODE 0x90 //译码方式2: 不译码
#define HD7279_HIDE 0x98 //消隐
#define HD7279_FLASH 0x88 //闪烁
#define HD7279_SEGON 0xe0 //段亮
#define HD7279_SEGOFF 0xc0 //段灭
#define HD7279_READ 0x15 //读
/*--------------------------------------------
调用方式: void HD7279_LongDelay(void) 等侍函数﹫2001/05/12
函数说明 私有函数,>500ms
--------------------------------------------*/
void HD7279_LongDelay(void)
{
unsigned char i;
for (i=0;i<6;i++);
}
/*--------------------------------------------
调用方式:void HD7279_ShortDelay(void) 等侍函数﹫2001/05/12
函数说明:私有函数,=500ms
--------------------------------------------*
/void HD7279_ShortDelay(void)
{;}
/*--------------------------------------------
调用方式:void Delay10ms(unsigned char time) 等侍函数﹫2001/05/12
函数说明:私有函数, 6M晶振
--------------------------------------------*/
void Delay10ms(unsigned char time)
{
unsigned char i;
unsigned int j;
for(i=0;i<time;i++)
{
for(j=0;j<931;j++)
{;}
}
}
/*--------------------------------------------
调用方式:void HD7279_ShortDelay(void) 函数﹫2001/05/12
函数说明:私有函数,送指令
--------------------------------------------*/
void HD7279_SendByte( unsigned char out_byte)
{
unsigned char i;
HD7279_CS=0;
HD7279_LongDelay();
for(i=0;i<8;i++)
{
if(out_byte&0x80) { HD7279_DATA=1; }
else { HD7279_DATA=0; }
HD7279_CLK=1;
HD7279_ShortDelay();
HD7279_CLK=0;
HD7279_ShortDelay();
out_byte=out_byte<<1;
}
HD7279_DATA=0;
}
/*--------------------------------------------
调用方式:void Write7279(unsigned char command, unsigned char dta) 函数﹫2001/05/12
函数说明:私有函数,写函数
--------------------------------------------*/
void Write7279(unsigned char command, unsigned char dta)
{
HD7279_SendByte( command );
HD7279_SendByte( dta );
}
/*--------------------------------------------
调用方式:自定义函数﹫2001/05/12
函数说明:私有函数,自行定义
--------------------------------------------*/
#define RunKey 0xXX
#define StopKey 0xXX
/*--------------------------------------------
调用方式:unsigned char HD7279_ReceiveByte(void)函数﹫2001/05/12
函数说明:私有函数,接受一个BYTE函数
--------------------------------------------*/
unsigned char HD7279_ReceiveByte(void)
{
unsigned char i, in_byte;
HD7279_DATA=1;
HD7279_LongDelay();
for(i=0;i<8;i++)
{HD7279_CLK=1;
HD7279_ShortDelay();
in_byte=in_byte<<1;
if(HD7279_DATA) { in_byte=in_byte|0x01; }
HD7279_CLK=0;
HD7279_ShortDelay();
}
HD7279_DATA=0;
return (in_byte);
}
/*--------------------------------------------
调用方式:unsigned char HD7279_GetKey()函数﹫2001/05/12
函数说明:私有函数,读键盘函数
--------------------------------------------*/
unsigned char HD7279_GetKey()
{
unsigned char key;
if(!HD7279_KEY)
{
HD7279_SendByte(HD7279_READ);
key=HD7279_ReceiveByte();
switch( key )
{case RunKey:
case StopKey:
while(!HD7279_KEY);
default: return(0xff);
}
}
return(0xff);
}
/*--------------------------------------------
调用方式:main()函数﹫2001/05/12
函数说明:私有函数,例函数
--------------------------------------------*
/main()
{HD7279_SendByte(0xa4);//复位
Write7279(0x80,0)//显示‘0’
}</P><P>