📄 vterminal_uart_wave.lst
字号:
C51 COMPILER V7.20 VTERMINAL_UART_WAVE 07/29/2006 16:03:59 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE VTERMINAL_UART_WAVE
OBJECT MODULE PLACED IN VTerminal_uart_wave.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE VTerminal_uart_wave.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //智能显示终端串口(Uart)通信演示程序。
2 //
3 #include <reg51.h>
4 #include <stdio.h>
5 #include <string.h>
6 #define uchar unsigned char
7
8 uchar Fcolor; //背景色
9 uchar Bcolor; //前景色
10
11 Lcd_Clr();
12 dis_wave(unsigned short x0,unsigned short y0,uchar con,unsigned short *p_data);
13
14 /********************************************
15 定义数据常量,这些数据在实际应用中一般由A/D转换器采样所得到。
16 这里的每一个字节代表一个Y轴坐标的大小即幅度。
17 **********************************************/
18 unsigned short code y_data1[110] = {
19 0x0b,0x0b,0x0b,0x0b,0x0b,
20 0x0b,0x0b,0x0b,0x0b,0x0b,
21 0x0b,0x0b,0x0b,0x0b,0x0b,
22 0x1c,0x1c,0x1c,0x1c,0x1c,
23 0x1c,0x1c,0x1c,0x1c,0x1c,
24 0x1c,0x1c,0x1c,0x1c,0x1c,
25 0x1c,0x1c,0x1c,0x1c,0x1c,
26 0x00,0x00,0x00,0x00,0x00,
27 0x00,0x00,0x00,0x00,0x00,
28 0x00,0x00,0x00,0x00,0x00,
29 0x00,0x00,0x00,0x00,0x00,
30 0x50,0x50,0x50,0x50,0x50,
31 0x50,0x50,0x50,0x50,0x50,
32 0x50,0x50,0x50,0x50,0x50,
33 0x50,0x50,0x50,0x50,0x50,
34 0x50,0x50,0x50,0x50,0x50,
35 0x48,0x46,0x44,0x42,0x40,
36 0x3e,0x3c,0x3a,0x38,0x36,
37 0x34,0x32,0x30,0x2e,0x2c,
38 0x2a,0x28,0x26,0x24,0x22,
39 0x20,0x1e,0x1c,0x1a,0x18,
40 0x16,0x14,0x12,0x10,0x84
41 };
42
43 unsigned short code y_data2[110] = {
44 0x015e,0x015e,0x015e,0x015e,0x015e,
45 0x015e,0x015e,0x015e,0x015e,0x015e,
46 0x015e,0x015e,0x015e,0x015e,0x015e,
47 0x015e,0x015e,0x015e,0x015e,0x015e,
48 0x015e,0x015e,0x015e,0x015e,0x015e,
49 0x015e,0x015e,0x015e,0x015e,0x015e,
50 0x015e,0x015e,0x015e,0x015e,0x015e,
51 0x00,0x00,0x00,0x00,0x00,
52 0x00,0x00,0x00,0x00,0x00,
53 0x00,0x00,0x00,0x00,0x00,
54 0x00,0x00,0x00,0x00,0x00,
55 0x0084,0x0084,0x0084,0x0084,0x0084,
C51 COMPILER V7.20 VTERMINAL_UART_WAVE 07/29/2006 16:03:59 PAGE 2
56 0x0084,0x0084,0x0084,0x0084,0x0084,
57 0x0084,0x0084,0x0084,0x0084,0x0084,
58 0x0084,0x0084,0x0084,0x0084,0x0084,
59 0x0084,0x0084,0x0084,0x0084,0x0084,
60 0x48,0x46,0x44,0x42,0x40,
61 0x3e,0x3c,0x3a,0x38,0x36,
62 0x34,0x32,0x30,0x2e,0x2c,
63 0x2a,0x28,0x26,0x24,0x22,
64 0x20,0x1e,0x1c,0x1a,0x18,
65 0x16,0x14,0x12,0x10,0xffff
66 };
67
68 main(void)
69 {
70 1 unsigned int i;
71 1
72 1 //对AT89C51(11.059MHz)的串口初始化
73 1 TMOD=0x20; //定时器1设置为模式2
74 1 SM0=0;
75 1 SM1=1; //设置串口为方式1,10位异步收发
76 1 PCON=PCON|0x80; //波特率加倍
77 1 TL1=0xFD;
78 1 TH1=0xFD; //波特率为19200
79 1 TR1=1; //启动定时器1
80 1 REN = 1; //允许串口接受使能
81 1
82 1 //EA=1; //全局中断使能,(EA=0,关全局中断;EA=1,开全局中断)
83 1 //ES = 1; //串口中断使能置1,允许串口中断
84 1
85 1 Fcolor = 0x0;
86 1 Bcolor = 0xff;
87 1 i = 0;
88 1
89 1 //显示终端在上电就绪时发送F0.用仿真器时不要检测F0.
90 1 //当把程序烧写到单片机上时,显示终端和单片机同时上电,所以一定
91 1 //要检测是否收到F0。以判断显示终端是否上电就绪
92 1 //while(!(i == 0xF0))
93 1 //{i = SBUF;}
94 1
95 1 Lcd_Clr(); //清除全屏。
96 1 Fcolor = 0xe0;
97 1 dis_wave(0,0,1,y_data1); //以 (0,0) 为坐标原点显示波形。幅度为单字节
98 1 Fcolor = 0x1c;
99 1 dis_wave(100,100,2,y_data2); //以 (80,80) 为坐标原点显示波形。幅度为双字节。
100 1 Fcolor = 0xff;
101 1 while(1);
102 1 }
103
104 //查看一个字符是否传送完毕,当一个字符传送完毕后TI位会被硬件置1;
105 void check_uart(void)
106 {
107 1 while(TI==0)
108 1 {}
109 1 TI=0;
110 1 }
111 //指令头,每一条指令都规定为"0x81, command1,command2,Fcolor,Bcolor"
112 command_head(unsigned char command1,unsigned char command2)
113 {
114 1 TI=0;
115 1 SBUF= 0x81;
116 1 check_uart();
117 1 SBUF= command1;
C51 COMPILER V7.20 VTERMINAL_UART_WAVE 07/29/2006 16:03:59 PAGE 3
118 1 check_uart();
119 1 SBUF= command2;
120 1 check_uart();
121 1
122 1 SBUF= Fcolor;
123 1 check_uart();
124 1 SBUF= Bcolor;
125 1 check_uart();
126 1 }
127 //指令头+x0+y0
128 command_head2(uchar command1,uchar command2,unsigned short x0,unsigned short y0)
129 {
130 1 command_head(command1,command2);
131 1
132 1 SBUF= x0/100;
133 1 check_uart();
134 1 SBUF= x0%100;
135 1 check_uart();
136 1 SBUF= y0/100;
137 1 check_uart();
138 1 SBUF= y0%100;
139 1 check_uart();
140 1 }
141
142 //清屏子程序
143 Lcd_Clr()
144 {
145 1 command_head(0x43,0x4c);
146 1 SBUF= 0x84;
147 1 check_uart();
148 1 }
149
150 //显示波形子程序。
151 //显示波形的原理是:x轴从坐标原点开始自动加一,y轴(幅度)是*p_data。
152 //x0, y0是坐标原点。
153 //con=1 y轴(幅度)的大小用一个字节表示。con = 2:y轴(幅度)的大小用二个字节表示
154 dis_wave(unsigned short x0,unsigned short y0,uchar con,unsigned short *p_data)
155 {
156 1 command_head2(0x53,0x53,x0,y0);
157 1 SBUF= con;
158 1 check_uart();
159 1 switch(con)
160 1 {case 1:
161 2 do
162 2 {
163 3 SBUF = (*p_data%100); //因为*p_data定义为short类型指针,所以这里要先取模运算再发送
164 3 check_uart();
165 3 p_data++;
166 3 }
167 2 while(*p_data !=0x84);
168 2 break;
169 2
170 2 case 2:
171 2 do
172 2 {
173 3 SBUF=(*p_data/100);
174 3 check_uart();
175 3 SBUF=(*p_data%100);
176 3 check_uart();
177 3 p_data++;
178 3 }
179 2 while(*p_data !=0xffff); //这里不能定义为Ox84,因为p_data[x]有可能是0x84
C51 COMPILER V7.20 VTERMINAL_UART_WAVE 07/29/2006 16:03:59 PAGE 4
180 2 break;
181 2
182 2 default: break;
183 2 }
184 1 SBUF=(0x84);
185 1 check_uart();
186 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 338 ----
CONSTANT SIZE = 440 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 16
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 + -