9.零基础入门(四)

零基础入门(四)

建立模板

1.建立两个工程文件夹(User Driver)

2.使用keil5在工程User文件夹内新建工程

3.选择芯片AT89C52,点击OK,点击是拷贝到文件

4.选择品字形,第一列配置工程名字,第二列改为User,加一类Driver

5.OUTPUT勾选hex文件,C51中Include Paths中添加头文件,将Driver文件夹添加

6.在User点击右键添加main头文件

7.添加主体框架

#include <REGX52.H>
void main()
{
	while(1)
	{
	
	}
}

8.点击新建,再点保存,保存至Driver文件,编写头文件,并添加到工程里

Key.c

#include<Key.h>
unsigned char Key_Read()//按键读取函数
{
	unsigned char temp=0;
	P3_0=0;P3_1=1;P3_2=1;P3_3=1;
	if(P3_4 ==0) temp=1;
	if(P3_5 ==0) temp=2;
	if(P3_6 ==0) temp=3;
	if(P3_7 ==0) temp=4;
	P3_0=1;P3_1=0;P3_2=1;P3_3=1;
	if(P3_4 ==0) temp=5;
	if(P3_5 ==0) temp=6;
	if(P3_6 ==0) temp=7;
	if(P3_7 ==0) temp=8;
	P3_0=1;P3_1=1;P3_2=0;P3_3=1;
	if(P3_4 ==0) temp=9;
	if(P3_5 ==0) temp=10;
	if(P3_6 ==0) temp=11;
	if(P3_7 ==0) temp=12;
	P3_0=1;P3_1=1;P3_2=1;P3_3=0;
	if(P3_4 ==0) temp=13;
	if(P3_5 ==0) temp=14;
	if(P3_6 ==0) temp=15;
	if(P3_7 ==0) temp=16;
	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);