📄 uart.lst
字号:
C51 COMPILER V8.08 UART 11/20/2012 17:41:44 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN uart.OBJ
COMPILER INVOKED BY: D:\Program Files\keil_51\C51\BIN\C51.EXE uart.c LARGE OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "NEW_8051.H"
2 #include "main.h"
3 //起始标志 0x5A 结束标志 0xA5 0x00 无反应
4 #define START 0X5A //起始位
5 #define END 0XA5 //结束位
6 sbit LED1=P2^5;
7 /*
8 0x5a+C+L+DATA+CS+0xA5
9 C 控制码
10 L 长度
11 DATA 数据
12 CS 较验和 C+L+DATA
13
14
15 和取模
16 接收成功返回1字节:0x06
17 */
18
19 bit uart_rBIT=0;
20 uchar ReceVeryfy=0;
21 uint uiAddressCount=0x200;
22 uchar ReceState=0;
23 uchar ucDataBuff[220];
24 uchar ReceCount=0;
25 bit bEanle=0;
26 uchar ucControlCode;
27 uchar ucLength;
28 void uart_init()
29 {
30 1 SCON = 0x50;
31 1 BRT= 0xf4; //0xfb: 30MHz,12T,SMOD=0,9600bps
32 1 AUXR |= 0x11; // 使用独立波特率发生器
33 1 ES=1;
34 1 PS = 1; //"串行中断优先"
35 1
36 1 PSH;
37 1 EA=1;
38 1 }
39 /*******************************************/
40 void MAIN_RS_INT(void) interrupt 4
41 {
42 1 uchar DataTemp;
43 1
44 1 //uart_rBIT=1;
45 1 if(RI) // 接收
46 1 {
47 2 RI = 0;
48 2 //ucUdateTime=200;
49 2 DataTemp = SBUF;
50 2 bEanle=1;
51 2 /************************************/
52 2 switch (ReceState)
53 2 {
54 3 case 0:
55 3 if(START == DataTemp)
C51 COMPILER V8.08 UART 11/20/2012 17:41:44 PAGE 2
56 3 {
57 4 ReceState = 1;
58 4 }
59 3 break;
60 3 case 1:
61 3 ucControlCode=DataTemp; //接收控制码
62 3 ReceVeryfy += ucControlCode;//开始计算校验和
63 3 ReceState = 2;
64 3 break;
65 3 case 2:
66 3 ucLength=DataTemp;
67 3 ReceVeryfy += ucLength;//计算校验和
68 3 ReceState = 3;
69 3 break;
70 3 case 3:
71 3 if(ReceCount<ucLength)
72 3 {
73 4 ReceVeryfy += DataTemp;
74 4 ucDataBuff[ReceCount]=DataTemp;
75 4 ReceCount++;
76 4
77 4 }
78 3 else
79 3 {
80 4 if(ReceVeryfy == DataTemp)
81 4 {
82 5
83 5 ReceVeryfy=0;
84 5 ReceCount=0;
85 5 ReceState=4;
86 5 //LED1=~LED1;
87 5 }
88 4 else
89 4 {
90 5 ReceState=0;
91 5 }
92 4 }
93 3 break;
94 3 case 4:
95 3 if(END == DataTemp)
96 3 {
97 4 uart_rBIT=1;
98 4 ReceState=0;
99 4 }
100 3 break;
101 3 default:
102 3 ReceState=0;
103 3 break;
104 3 }
105 2 /********************************************/
106 2 if( uart_rBIT )
107 2 {
108 3 uart_rBIT = 0;
109 3 switch (ucControlCode)
110 3 {
111 4 case 0x01://扇区擦除命令
112 4 for(i=1;i<=ucDataBuff[0];i++)
113 4 {
114 5 sector_erase(i*0x200);
115 5 }
116 4 Send_data(0x06);
117 4 break;
C51 COMPILER V8.08 UART 11/20/2012 17:41:44 PAGE 3
118 4 case 0x02://字幕数据命令
119 4
120 4 for(BuffCount=0;BuffCount<ucLength;BuffCount++)
121 4 {
122 5 byte_program(0x200+BuffCount+uiBaseAddress,ucDataBuff[BuffCount]);//把字幕数据写入EEP
123 5 }
124 4 uiBaseAddress=uiBaseAddress+ucLength;
125 4 if(ucLength<180)
126 4 {
127 5 uiFontNumber=uiBaseAddress;//字模的总数量
128 5 byte_program(0x100,uiFontNumber>>8);
129 5 byte_program(0x101,uiFontNumber);
130 5 uiBaseAddress=0;
131 5 bEanle=0;
132 5 }
133 4 //ucEEPArray=1;//EEP有字幕数据标志
134 4
135 4 Send_data(0x06);
136 4 break;
137 4 case 0x03://参数设置命令
138 4 sector_erase(0);
139 4 for(BuffCount=0;BuffCount<ucLength;BuffCount++)
140 4 {
141 5 byte_program(BuffCount,ucDataBuff[BuffCount]); //把设置的参数写入EEP
142 5 }
143 4 byte_program(0x100,uiFontNumber>>8);
144 4 byte_program(0x101,uiFontNumber);
145 4 ucSpeed=ucDataBuff[0]<<1; //移动速度
146 4 ucFontSize=ucDataBuff[1]<<4; //字体大小
147 4 ucFontColor=ucDataBuff[2]; //字体颜色
148 4 ucPlateNum=ucDataBuff[3]<<3; //级联块数(32*64一块)
149 4 ucShowMode=ucDataBuff[4];//显示模式
150 4
151 4 Send_data(0x06);
152 4 break;
153 4 case 0x04:
154 4 ES = 0;
155 4 //Send_data(uiBaseAddress>>8);
156 4 //Send_data(uiBaseAddress);
157 4 /*for( i=0;i<250;i++ )
158 4 {
159 4 SBUF = byte_read(0x200+i);
160 4 while( TI == 0 );
161 4 TI = 0;
162 4 }*/
163 4 ES = 1;
164 4 break;
165 4 default:
166 4 break;
167 4 }
168 3
169 3 }
170 2 }
171 1 /*****************************************/
172 1 /* if(TI)
173 1 {
174 1 TI = 0;
175 1 } */
176 1
177 1 }
C51 COMPILER V8.08 UART 11/20/2012 17:41:44 PAGE 4
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 760 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 228 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -