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

📄 7279.c

📁 C51的12864m
💻 C
字号:
/* */ 
/* S A G E T E C H . P R O P R I E T A R Y */ 
/* */ 
/* COPYRIGHT (c) 2005 BY SAGE TECH. CHINA. */ 
/* -- ALL RIGHTS RESERVED -- */ 
/* */ 
/* File Name: HD7279Atest.c */ 
/* Author: sagestar */ 
/* Created: 2005 */ 
/* Modified: no */ 
/* Revision: V1.0 */ 
/************************************************************************************/ 
/*程序作用:测试Sage Tech.开发板(MCP300)中hd7279键盘显示芯片是否能正常工作 */ 
/*程序功能:按下1号键显示0、1、2、3,按下2号键显示c、d、e、f,按下3号键显示4、5、6、7 */ 
/* 按下4号键显示8、9、a、b,按下0号键点亮4个LED灯 */ 
/************************************************************************************/ 
#include "my_include.h"
/************************************************************************************/ 
typedef unsigned char BYTE; /*自定义字节类型*/ 
/************************************************************************************/ 
#define Set_Bit(BIT) (BIT = 1) /*定义置1函数*/ 
#define Clear_Bit(BIT) (BIT = 0) /*定义清0函数*/ 
/************************************************************************************/ 
void Led_On(BYTE); /*定义点亮LED灯函数*/ 
void Led_Off(BYTE); /*定义熄灭LED灯函数*/ 
void Write_Hd7279(BYTE,BYTE); /*定义HD7279写函数*/ 
BYTE Read_Hd7279(BYTE); /*定义HD7279读函数*/ 
void Send_Byte(BYTE); /*定义HD7279发送字节函数*/ 
BYTE Receive_Byte(void); /*定义HD7279接收字节函数*/ 
void Short_Delay(void); /*定义短延时函数*/ 
void Long_Delay(void); /*定义长延时函数*/ 
void Mcu_Init(void); /*定义MCU初始化函数*/ 
void Delay_200_mS(void); /*定义200ms延时函数*/ 
/************************************************************************************/ 
BYTE Keyboard_Out; /*定义键值变量*/ 
bit Keyboard_Flag; /*定义按键标志*/ 
/************************************************************************************/ 
#define Hd7279_Key P3_2
#define Hd7279_Clk P1_4
#define Hd7279_Data P1_5
/************************************************************************************/ 
unsigned int cumulate=0x00;
unsigned int cumulate1=0x00;

