基于C51单片机的键盘及LCD显示
- 格式:doc
- 大小:37.50 KB
- 文档页数:8
基于51单片机的数字LCD显示摘要:基于89 C51单片机的数字显示标题硬件实现和软件设计,阐述了它的工作原理。
介绍了研制过程中遇到的问题和解决办法。
通过实验和运行,那头性能可靠,满足设计指标参数,LCD显示具有广阔的市场前景,然后是成熟和普及。
在显示领域,LED显示装置系列微电子技术、计算机技术和信息处理于一体,以其色彩鲜艳、动态范围、高亮度、清晰度高,低电压操作,能耗低、使用寿命长、耐冲击、色彩艳丽、工作可靠、稳定的优势,成为新一代的显示媒体,目前,LED显示屏已被广泛应用于大型广场,商业广告、信息传播、新闻发布、证券交易,能满足不同环境的需要。
由单片机外围电路系统,显示电路、单片机、最小的系统构成。
该系统的安装是容易的检测、软件功能完善、工作可靠、精度高的优点。
论述了单片机控制的液晶数字显示系统,阐述了软件的基本原理,实现您的系统使用的设计及模拟和系统的应用领域。
关键词: 单片机AT89C51、液晶数字显示, 凯尔软件ⅰBased on 51 SCM LCD digital displayAbstract Based on the 89 C51 SCM's digital display header hardware realization and the software design, expounds its principle of work. Introduces the developing process of the multiplier encounter problems and solving methods. Through the test and operation, that the header reliable performance, to meet the design index parameters, and has a broad market prospect, and then the mature and popularity. As in the display field, LED display set series microelectronics technology, computer technology and information processing in the integral whole, with its colourful, dynamic range, high brightness, high-definition, low voltage operation, low consumption, long service life, impact resistance, gorgeous colour and stable and reliable work, become the advantage of a new generation of show media, at present, the LED display has been widely used in large square, commercial advertising, information dissemination, press conference, securities trading, can satisfy the need of different environment. By single-chip microcomputer system, peripheral circuit and single-chip microcomputer and show circuit smallest system formed. This system is easy to install detection, software function is perfect, reliable operation, the advantages of high accuracy.This paper discusses the single-chip microcomputer control by the LCD digital display system, and expounds the basic principle of the Keil software to realize the system using design and simulation and the system applied fields.Keywords: single-chip microcomputer AT89C51, LCD digital display, Keil softwareii目录引言 (1)第一章初识系统 (2)1.1设计过程及工艺要求 (2)1.2设计的重点与难点 (2)第二章系统的设计 (3)2.1系统设计 (3)2.2芯片AT89C51介绍 (3)2.3 AT89S51单片机特性 (6)2.4 LCD显示屏介绍 (6)2.4.1 LCD的定义及作用 (6)2.4.2 LCD显示器的工作原理及主要参数 (6)2.4.3 LCD的分类 (10)2.4.4 LCD的特点 (10)第三章系统调试 (11)3.1 硬件的设计 (11)3.2原理分析 (13)3.3程序的调试与运行 (14)3.3.1 HEX文件的生成 (14)3.3.2 调试与仿真 (14)结论 (15)致谢 (16)参考文献 (17)iii引言目前,控制仪表经常使用的显示面板主要有LCD和LED两种类型,其中LCD比较美观,省电,显示方式灵活,但是价格比较昂贵,最重要的是它的醒目程度较低,可视角度也比较小;而LED数码管虽然功耗较大,但它亮度高,用作工业现场指示时更醒目,而且价格低。
普中51单⽚机按键-数码管显⽰基于普中单⽚机按键-数码管显⽰简介1.硬件部分普中单⽚机开发板 数码管 独⽴按键2.软件部分keil软件硬件部分普中单⽚机开发板数码管独⽴按键(这些都是开发板的最基本的配置)软件部分#include "reg52.h" //此⽂件中定义了单⽚机的⼀些特殊功能寄存器typedef unsigned int u16; //对数据类型进⾏声明定义typedef unsigned char u8;/*端⼝引脚定义*/sbit LSA=P2^2;sbit LSB=P2^3;sbit LSC=P2^4;sbit KEY1 = P3^0;sbit KEY2 = P3^1;/*变量定义*/int number;unsigned char KeyNum=0; //被触发的按键编号unsigned char KeyLock1=0;unsigned char KeyLock2=0;unsigned int cnt;/*函数声明部分*/void KEY_Scan();void KEY_Action();void Light_Scan();void delay(u16 i);void Display();void Time0Iint();/*数码管码表*/unsigned char code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴数码管显⽰0~F的值unsigned char LightBuf[]={0xFF,0xFF,0xFF,0xFF,0XFF};/******************************************************************************** 函数名 : delay* 函数功能 : 延时函数,i=1时,⼤约延时10us*******************************************************************************/void delay(u16 i){while(i--);}/******************************************************************************** 函数名 : Display* 函数功能 : 数码管显⽰部分*******************************************************************************/void Display(){LightBuf[0]=smgduan[number%10];LightBuf[1]=smgduan[number/10%10];LightBuf[2]=smgduan[number/100%10];LightBuf[3]=smgduan[number/1000%10];LightBuf[4]=smgduan[number/10000%10];}/******************************************************************************** 函数名 : Light_Scan()* 函数功能 : 数码管扫描函数,选择显⽰的位置*******************************************************************************/void Light_Scan(){u8 i;for(i=0;i<8;i++){switch(i) //位选,选择点亮的数码管,{case(0):LSA=0;LSB=0;LSC=0;P0=LightBuf[4];break;//显⽰第0位case(1):LSA=1;LSB=0;LSC=0;P0=LightBuf[3];break;//显⽰第1位case(2):LSA=0;LSB=1;LSC=0;P0=LightBuf[2];break;//显⽰第2位case(3):LSA=1;LSB=1;LSC=0;P0=LightBuf[1];break;//显⽰第3位case(4):LSA=0;LSB=0;LSC=1;P0=LightBuf[0];break;//显⽰第4位default: break;}delay(100); //间隔⼀段时间扫描P0=0x00;//消隐}}/******************************************************************************* * 函数名 : KEY_Scan()* 函数功能 : 按键扫描函数*******************************************************************************/ void KEY_Scan(){static unsigned char cnt1 = 0xFF;static unsigned char cnt2 = 0xFF;cnt1 =(cnt1<<1)|KEY1;cnt2 =(cnt2<<1)|KEY2;if(cnt1 != 0x00){KeyLock1 = 0;}else if(KeyLock1==0){KeyNum = 1;KeyLock1 = 1;}if(cnt2 != 0x00){KeyLock2 = 0;}else if(KeyLock2==0){KeyNum = 2;KeyLock2 = 1;}}/******************************************************************************* * 函数名 : KEY_Action()* 函数功能 : 按键执⾏操作部分*******************************************************************************/ void KEY_Action(){switch(KeyNum){case 1:number++; KeyNum = 0; break;case 2:number--; KeyNum = 0; break;default:break;}}/******************************************************************************* * 函数名 :Time0Iint* 函数功能 :定时器0配置,定时器初始化函数*******************************************************************************/ void Time0Iint(){EA=1;TH0 = (65536-2000)/256;//定时2msTL0 = (65536-2000)%256;TMOD &= 0xFC;TMOD = 0x01;ET0 = 1;TR0 = 1;}/******************************************************************************* * 函数名 :void InterruptT0() interrupt 1* 函数功能 : 定时器0中断执⾏部分*******************************************************************************/ void InterruptT0() interrupt 1{TH0 = (65536-2000)/256;//定时2msTL0 = (65536-2000)%256;Light_Scan();KEY_Scan();}/******************************************************************************* * 函数名 : main* 函数功能 : 主函数* 输⼊ : ⽆* 输出 : ⽆*******************************************************************************/ void main(){Time0Iint();while(1){Display();KEY_Action();}}参考资料。
键盘与显示方案
一、简介
键盘与显示实验板有三种显示方式分别为LED显示、数码管显示、LCD1602显示,按键有三种方式分别是直扩按键、164外扩2*8扫描按键、红外遥控,通过硬件设计、制作,软件编程仿真,能够让我们深入理解与学习基本的显示与按键输入,为以后单片机系统的设计打下坚实基础
二、方案
1、方案简介
(1)LED显示简单实用可以用来玩各种花样流水灯,大量的LED灯可以显示字
符、汉字等各种符号,由于本实验板i/o口有限,故在P1口连接八个LED,制作一个简单的跑马灯
(2)数码管显示为静态显示,用两片164外扩(由于i/o较少)protuse仿真连接图如下(数码管为共阳极)
(3)、LCD1602为液晶显示带有字库,可以方便的显示数字、字符、一些特殊符号,故本实验板用1602做一个菜单显示和一个时钟系统,从中熟悉和理解1602的使用,由于1602显示速度较慢故采用数据从P0口并行输入,仿真连接图如下所示
(4)、按键2*8扫描用164扩展,硬件连接如图
二、原理图
1、硬件连接图(由于连线复杂故大多采用标号连接)
1、PCB图
2、软件流程图
(1)、跑马灯(八个LED+四个直扩按键)
(2)、键值显示0~16(数码管+2*8扫描)
(3)、时钟系统(1602+四个直扩按键)
(4)、红外遥控(模拟四个直扩按键)
(5)、菜单显示(1602+三个个直扩)
三、元件列表
名称规格数量备注
89C51 1
LCD1602 1
数码管 2 共阳
74HC164 3
晶振12MHZ 1
按键开关21
电源开关 1
发光二极管 2.2V/1MA 8 白色蓝光电阻若干
电位器1K 1
电容若干。
51单片机之LCD1602液晶显示与4×4矩阵键盘一、要求:液晶显示器第一行显示“Hello World!”;第二行显示键值和按键次数,且按键时间大于1.5秒时,识别为2次按键。
单片机型号:STC--12C5A16AD二、程序代码:#include <reg52.h>#include <intrins.h>#define uchar unsigned char#define uint unsigned intunsigned char code dis[]={"Hello World!"};unsigned char code dis1[]={"KEY:"};unsigned char code dis2[]={"TIME:"};ucharkey_val[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G'};uchar code key_code[]={0x77,0x7B,0x7D,0x7E,0xB7,0xBB,0xBD,0xBE,0xD7,0x DB,0xDD,0xDE,0xE7,0xEB,0xED,0xEE};uchar key,x,count;uint time=0;sbit U3_DS=P1^5;sbit U3_STCP=P1^4;sbit U3_SHCP=P1^3;sbit U4_DS=P1^2;sbit U4_STCP=P1^1;sbit U4_SHCP=P1^0;void delay(unsigned int n);//74HC595void U3_595(unsigned char num){unsigned char count1;for (count1=0;count1<=7;count1++){if ((num&0x80)==0x80)//最高位为1,则向SDATA_595发送1 {U3_DS=1;}else{U3_DS=0;}U3_SHCP=0;U3_SHCP=1;num<<=1;//左移}U3_STCP=0;U3_STCP=1;}void U4_595(unsigned char num)//发送指令到RS,RW,E(4,5,6位){unsigned char count2;for (count2=0;count2<=7;count2++){if((num&0x80)==0x80){U4_DS=1;}else{U4_DS=0;}U4_SHCP=0;U4_SHCP=1;num<<=1;}U4_STCP=0;U4_STCP=1;}//LCD延时子程序 n=1时延时1ms void delay(unsigned int n){unsigned int i;for(;n>0;n--)for(i=0;i<255;i++)_nop_();}//写指令到LCDvoid wcmd(unsigned char cmd) {U4_595(0x00);U3_595(cmd);U4_595(0x40);U4_595(0x00);}//写要显示的数据到LCDvoid wdat(unsigned char dat) {U4_595(0x10);U3_595(dat);U4_595(0x50);U4_595(0x10);}//初始化LCDvoid init(){wcmd(0x38);//设置8位总线双行显示,5*7点阵delay(20);wcmd(0x0C);//开显示,开光标,不闪烁delay(20);wcmd(0x06);//读写字符时地址加1delay(20);wcmd(0x01);//清屏delay(20);wcmd(0x80+2);for(x=0;x<12;x++) //第一行显示hello world! wdat(dis[x]);delay(20);wcmd(0xC2);for(x=0;x<4;x++)//第二行显示按键和次数wdat(dis1[x]);wcmd(0xC8);for(x=0;x<5;x++)wdat(dis2[x]);TMOD=0x01;//中断设置TH0=0x3C;//定时初值设置TL0=0xB0;EA=1;//开中断ET0=1;//定时器0中断允许}//键盘扫描子程序uchar keyscan(void){unsigned char hang,lie,keycode;char i;P0=0xf0;hang=P0;if((hang&0xf0)!=0xf0) //有键按下?{delay(50); //去抖动hang=P0;if((hang&0xf0)!=0xf0) //有键按下{P0=0x0f;lie=P0;keycode=hang|lie; //获得键码for(i=15;i>=0;i--){if(keycode==key_code[i]) //查找键码{key=i;return(key);}}}}else{P0=0xff; //按键弹起则关闭定时器TR0=0;count=0;return (16);}}void keydown() //判断按键按下和显示程序{P0=0xf0;if((P0&0xf0)!=0xf0){TR0=1; //开启定时器while(P0!=0xf0)keyscan(); //获得键码if(count<30){time++;count=0;}else //超过1.5秒计数2次{time+=2;count=0;}wcmd(0xC6); //设置键值显示位置wdat(key_val[16-key]);wcmd(0xCD); //设置次数显示位置if(time<10)wdat(0x30+time);if(time>9&&time<100){wdat(0x30+time/10);wdat(0x30+time%10);}if(time>99&&time<1000){wdat(0x30+time/100);wdat(0x30+time/10-(time/100)*10); wdat(0x30+time%10);}}}//中断函数void timer() interrupt 1{TH0=0x3C;TL0=0xB0;count++;}void main(void){init();for(;;){keydown();}}。