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