📄 led.lst
字号:
C51 COMPILER V8.02 LED 09/21/2006 20:16:34 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LED
OBJECT MODULE PLACED IN Led.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Led.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*============================================================
2 功能:使用TM1623数码管显示演示.
3 作者: Mingtree ycxms88@163.com http://www.mcu123.com
4
5
6 ==============================================================*/
7
8 #include <REG52.H>
9 //TM1623显示控制口
10
11 sbit DOUT_LED=P1^5;
12 sbit DIN_LED=P1^2;
13 sbit CS_LED=P1^0;
14 sbit CLK_LED=P1^4;
15
16
17 unsigned char Disp_Buf[6];
18
19 /*;========================================================================================
- 10
20 ; 0 1 2 3 4 5 6 7 8 9 A B C D E F */
21 unsigned char code D_Code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0xF7,0x77,0xB7,0xC7,0xE2,
-0xD5,0xff};/*显示码表*/
22
23 //延时
24 void dly(unsigned int i)
25 {
26 1 while (i--)
27 1 {
28 2 ;
29 2 } ;
30 1 }
31
32 //输出一个字节
33 void Sent_Byte(unsigned char wrdata){
34 1 unsigned char k;
35 1 CLK_LED=0;
36 1
37 1 for(k=0;k<8;k++){
38 2 if((wrdata & 0x01)==0){
39 3 DIN_LED=0;
40 3 }
41 2 else{
42 3 DIN_LED=1;
43 3 }
44 2 wrdata>>=1;
45 2 CLK_LED=1;
46 2
47 2 CLK_LED=0;
48 2
49 2 }
50 1 }
51
52
53 /*//显示程序
C51 COMPILER V8.02 LED 09/21/2006 20:16:34 PAGE 2
54 void disp(void)
55 {
56 CLK_LED0;
57 CS_LED0;
58 Sent_Byte(0xc1);
59 CS_LED1;
60 CLK_LED0;
61 CS_LED0;
62 Sent_Byte(0xf8);
63 Sent_Byte(0x88);
64 Sent_Byte(0x61);
65 CS_LED1;
66 }
67 */
68 void Disp_Led(void)
69 {
70 1 CS_LED=0;
71 1 Sent_Byte(0x01);//显示模式5位13段
72 1 CS_LED=1;
73 1
74 1 CS_LED=0;
75 1 Sent_Byte(0x40);//设置数据
76 1 CS_LED=1;
77 1
78 1 CS_LED=0;
79 1 Sent_Byte(0xc0);//设置地址
80 1 Sent_Byte(D_Code[Disp_Buf[0]]);//1
81 1 Sent_Byte(0x00);
82 1 Sent_Byte(D_Code[Disp_Buf[1]]);//2
83 1 Sent_Byte(0x00);
84 1 Sent_Byte(D_Code[Disp_Buf[2]]);//3
85 1 Sent_Byte(0x00);
86 1 Sent_Byte(D_Code[Disp_Buf[3]]);//4
87 1 Sent_Byte(0x00);
88 1 Sent_Byte(D_Code[Disp_Buf[4]]);//5
89 1 //Sent_Byte(0x00);
90 1
91 1 CS_LED=1;
92 1 CS_LED=0;
93 1 Sent_Byte(0x8a);//控制显示
94 1 CS_LED=1;
95 1 }
96
97 void Fill_DispBuf(void)
98 {
99 1 Disp_Buf[0]=1;
100 1 Disp_Buf[1]=1;
101 1 Disp_Buf[2]=8;
102 1 Disp_Buf[3]=8;
103 1 Disp_Buf[4]=0x10;
104 1 }
105
106
107 unsigned char Scan_Key(void)//按键读数据子程序
108 {
109 1 unsigned char key_i,key_temp;//key_read;
110 1 key_temp=0;
111 1 for(key_i=0;key_i<8;key_i++)
112 1 {
113 2 key_temp>>=1;
114 2 CLK_LED=0;//下降沿输出数据
115 2
C51 COMPILER V8.02 LED 09/21/2006 20:16:34 PAGE 3
116 2 if(DOUT_LED!=0)
117 2 key_temp=key_temp|0x80;
118 2 //key_read=key_temp;
119 2 CLK_LED=1;
120 2
121 2
122 2 }
123 1 return key_temp;
124 1 }
125
126 unsigned char Get_Key(void)//按键处理子程序,返回按键编号
127 {
128 1 unsigned char K1,K2;
129 1 CS_LED=0;
130 1 Sent_Byte(0x42);//读键扫数据指令
131 1 K1=Scan_Key()&0x1b;
132 1 K2=Scan_Key()&0x1b;
133 1 CS_LED=1;
134 1 if(K1!=0x00)
135 1 {
136 2 switch(K1)
137 2 {
138 3 case 0x01:
139 3 return 0x01;
140 3 break;
141 3 case 0x02:
142 3 return 0x02;
143 3 break;
144 3 case 0x08:
145 3 return 0x03;
146 3 break;
147 3 case 0x10:
148 3 return 0x04;
149 3 break;
150 3 default:
151 3 return 0x00;
152 3 break;
153 3 }
154 2 }
155 1 if(K2!=0x00)
156 1 {
157 2 switch(K2)
158 2 {
159 3 case 0x01:
160 3 return 0x05;
161 3 break;
162 3 case 0x02:
163 3 return 0x06;
164 3 break;
165 3 case 0x08:
166 3 return 0x07;
167 3 break;
168 3 case 0x10:
169 3 return 0x08;
170 3 break;
171 3 default:
172 3 return 0x00;
173 3 break;
174 3 }
175 2 }
176 1 return 0x00;
177 1 }
C51 COMPILER V8.02 LED 09/21/2006 20:16:34 PAGE 4
178
179 void Disp_All(void)
180 {
181 1 Fill_DispBuf();
182 1 Disp_Buf[3]=Get_Key();
183 1 Disp_Led();
184 1 }
185
186 void Disp_buf(unsigned char xdata * buf)
187 {
188 1 Disp_Buf[0]=buf[0]-0x30;
189 1 Disp_Buf[1]=buf[1]-0x30;
190 1 Disp_Buf[2]=buf[2]-0x30;
191 1 Disp_Buf[3]=buf[3]-0x30;
192 1 Disp_Buf[4]=0x10;
193 1 Disp_Led();
194 1
195 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 299 ----
CONSTANT SIZE = 17 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 6 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -