?? ps2.lst
字號:
C51 COMPILER V7.06 PS2 06/06/2004 19:47:47 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE PS2
OBJECT MODULE PLACED IN ps2.OBJ
COMPILER INVOKED BY: E:\Keil706\C51\BIN\C51.EXE ps2.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <at89x51.h>
2 #include "scancodes.h"
3
4 #define LCM_RW P1_1 //定義LCD引腳
5 #define LCM_RS P1_0
6 #define LCM_E P1_2
7 #define LCM_Data P0
8
9 #define Key_Data P1_7 //定義Keyboard引腳
10 #define Key_CLK P3_2
11
12 #define Busy 0x80 //用于檢測LCM狀態字中的Busy標識
13
14 void LCMInit(void);
15 void DisplayOneChar(unsigned char X,unsigned char Y,unsigned char DData);
16 void DisplayListChar(unsigned char X,unsigned char Y,unsigned char code *DData);
17 void Delay5Ms(void);
18 void Delay400Ms(void);
19 void Decode(unsigned char ScanCode);
20 void WriteDataLCM(unsigned char WDLCM);
21 void WriteCommandLCM(unsigned char WCLCM,BuysC);
22
23 unsigned char ReadDataLCM(void);
24 unsigned char ReadStatusLCM(void);
25 unsigned char code cdle_net[] = {"-www.cdle.net--"};
26 unsigned char code email[] = {"pnzwzw@cdle.net"};
27 unsigned char code Cls[] = {" "};
28 static unsigned char IntNum = 0; //中斷次數計數
29 static unsigned char KeyV; //鍵值
30 static unsigned char DisNum = 0; //顯示用指針
31 static unsigned char Key_UP=0, Shift = 0;//Key_UP是鍵松開標識,Shift是Shift鍵按下標識
32 static unsigned char BF = 0; //標識是否有字符被收到
33
34 void main(void)
35 {
36 1 unsigned char TempCyc;
37 1
38 1 Delay400Ms(); //啟動等待,等LCM講入工作狀態
39 1 LCMInit(); //LCM初始化
40 1 Delay5Ms(); //延時片刻(可不要)
41 1
42 1 DisplayListChar(0, 0, cdle_net);
43 1 DisplayListChar(0, 1, email);
44 1 ReadDataLCM();//測試用句無意義
45 1 for(TempCyc=0; TempCyc<10; TempCyc++) {
46 2 Delay400Ms(); //延時
47 2 }
48 1 DisplayListChar(0, 1, Cls);
49 1
50 1 IT0 = 0; //設外部中斷1為低電平觸發
51 1 EX0 = 1; //開中斷
52 1 EA = 1;
53 1
54 1 while(1) {
55 2 if(BF)
C51 COMPILER V7.06 PS2 06/06/2004 19:47:47 PAGE 2
56 2 Decode(KeyV);
57 2 else {
58 3 EA = 1; //開中斷
59 3 }
60 2 }
61 1 }
62
63 //寫數據
64 void WriteDataLCM(unsigned char WDLCM)
65 {
66 1 ReadStatusLCM(); //檢測忙
67 1 LCM_Data = WDLCM;
68 1 LCM_RS = 1;
69 1 LCM_RW = 0;
70 1 LCM_E = 0; //若晶振速度太高可以在這后加小的延時
71 1 LCM_E = 0; //延時
72 1 LCM_E = 1;
73 1 }
74
75 //寫指令
76 void WriteCommandLCM(unsigned char WCLCM,BuysC) //BuysC為0時忽略忙檢測
77 {
78 1 if(BuysC) ReadStatusLCM(); //根據需要檢測忙
79 1 LCM_Data = WCLCM;
80 1 LCM_RS = 0;
81 1 LCM_RW = 0;
82 1 LCM_E = 0;
83 1 LCM_E = 0;
84 1 LCM_E = 1;
85 1 }
86
87 //讀數據
88 unsigned char ReadDataLCM(void)
89 {
90 1 LCM_RS = 1;
91 1 LCM_RW = 1;
92 1 LCM_E = 0;
93 1 LCM_E = 1;
94 1
95 1 return(LCM_Data);
96 1 }
97
98 //讀狀態
99 unsigned char ReadStatusLCM(void)
100 {
101 1 LCM_Data = 0xFF;
102 1 LCM_RS = 0;
103 1 LCM_RW = 1;
104 1 LCM_E = 0;
105 1 LCM_E = 1;
106 1 while(LCM_Data & Busy); //檢測忙信號
107 1
108 1 return(LCM_Data);
109 1 }
110
111 void LCMInit(void) //LCM初始化
112 {
113 1 LCM_Data = 0;
114 1 WriteCommandLCM(0x38,0); //三次顯示模式設置,不檢測忙信號
115 1 Delay5Ms();
116 1 WriteCommandLCM(0x38,0);
117 1 Delay5Ms();
C51 COMPILER V7.06 PS2 06/06/2004 19:47:47 PAGE 3
118 1 WriteCommandLCM(0x38,0);
119 1 Delay5Ms();
120 1
121 1 WriteCommandLCM(0x38,1); //顯示模式設置,開始要求每次檢測忙信號
122 1 WriteCommandLCM(0x08,1); //關閉顯示
123 1 WriteCommandLCM(0x01,1); //顯示清屏
124 1 WriteCommandLCM(0x06,1); // 顯示光標移動設置
125 1 WriteCommandLCM(0x0F,1); // 顯示開及光標設置
126 1 }
127
128 //按指定位置顯示一個字符
129 void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
130 {
131 1 Y &= 0x1;
132 1 X &= 0xF; //限制X不能大于15,Y不能大于1
133 1 if(Y)
134 1 X |= 0x40; //當要顯示第二行時地址碼+0x40;
135 1 X |= 0x80; //算出指令碼
136 1 WriteCommandLCM(X, 1); //發命令字
137 1 WriteDataLCM(DData); //發數據
138 1 }
139
140 //按指定位置顯示一串字符
141 void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
142 {
143 1 unsigned char ListLength;
144 1
145 1 ListLength = 0;
146 1 Y &= 0x1;
147 1 X &= 0xF; //限制X不能大于15,Y不能大于1
148 1 while (DData[ListLength]>0x19) {//若到達字串尾則退出
149 2 if(X <= 0xF) {//X坐標應小于0xF
150 3 DisplayOneChar(X, Y, DData[ListLength]); //顯示單個字符
151 3 ListLength++;
152 3 X++;
153 3 }
154 2 }
155 1 }
156
157 //5ms延時
158 void Delay5Ms(void)
159 {
160 1 unsigned int TempCyc = 5552;
161 1 while(TempCyc--)
162 1 ;
163 1 }
164
165 //400ms延時
166 void Delay400Ms(void)
167 {
168 1 unsigned char TempCycA = 5;
169 1 unsigned int TempCycB;
170 1 while(TempCycA--) {
171 2 TempCycB=7269;
172 2 while(TempCycB--)
173 2 ;
174 2 }
175 1 }
176
177 void Keyboard_out(void) interrupt 0
178 {
179 1 if((IntNum > 0) && (IntNum < 9)) {
C51 COMPILER V7.06 PS2 06/06/2004 19:47:47 PAGE 4
180 2 KeyV >>= 1; //因鍵盤數據是低>>高,結合上一句所以右移一位
181 2 if(Key_Data) {
182 3 KeyV |= 0x80; //當鍵盤數據線為1時為1到最高位
183 3 }
184 2 }
185 1 IntNum++;
186 1 while(!Key_CLK); //等待PS/2CLK拉高
187 1 if(IntNum > 10) {
188 2 IntNum = 0; //當中斷10次后表示一幀數據收完,清變量準備下一次接收
189 2 BF = 1; //標識有字符輸入完了
190 2 EA = 0; //關中斷等顯示完后再開中斷 (注:如這里不用BF和關中斷直接調Decode()則所Decode中所調用的所有函
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -