您的位置 首页 发布

51单片机 1602液晶显示操控代码

引脚的连接方式>_:下面是对其各个引脚进行说明:1/*–2REG52.H34Headerfileforgeneric80C52and80C32…

引脚的衔接方法

>_<:下面是对其各个引脚进行阐明:


1 /*--2 REG52.H3 4 Header file for generic 80C52 and 80C32 microcontroller.5 Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.6 All rights reserved.7 --*/8 9 #ifndef __REG52_H__10 #define __REG52_H__11 12 /*  BYTE Registers  */13 sfr P0    = 0x80;14 sfr P1    = 0x90;15 sfr P2    = 0xA0;16 sfr P3    = 0xB0;17 sfr PSW   = 0xD0;18 sfr ACC   = 0xE0;19 sfr B     = 0xF0;20 sfr SP    = 0x81;21 sfr DPL   = 0x82;22 sfr DPH   = 0x83;23 sfr PCON  = 0x87;24 sfr TCON  = 0x88;25 sfr TMOD  = 0x89;26 sfr TL0   = 0x8A;27 sfr TL1   = 0x8B;28 sfr TH0   = 0x8C;29 sfr TH1   = 0x8D;30 sfr IE    = 0xA8;31 sfr IP    = 0xB8;32 sfr SCON  = 0x98;33 sfr SBUF  = 0x99;34 35 /*  8052 Extensions  */36 sfr T2CON  = 0xC8;37 sfr RCAP2L = 0xCA;38 sfr RCAP2H = 0xCB;39 sfr TL2    = 0xCC;40 sfr TH2    = 0xCD;41 42 43 /*  BIT Registers  */44 /*  PSW  */45 sbit CY    = PSW^7;46 sbit AC    = PSW^6;47 sbit F0    = PSW^5;48 sbit RS1   = PSW^4;49 sbit RS0   = PSW^3;50 sbit OV    = PSW^2;51 sbit P     = PSW^0; //8052 only52 53 /*  TCON  */54 sbit TF1   = TCON^7;55 sbit TR1   = TCON^6;56 sbit TF0   = TCON^5;57 sbit TR0   = TCON^4;58 sbit IE1   = TCON^3;59 sbit IT1   = TCON^2;60 sbit IE0   = TCON^1;61 sbit IT0   = TCON^0;62 63 /*  IE  */64 sbit EA    = IE^7;65 sbit ET2   = IE^5; //8052 only66 sbit ES    = IE^4;67 sbit ET1   = IE^3;68 sbit EX1   = IE^2;69 sbit ET0   = IE^1;70 sbit EX0   = IE^0;71 72 /*  IP  */73 sbit PT2   = IP^5;74 sbit PS    = IP^4;75 sbit PT1   = IP^3;76 sbit PX1   = IP^2;77 sbit PT0   = IP^1;78 sbit PX0   = IP^0;79 80 /*  P3  */81 sbit RD    = P3^7;82 sbit WR    = P3^6;83 sbit T1    = P3^5;84 sbit T0    = P3^4;85 sbit INT1  = P3^3;86 sbit INT0  = P3^2;87 sbit TXD   = P3^1;88 sbit RXD   = P3^0;89 90 /*  SCON  */91 sbit SM0   = SCON^7;92 sbit SM1   = SCON^6;93 sbit SM2   = SCON^5;94 sbit REN   = SCON^4;95 sbit TB8   = SCON^3;96 sbit RB8   = SCON^2;97 sbit TI    = SCON^1;98 sbit RI    = SCON^0;99 100 /*  P1  */101 sbit T2EX  = P1^1; // 8052 only102 sbit T2    = P1^0; // 8052 only103              104 /*  T2CON  */105 sbit TF2    = T2CON^7;106 sbit EXF2   = T2CON^6;107 sbit RCLK   = T2CON^5;108 sbit TCLK   = T2CON^4;109 sbit EXEN2  = T2CON^3;110 sbit TR2    = T2CON^2;sbit C_T2   = T2CON^1;112 sbit CP_RL2 = T2CON^0;113 114 #endif

reg52.h 一般自带直接引证就含有这个文件啦


1 /*--2 INTRINS.H3 4 Intrinsic functions for C51.5 Copyright (c) 1988-2004 Keil Elektronik GmbH and Keil Software, Inc.6 All rights reserved.7 --*/8 9 #ifndef __INTRINS_H__10 #define __INTRINS_H__11 12 extern void          _nop_     (void);13 extern bit           _testbit_ (bit);14 extern unsigned char _cror_    (unsigned char, unsigned char);15 extern unsigned int  _iror_    (unsigned int,  unsigned char);16 extern unsigned long _lror_    (unsigned long, unsigned char);17 extern unsigned char _crol_    (unsigned char, unsigned char);18 extern unsigned int  _irol_    (unsigned int,  unsigned char);19 extern unsigned long _lrol_    (unsigned long, unsigned char);20 extern unsigned char _chkfloat_(float);21 extern void          _push_    (unsigned char _sfr);22 extern void          _pop_     (unsigned char _sfr);23 24 #endif

intrins.h 一般自带

1 /*--2 称号:LCD16023 论坛:www.doflye.net4 编写:shifang5 内容:经过规范程序静态显现字符6 引脚界说如下:1-VSS 2-VDD 3-V0 4-RS 5-R/W 6-E 7-14 DB0-DB7 15-BLA 16-BLK7 */8 #include //包括头文件,一般状况不需要改动,头文件包括特别功用寄存器的界说9 #include10 11 sbit RS = P2^4;   //界说端口 12 sbit RW = P2^5;13 sbit EN = P2^6;14 15 #define RS_CLR RS=0 16 #define RS_SET RS=117 18 #define RW_CLR RW=0 19 #define RW_SET RW=1 20 21 #define EN_CLR EN=022 #define EN_SET EN=123 24 #define DataPort P025 /*26 uS延时函数,含有输入参数 unsigned char t,无返回值27 unsigned char 是界说无符号字符变量,其值的规模是28 0~255 这儿运用晶振12M,准确延时请运用汇编,大致延时29 长度如下 T=tx2+5 uS 30 */31 void DelayUs2x(unsigned char t)32 {   33     while(--t);34 }35 /*36 mS延时函数,含有输入参数 unsigned char t,无返回值37 unsigned char 是界说无符号字符变量,其值的规模是38 0~255 这儿运用晶振12M,准确延时请运用汇编39 */40 void DelayMs(unsigned char t)41 {  42     while(t--)43     {44         //大致延时1mS45         DelayUs2x(245);46         DelayUs2x(245);47     }48 }49 /*50 判忙函数51 */52 bit LCD_Check_Busy(void) 53 { 54     DataPort= 0xFF; 55     RS_CLR; 56     RW_SET; 57     EN_CLR; 58     _nop_(); 59     EN_SET;60     return (bit)(DataPort & 0x80);61 }62 /*63 写入指令函数64 */65 void LCD_Write_Com(unsigned char com) 66 {  67     // while(LCD_Check_Busy()); //忙则等候68     DelayMs(5);69     RS_CLR; 70     RW_CLR; 71     EN_SET; 72     DataPort= com; 73     _nop_(); 74     EN_CLR;75 }76 /*77 写入数据函数78 */79 void LCD_Write_Data(unsigned char Data) 80 { 81     //while(LCD_Check_Busy()); //忙则等候82     DelayMs(5);83     RS_SET; 84     RW_CLR; 85     EN_SET; 86     DataPort= Data; 87     _nop_();88     EN_CLR;89 }90 91 /*92 清屏函数93 */94 void LCD_Clear(void) 95 { 96     LCD_Write_Com(0x01); 97     DelayMs(5);98 }99 /*100 写入字符串函数101 */102 void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s) 103 {     104     if (y == 0) 105     {     106         LCD_Write_Com(0x80 + x);     //一共榜首行107     }108     else 109     {      110         LCD_Write_Com(0xC0 + x);      //一共第二行}        112     while (*s) 113     {     114         LCD_Write_Data( *s);     115         s ++;     116     }117 }118 /*119 写入字符函数120 */121 void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data) 122 {     123     if (y == 0) 124     {     125         LCD_Write_Com(0x80 + x);     126     }    127     else 128     {     129         LCD_Write_Com(0xC0 + x);     130     }        131     LCD_Write_Data( Data);  132 }133 /*134 初始化函数135 */136 void LCD_Init(void) 137 {138     LCD_Write_Com(0x38);    /*显现形式设置*/ 139     DelayMs(5); 140     LCD_Write_Com(0x38); 141     DelayMs(5); 142     LCD_Write_Com(0x38); 143     DelayMs(5); 144     LCD_Write_Com(0x38);  145     LCD_Write_Com(0x08);    /*显现封闭*/ 146     LCD_Write_Com(0x01);    /*显现清屏*/ 147     LCD_Write_Com(0x06);    /*显现光标移动设置*/ 148     DelayMs(5); 149     LCD_Write_Com(0x0C);    /*显现开及光标设置*/150 }151 152 /*153 主函数[上面现已把显现功用封装好了,往后再写其他显现就直接调用]154 */ 155 void main(void) 156 { 157     LCD_Init(); 158     LCD_Clear();//清屏159     while (1) 160     {  161         LCD_Write_Char(7,0,o);162         LCD_Write_Char(8,0,k);163         LCD_Write_String(1,1,"www.doflye.net");164         while(1);165     }166 }

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/fabu/265464.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部