hd7279芯片程序

上传人:第*** 文档编号:34611280 上传时间:2018-02-26 格式:DOC 页数:5 大小:30.50KB
返回 下载 相关 举报
hd7279芯片程序_第1页
第1页 / 共5页
hd7279芯片程序_第2页
第2页 / 共5页
hd7279芯片程序_第3页
第3页 / 共5页
hd7279芯片程序_第4页
第4页 / 共5页
hd7279芯片程序_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《hd7279芯片程序》由会员分享,可在线阅读,更多相关《hd7279芯片程序(5页珍藏版)》请在金锄头文库上搜索。

1、/*/ /* */ /* 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)中 hd727

2、9 键盘显示芯片是否能正常工作 */ /*程式功能:按下 1 号键显示 0、1、2 、3,按下 2 号键显示 c、d、e 、f ,按下 3 号键显示 4、5 、6 、7 */ /* 按下 4 号键显示 8、9、a 、b,按下 0 号键点亮 4 个 LED 灯 */ /*/ #include /*定义头文档 */ /*/ typedef unsigned char BYTE; /*自定义字节类型*/ /*/ #define Set_Bit(BIT) (BIT = 1) /*定义置 1 函数*/ #define Clear_Bit(BIT) (BIT = 0) /*定义清 0 函数*/ /*/ v

3、oid 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_D

4、elay(void); /*定义长延时函数*/ void Mcu_Init(void); /*定义 MCU 初始化函数*/ void Delay_200_mS(void); /*定义 200ms 延时函数*/ /*/ BYTE Keyboard_Out; /*定义键值变量*/ bit Keyboard_Flag; /*定义按键标志*/ /*/ sbit Hd7279_Key=P32; /*定义 HD7279 中断硬件连接*/ sbit Hd7279_Clk=P21; /*定义 HD7279 时钟硬件连接 */ sbit Hd7279_Data=P20; /*定义 HD7279 数据硬件连接*/

5、 /*/ void main(void) /*主函数*/ Mcu_Init(); /*MCU 初始化 */ while(1) if(Keyboard_Flag) Clear_Bit(Keyboard_Flag); if(Keyboard_Out=0) /*0 号键处理*/ Led_On(0x00); Led_On(0x01); Led_On(0x02); Led_On(0x03); else if(Keyboard_Out=1) /*1 号键处理*/ /*显示 0、1、2、3*/ Write_Hd7279(0xc9,0x03); Write_Hd7279(0xca,0x02); Write_H

6、d7279(0xcb,0x01); Write_Hd7279(0xcc,0x00); Led_Off(0x02); else if(Keyboard_Out=2) /*2 号键处理*/ /*显示 c、d、e、f*/ Write_Hd7279(0xc9,0x0f); Write_Hd7279(0xca,0x0e); Write_Hd7279(0xcb,0x0d); Write_Hd7279(0xcc,0x0c); Led_Off(0x02); else if(Keyboard_Out=3) /*3 号键处理*/ /*显示 4、5、6、7*/ Write_Hd7279(0xc9,0x07); Wr

7、ite_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

8、i,j; i=200; while (i-) j=228; while(j-); /*/ void Mcu_Init(void) /*MCU 初始化函数*/ Set_Bit(EX0); /*外部中断 0 使能*/ Set_Bit(IT0); /*外部中断 0 下降沿触发*/ Set_Bit(EA); /*中断使能*/ Send_Byte(0xa4); /*HD7279 复位*/ Write_Hd7279(0x98,0x1f); /*HD7279 启动消隐功能,能提高灯的亮度*/ Write_Hd7279(0xc9,0x03); /*上电显示 6、5、4、3*/ Write_Hd7279(0xc

9、a,0x04); Write_Hd7279(0xcb,0x05); Write_Hd7279(0xcc,0x06); /*/ 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;i0x08;i+); /*/ void Long_Delay(void

10、) /*长延时函数*/ BYTE i; for(i=0;i0x30;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_H

11、d7279(BYTE Command) /*HD7279 读函数*/ Send_Byte(Command); return(Receive_Byte(); /*/ void Send_Byte(BYTE Data_Out) /*HD7279 发送字节函数*/ BYTE i; Long_Delay(); for(i=0;i8;i+) if(Data_Out else Clear_Bit(Hd7279_Data); Set_Bit(Hd7279_Clk); Short_Delay(); Clear_Bit(Hd7279_Clk); Short_Delay(); Data_Out=Data_Out1;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号