unsigned char disp=0x09;
void time(void) interrupt 3 using 2
{
cumulate++;
if(cumulate>0xefff)
{
cumulate=0x00;
cumulate1+=1;
}
if(cumulate1>0x8ca0)
{disp+=1;
cumulate=0x00;
cumulate1=0x00;
}
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
TL1=0xff;
TH1=0xff;

}
void main(void) /*主函数*/ 
{

Mcu_Init(); /*MCU初始化*/ 
mai();
while(1) 
{ 
Write_Hd7279(0xcf,disp); 
if(Keyboard_Flag) 
{ 
Clear_Bit(Keyboard_Flag); 
if(Keyboard_Out==0) /*0号键处理*/ 
{ 
Send_Byte(0xa3);
} 
else if(Keyboard_Out==1) /*1号键处理*/ 
{ /*显示0、1、2、3*/ 

Led_On(0x07); 

} 
else if(Keyboard_Out==2) /*2号键处理*/ 
{ /*显示c、d、e、f*/ 
Led_On(0x07); 
} 
else if(Keyboard_Out==3) /*3号键处理*/ 
{ /*显示4、5、6、7*/ 
Write_Hd7279(0xc9,0x07); 
Write_Hd7279(0xca,0x06); 
Write_Hd7279(0xcb,0x05); 
Write_Hd7279(0xcc,0x04); Led_Off(0x02); 
} 
else /*4号键处理*/ 
{ /*显示8、9、a、b*/ 
Write_Hd7279(0xc9,0x0b); 
Write_Hd7279(0xca,0x0a); 
Write_Hd7279(0xcb,0x09); 
Write_Hd7279(0xcc,0x08); Led_Off(0x02); 
} 
Delay_200_mS(); 
} 
} 
} 
/***********************************************************************************/ 
void Delay_200_mS(void) /*500ms延时函数*/ 
{ 
BYTE i,j; 
i=200; 
while (i--) 
{ 
j=228; 
while(j--); 
} 
} 
/************************************************************************************/ 
void Mcu_Init(void) /*MCU初始化函数*/ 
{ 
P1_3=0;
Delay_200_mS();

Set_Bit(EX0); /*外部中断0使能*/ 
Set_Bit(IT0); /*外部中断0下降沿触发*/ 
Set_Bit(EA); /*中断使能*/ 
TL1=0xff;
TH1=0xff;
IE1=1;
TR1=1;
ET1=1;
Send_Byte(0xa4); /*HD7279复位*/ 
Write_Hd7279(0x98,0x00); /*HD7279启动消隐功能,能提高灯的亮度*/ 
Write_Hd7279(0xc8,0x00);
Write_Hd7279(0xc9,0x02);
//Write_Hd7279(0xca,0x45); /*上电显示1、2、3、4、5、6、7、8*/ 
Write_Hd7279(0xcb,0x00); 
Write_Hd7279(0xcc,0x05); 
//Write_Hd7279(0xcd,0x26);  
Write_Hd7279(0xce,0x01); 
Write_Hd7279(0xcf,0x09); 
} 
/************************************************************************************/ 
void int1_Hd7279key(void) interrupt 0 /*外部中断0函数*/ 
{ 
Keyboard_Out=Read_Hd7279(0x15); /*读取键值*/ 
if(Keyboard_Out<=0x04) 
{ 
Set_Bit(Keyboard_Flag); /*设置键标志*/ 
} 
} 
/************************************************************************************/ 
void Short_Delay(void) /*短延时函数*/ 
{ 
BYTE i; 
for(i=0;i<0x08;i++); 
} 
/************************************************************************************/ 
void Long_Delay(void) /*长延时函数*/ 
{ 
BYTE i; 
for(i=0;i<0x30;i++); 
} 
/************************************************************************************/ 
void Led_On(BYTE Led_Num) /*点亮LED灯函数*/ 
{ 
Write_Hd7279(0xe0,Led_Num); 
} 
/************************************************************************************/ 
void Led_Off(BYTE Led_Num) /*熄灭LED灯函数*/ 
{ 
Write_Hd7279(0xc0,Led_Num); 
} 
/************************************************************************************/ 
void Write_Hd7279(BYTE Command,BYTE Data) /*HD7279写函数*/ 
{ 
Send_Byte(Command); 
Send_Byte(Data); 
} 
/************************************************************************************/ 
BYTE Read_Hd7279(BYTE Command) /*HD7279读函数*/ 
{ 
Send_Byte(Command); 
return(Receive_Byte()); 
} 
/************************************************************************************/ 
void Send_Byte(BYTE Data_Out) /*HD7279发送字节函数*/ 
{ 
BYTE i; 
Long_Delay(); 
for(i=0;i<8;i++) 
{ 
if(Data_Out&0x80) Set_Bit(Hd7279_Data); 
else Clear_Bit(Hd7279_Data); 
Set_Bit(Hd7279_Clk); 
Short_Delay(); 
Clear_Bit(Hd7279_Clk); 
Short_Delay(); 
Data_Out=Data_Out<<1; 
} 
Clear_Bit(Hd7279_Data); 
} 
/************************************************************************************/ 
BYTE Receive_Byte(void) /*HD7279接收字节函数*/ 
{ 
BYTE i,Data_In; 
Set_Bit(Hd7279_Data); 
Long_Delay(); 
for(i=0;i<8;i++) 
{ 
Set_Bit(Hd7279_Clk); 
Short_Delay(); 
Data_In=Data_In<<1; 
if(Hd7279_Data) Data_In=Data_In|0x01; 
Clear_Bit(Hd7279_Clk); 
Short_Delay(); 
} 
Clear_Bit(Hd7279_Data); 
return(Data_In); 
} 
/************************************************************************************/ 

⌨️ 快捷键说明

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