?? 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 + -