📄 clock- lcd1602.lst
字号:
C51 COMPILER V8.02 CLOCK__LCD1602 12/24/2006 12:07:26 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE CLOCK__LCD1602
OBJECT MODULE PLACED IN CLOCK- LCD1602.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE CLOCK- LCD1602.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*******************************************************************
2 * *
3 * ME500单片机开发系统演示程序 - 时钟 *
4 * *
5 * LCD1602显示 *
6 * *
7 * 版本: V1.0 (2006/11/20) *
8 * 作者: gguoqing (Email: gguoqing@willar.com) *
9 * 网站: www.willar.com(伟纳电子) www.mcusj.com(伟纳单片机世界) *
10 * 时间: 2006/12/23 *
11 * *
12 *【版权】Copyright(C)伟纳电子 www.willar.com All Rights Reserved *
13 *【声明】此程序仅用于学习与参考,引用请注明版权和作者信息! *
14 * *
15 *******************************************************************/
16
17 #include <reg51.h>
18 #include <intrins.h>
19
20 #define uchar unsigned char
21 #define uint unsigned int
22
23 sbit K1 = P1^4;
24 sbit K2 = P1^5;
25 sbit K3 = P1^6;
26 sbit K4 = P1^7;
27 sbit BEEP = P3^7; //蜂鸣器
28
29 uchar code cdis1[ ] = {" WELCOME TO "};
30 uchar code cdis2[ ] = {" WWW.WILLAR.COM "};
31 uchar code cdis3[ ] = {" BEIJING TIME "};
32 uchar code cdis4[ ] = {"TIME: "};
33 uchar code cdis5[ ] = {" RESET REALTIME "};
34
35 sbit LCD_RS = P2^0;
36 sbit LCD_RW = P2^1;
37 sbit LCD_EN = P2^2;
38
39 #define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
40
41 bit settime,updown;
42 uchar msec,sec,min=59,hour=23,m,count;
43
44 uchar display[] = {0x00,0x00,0x00,0x00,0x00,0x00};
45
46 /*********************************************************
47 * *
48 * 延时函数 *
49 * *
50 *********************************************************/
51 void Delay(uint num)//延时函数
52 {
53 1 while( --num );
54 1 }
55
C51 COMPILER V8.02 CLOCK__LCD1602 12/24/2006 12:07:26 PAGE 2
56 /*********************************************************
57 * *
58 * 延时函数 *
59 * *
60 *********************************************************/
61 void delay1(int ms)
62 {
63 1 unsigned char n;
64 1 while(ms--)
65 1 {
66 2 for(n = 0; n<250; n++)
67 2 {
68 3 _nop_();
69 3 _nop_();
70 3 _nop_();
71 3 _nop_();
72 3 }
73 2 }
74 1 }
75
76 /**********************************************************
77 * *
78 * 蜂鸣器响一声 *
79 * *
80 **********************************************************/
81 void beep()
82 {
83 1 unsigned char y;
84 1 for (y=0;y<180;y++)
85 1 {
86 2 BEEP=!BEEP; //BEEP取反
87 2 Delay(70);
88 2 }
89 1 BEEP=1; //关闭蜂鸣器
90 1 delay1(100);
91 1
92 1 }
93
94 /**********************************************************
95 * *
96 * 检查LCD忙状态 *
97 * lcd_busy为1时,忙,等待。 *
98 * lcd-busy为0时,闲,可写指令与数据。 *
99 * *
100 **********************************************************/
101 bit lcd_busy()
102 {
103 1 bit result;
104 1 LCD_RS = 0;
105 1 LCD_RW = 1;
106 1 LCD_EN = 1;
107 1 delayNOP();
108 1 result = (bit)(P0&0x80);
109 1 LCD_EN = 0;
110 1 return(result);
111 1 }
112
113 /**********************************************************
114 * *
115 *写指令数据到LCD *
116 *RS=L,RW=L,E=高脉冲,D0-D7=指令码。 *
117 * *
C51 COMPILER V8.02 CLOCK__LCD1602 12/24/2006 12:07:26 PAGE 3
118 **********************************************************/
119 void lcd_wcmd(uchar cmd)
120 {
121 1 while(lcd_busy());
122 1 LCD_RS = 0;
123 1 LCD_RW = 0;
124 1 LCD_EN = 0;
125 1 _nop_();
126 1 _nop_();
127 1 P0 = cmd;
128 1 delayNOP();
129 1 LCD_EN = 1;
130 1 delayNOP();
131 1 LCD_EN = 0;
132 1 }
133
134 /**********************************************************
135 * *
136 *写显示数据到LCD *
137 *RS=H,RW=L,E=高脉冲,D0-D7=数据。 *
138 * *
139 **********************************************************/
140 void lcd_wdat(uchar dat)
141 {
142 1 while(lcd_busy());
143 1 LCD_RS = 1;
144 1 LCD_RW = 0;
145 1 LCD_EN = 0;
146 1 P0 = dat;
147 1 delayNOP();
148 1 LCD_EN = 1;
149 1 delayNOP();
150 1 LCD_EN = 0;
151 1 }
152
153 /**********************************************************
154 * *
155 * LCD初始化设定 *
156 * *
157 **********************************************************/
158 void lcd_init()
159 {
160 1 delay1(15);
161 1 lcd_wcmd(0x01); //清除LCD的显示内容
162 1 lcd_wcmd(0x38); //16*2显示,5*7点阵,8位数据
163 1 delay1(5);
164 1 lcd_wcmd(0x38);
165 1 delay1(5);
166 1 lcd_wcmd(0x38);
167 1 delay1(5);
168 1
169 1 lcd_wcmd(0x0c); //开显示,不显示光标
170 1 delay1(5);
171 1
172 1 lcd_wcmd(0x01); //清除LCD的显示内容
173 1 delay1(5);
174 1 }
175
176 /**********************************************************
177 * *
178 * 设定显示位置 *
179 * *
C51 COMPILER V8.02 CLOCK__LCD1602 12/24/2006 12:07:26 PAGE 4
180 **********************************************************/
181
182 void lcd_pos(uchar pos)
183 {
184 1 lcd_wcmd(pos | 0x80); //数据指针=80+地址变量
185 1 }
186
187 /**********************************************************
188 * *
189 * 显示函数 *
190 * *
191 **********************************************************/
192 void play(uchar input1,input2,input3)
193 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -