📄 key.lst
字号:
C51 COMPILER V8.02 KEY 08/26/2008 16:25:31 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE KEY
OBJECT MODULE PLACED IN KEY.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE KEY.C BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <REG2051.H>
2 #include <intrins.h>
3 #include <stdlib.h>
4
5 #define Uchar unsigned char
6 #define Uint unsigned int
7 #define Ulong unsigned long
8
9 Uchar bdata flag;
10 sbit addflag=flag^0; //加标志位
11 sbit subflag=flag^1; //减标志位
12 sbit mulflag=flag^2; //乘标志位
13 sbit divflag=flag^3; //除标志位
14 sbit offflag=flag^4; //关开键
15 sbit equflag=flag^5; //等于键
16
17 Ulong progrm(Ulong ,Ulong); //运算子程序
18
19 Uchar get_ch(void); //按键值
20 Uchar *get_str(Uchar *str,Uint len); //按键字符串
21 bit kb_hit(void); //按键检测
22 void delay(int x); //延时
23 void initflag(void); //标志变量初始化
24
25 //主函数
26 void main(void)
27 {
28 1 Uchar i;
29 1 Uchar str[14];
30 1 Uchar xy[6],ab[6];
31 1 Uint temp,temp_data,temp_data_a;
32 1 Uchar pos=0;
33 1 Uchar pos_a=0;
34 1 initflag();
35 1
36 1 while(1){
37 2 if(!get_str(str,14)) //
38 2 continue;
39 2 for(i=0;i<6;i++)
40 2 {
41 3 if(str[i]<0x40)
42 3 {
43 4 ++pos;
44 4 xy[i]=str[i];
45 4 }
46 3 else
47 3 {
48 4 xy[pos++]=0;
49 4 break;
50 4 }
51 3
52 3 }
53 2
54 2 for(i=0;i<6;i++)
55 2 {
C51 COMPILER V8.02 KEY 08/26/2008 16:25:31 PAGE 2
56 3 if(str[i+pos]<0x40)
57 3 {
58 4 ++pos_a;
59 4 ab[i]=str[i+pos];
60 4 }
61 3 else
62 3 {
63 4 ab[pos_a]=0;
64 4 break;
65 4 }
66 3 }
67 2 temp_data=atoi(xy);
68 2 temp_data_a=atoi(ab);
69 2 if(temp_data<0||temp_data_a<0)
70 2 continue;
71 2 //----------------------------------------------------------------------
72 2 temp_data=2;
73 2 temp_data_a=3;
74 2 if(equflag)
75 2 {
76 3 equflag=0;
77 3 temp= progrm(temp_data,temp_data_a);
78 3
79 3 for(i=0;i<4;i++)
80 3 {
81 4
82 4
83 4 temp_data=temp&0xf000;
84 4 SBUF=temp_data>>=12;
85 4 while(!TI);
86 4 TI=0; // 从串口发出去.
87 4 temp<<=4;
88 4
89 4 }
90 3 while(1);
91 3 }
92 2 //----------------------------------------------------------------------------------
93 2
94 2 if(equflag)
95 2 {
96 3 equflag=0;
97 3 temp= progrm(temp_data,temp_data_a);
98 3 //temp=0x8;
99 3 if(temp)
100 3 {
101 4 for(i=0;i<4;i++)
102 4 {
103 5 temp_data=temp&0xf000;
104 5 SBUF=temp_data>>=12;
105 5 while(!TI);
106 5 TI=0; // 从串口发出去.
107 5 temp<<=4;
108 5
109 5 }
110 4 }
111 3
112 3 }
113 2 }
114 1
115 1 }
116 Ulong progrm(Ulong x ,Ulong y)
117 {
C51 COMPILER V8.02 KEY 08/26/2008 16:25:31 PAGE 3
118 1 Uint temp=0;
119 1
120 1 if(addflag)
121 1 {
122 2 temp=x+y;
123 2 return temp;
124 2 }
125 1 if(subflag)
126 1 {
127 2 if(x<y)
128 2 return 0;
129 2 temp=x-y;
130 2 return temp;
131 2 }
132 1 if(mulflag)
133 1 {
134 2 temp=x*y;
135 2 return temp;
136 2 }
137 1 if(divflag)
138 1 {
139 2 if((x<y)||(y==0))
140 2 return 0;
141 2 temp= x/y;
142 2 return(temp);
143 2 }
144 1 //return 0 ;
145 1
146 1 }
147 //------------------------------------------------------------------------------------
148 Uchar get_ch()
149 {
150 1 Uchar row=0,col=0;
151 1 Uchar mask=0xef;
152 1 Uchar pic;
153 1 if(!kb_hit())
154 1 return(0); /*无键按下,输入不成功,返回0*/
155 1 /*分析按键所在的列号*/
156 1 P1=mask;
157 1
158 1 while((P3&0x3f)==0x3f&&mask>0x7f)
159 1 {
160 2 ++col;
161 2 mask=_crol_(mask,1);
162 2
163 2 P1=mask;
164 2
165 2 }
166 1 /*分析按键所在的行号*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -