📄 uart.lst
字号:
C51 COMPILER V7.20 UART 11/13/2004 14:51:06 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN UART.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE UART.C LARGE OPTIMIZE(6,SPEED) BROWSE ORDER NOINTPROMOTE DEBUG OBJECTEXTEND
line level source
1 #include <reg52.h>
2 #include <string.h>
3 #include <intrins.h>
4 //#include "init.h"
5 #include "uart.h"
6 #include "xsp.h"
7
8
9 static data unsigned int UartSend_rp, UartSend_wp;
10 static data unsigned int UartRecv_rp, UartRecv_wp;
11
12 unsigned char UartSendBuffer[UART_BUFFER_SIZE];
13 unsigned char UartRecvBuffer[UART_BUFFER_SIZE];
14
15 unsigned char GPRSRecvBuff[UART_RECV_SIZE];
16 unsigned char GPRSSendBuff[UART_RECV_SIZE];
17 unsigned char GPRSSaveBuff[UART_RECV_SIZE];
18
19 static data unsigned int GPRSRecvSize; // 接收缓冲区的当前位置
20 static data unsigned char GPRSDBusFlag;
21
22 //unsigned char UartData[UART_RECV_SIZE];
23
24 //void UART_init(void);
25 //void UARTSend(BYTE * Data,BYTE LenStr);
26
27
28 //***********************************************************************
29 //串行口初始化
30 void UART_init(void){
31 1 TMOD&=0x0f;
32 1 TMOD|=0x20; //定时器1工作在方式2(自动重装载)
33 1 SCON=0x50; //设定串行口工作方式为方式1;允许接收
34 1 PCON=0;
35 1 TH1=USART_BAND;
36 1 TR1=1;
37 1 ES=1;
38 1 UartSend_wp = UartSend_rp = 0;
39 1 UartRecv_wp = UartRecv_rp = 0;
40 1 }
41
42 //----------------------------------------------------------------------------------
43 //串行口发送数据
44
45 void UARTSend(unsigned char *a, unsigned char n)
46 {
47 1 // bit intTI;
48 1 // intTI=0;
49 1 while (n > 0) {
50 2 UartSendBuffer[UartSend_wp++] = *a++;
51 2 UartSend_wp &= UART_BUFFER_MASK;
52 2 n--;
53 2 }
54 1 // if (!intTI) {TI=1;intTI=1;}
55 1 TI=1;
C51 COMPILER V7.20 UART 11/13/2004 14:51:06 PAGE 2
56 1 }
57
58 unsigned char UARTReceive(unsigned char *a, unsigned char n)
59 {
60 1 unsigned char ReceiveCount = 0;
61 1
62 1 while (n > 0 && UartRecv_wp != UartRecv_rp) {
63 2 *a++ = UartRecvBuffer[UartRecv_wp++];
64 2 UartRecv_wp &= UART_BUFFER_MASK;
65 2 ReceiveCount++;
66 2 n--;
67 2 }
68 1 return ReceiveCount;
69 1 }
70
71 //-----------------------------------------------------------------------------------
72 //串行口数据发送与接收中断函数
73 void UartInt() interrupt 4 {
74 1 if (RI) {
75 2 RI=0;
76 2 UartRecvBuffer[UartRecv_rp++] = SBUF;
77 2 UartRecv_rp &= UART_BUFFER_MASK;
78 2 }
79 1 else{
80 2 TI=0;
81 2 if (UartSend_rp != UartSend_wp) {
82 3 SBUF = UartSendBuffer[UartSend_rp++];
83 3 UartSend_rp &= UART_BUFFER_MASK;
84 3 }
85 2 }
86 1 }
87
88
89
90 unsigned char GPRSRecvResponse(void)
91 {
92 1 data unsigned int UartReceivedBytes;
93 1 data unsigned int UartBuffPoint;
94 1 static data unsigned int GPRSDBusPos1;
95 1 static data unsigned int GPRSDBusPos2;
96 1 data unsigned int i;
97 1 data unsigned int j;
98 1 //idata unsigned char Result;
99 1 data unsigned char DataLength;
100 1 data unsigned char XorSum;
101 1
102 1 if ((UartReceivedBytes = UARTReceive(GPRSRecvBuff + GPRSRecvSize, UART_RECV_SIZE)) == 0)
103 1 return FALSE;
104 1
105 1 GPRSRecvSize += UartReceivedBytes;
106 1
107 1
108 1 for (i = 0; i < UartReceivedBytes; i++) {
109 2 UartBuffPoint = GPRSRecvSize - UartReceivedBytes + i + 1;
110 2 if (UartBuffPoint < 2) continue;
111 2 if (!GPRSDBusFlag) {
112 3 if (GPRSRecvBuff[UartBuffPoint - 1] == 0x55 &&
113 3 GPRSRecvBuff[UartBuffPoint - 2] == 0xaa) {
114 4 GPRSDBusFlag = TRUE;
115 4 GPRSDBusPos1 = UartBuffPoint - 2;
116 4 }
117 3 }
C51 COMPILER V7.20 UART 11/13/2004 14:51:06 PAGE 3
118 2 else{
119 3 if (UartBuffPoint > GPRSDBusPos1+3) DataLength = GPRSRecvBuff[GPRSDBusPos1+3];
120 3 if(UartBuffPoint >= GPRSDBusPos1+DataLength+5+1){
121 4 GPRSDBusFlag = FALSE;
122 4 GPRSDBusPos2 = UartBuffPoint - 1;
123 4 GPRSRecvSize -= UartBuffPoint;
124 4 XorSum = 0;
125 4 for (j = 0; j < DataLength + 5; j++) {
126 5 XorSum ^= GPRSRecvBuff[GPRSDBusPos1+j];
127 5 }
128 4 if (XorSum != GPRSRecvBuff[GPRSDBusPos1+DataLength + 5]) return FALSE;
129 4 memcpy(GPRSSaveBuff, GPRSRecvBuff + GPRSDBusPos1,GPRSDBusPos2 - GPRSDBusPos1 + 1);
130 4 return TRUE;
131 4 }
132 3 }
133 2 }
134 1 return FALSE;
135 1 }
136
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 659 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 4246 6
PDATA SIZE = ---- ----
DATA SIZE = 15 10
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 + -