链接: 视频
基本框架
User - 用户层(main)
Driver - 底层(固定)
建立工程模板 - 编写底层函数Key,Seg
.c 编写底层函数
.h 声明底层函数
Key_Read(); Seg_Disp()
Key.c
#include <Key.h>
unsigned char Key_Read()
{
unsigned char temp = 0;
if(P3_4 == 0) temp = 1;
if(P3_5 == 0) temp = 2;
if(P3_6 == 0) temp = 3;
if(P3_7 == 0) temp = 4;
return temp;
}
Key.h
#include <REGX52.H>
unsigned char Key_Read();
Seg.c
#include "Seg.h"
unsigned char Seg_Dula[] = {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
unsigned char Seg_Wela[] = {
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void Seg_Disp(unsigned char wela,dula)
{
P0 = 0x00;
P2_6 = 1;
P2_6 = 0;
P0 = Seg_Wela[wela];
P2_7 = 1;
P2_7 = 0;
P0 = Seg_Dula[dula];
P2_6 = 1;
P2_6 = 0;
}
Seg.h
#include <REGX52.H>
void Seg_Disp(unsigned char wela,dula);
Main:
1.头文件
2.变量声明
3.Key_Proc()
4.Seg_Proc()
5.Led_Proc()
6.Timer0Init() 定时器0中断初始化函数,通过stc生成
7.Server 定时器0中断服务函数
8.Main
/* 头文件声明区 */
#include <REGX52.H>//单片机寄存器专用头文件
#include <Key.h>//按键底层驱动专用头文件
#include <Seg.h>//数码管底层驱动专用头文件
/* 变量声明区 */
unsigned char Key_Val,Key_Down,Key_Old;//按键专用变量
unsigned char Key_Slow_Down;//按键减速专用变量