📄 serial.lst
字号:
C51 COMPILER V7.50 SERIAL 01/06/2006 00:20:27 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE SERIAL
OBJECT MODULE PLACED IN Serial.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE Serial.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "Serial.h"
2
3 #if CPU == MCS51
4 #include <reg52.h>
5 #endif
6
7 #if CPU == MSP430
#include <MSP430X44X.h>
#endif
10
11 #if CPU == MCS51
12 #define SETTI TI = 1
13 #endif
14
15 #if CPU == MSP430
#define SETTI IE1 |= UTXIE0
#endif
18
19 #if UartTXBufMAX == 8
#define UartTXBufTBL 0x07
#endif
22 #if UartTXBufMAX == 16
23 #define UartTXBufTBL 0x0f
24 #endif
25 #if UartTXBufMAX == 32
#define UartTXBufTBL 0x1f
#endif
28 #if UartTXBufMAX == 64
#define UartTXBufTBL 0x3f
#endif
31 #if UartTXBufMAX == 128
#define UartTXBufTBL 0x7f
#endif
34 #if UartRXBufMAX == 8
#define UartRXBufTBL 0x07
#endif
37 #if UartRXBufMAX == 16
38 #define UartRXBufTBL 0x0f
39 #endif
40 #if UartRXBufMAX == 32
#define UartRXBufTBL 0x1f
#endif
43 #if UartRXBufMAX == 64
#define UartRXBufTBL 0x3f
#endif
46 #if UartRXBufMAX == 128
#define UartRXBufTBL 0x7f
#endif
49
50 #if UartQueueEN == 1
51 unsigned char UartTXHead; //串口发送缓冲区头指针
52 unsigned char UartTXRear; //串口发送缓冲区尾指针
53 unsigned char UartTXCount; //串口发送缓冲区数据个数
54
55 unsigned char UartRXHead; //串口接收缓冲区头指针
C51 COMPILER V7.50 SERIAL 01/06/2006 00:20:27 PAGE 2
56 unsigned char UartRXRear; //串口接收缓冲区尾指针
57 unsigned char UartRXCount; //串口接收缓冲区数据个数
58
59 unsigned char UartTXBuf[ UartTXBufMAX ];//串口发送缓冲区
60 unsigned char UartRXBuf[ UartRXBufMAX ];//串口接收缓冲区
61
62 /*
63 _________________________________________________________________
64 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
65 -----------------------------------------------------------------
66 /\ /\
67 | |
68 front rear
69 */
70
71 //向队尾插入一个新元素ddata,并返回操作结果
72 //若操作成功则返回TRUE 否则返回FALSE
73
74
75 //unsigned char PutData(unsigned char ddata)
76 // if Count == MAXSIZE;
77 // return Queue full
78 // Buf[Rear]=ddata;
79 // Rear=(Rear+1)%MAXSIZE;
80 // Count++;
81 // return OK;
82 unsigned char PutUartTXData(unsigned char ddata)
83 {
84 1 if( UartTXCount == UartTXBufMAX )
85 1 return FALSE;
86 1 UartTXBuf[ UartTXRear ] = ddata;
87 1 UartTXRear = (UartTXRear + 1) & UartTXBufTBL;
88 1 UartTXCount++;
89 1 return TRUE;
90 1 }
91
92 unsigned char PutUartRXData(unsigned char ddata)
93 {
94 1 if( UartRXCount == UartRXBufMAX )
95 1 return FALSE;
96 1 UartRXBuf[ UartRXRear ] = ddata;
97 1 UartRXRear = (UartRXRear + 1) & UartRXBufTBL;
98 1 UartRXCount++;
99 1 return TRUE;
100 1 }
101
102 //从队首读取一个数据,并将数据存入ddate指向的单元
103
104 //unsigned char GetData(unsigned char *ddata)
105 // if count == 0;
106 // return Queue empty
107 // *ddata = Buf[Head];
108 // Head = (Head + 1) % MAXSIZE;
109 // Count--;
110 // return OK;
111 unsigned char GetUartTXData(unsigned char *ddata)
112 {
113 1 if( UartTXCount == 0 )
114 1 return FALSE;
115 1 *ddata = UartTXBuf[ UartTXHead ];
116 1 UartTXHead = ( UartTXHead +1 ) & UartTXBufTBL;
117 1 UartTXCount--;
C51 COMPILER V7.50 SERIAL 01/06/2006 00:20:27 PAGE 3
118 1 return TRUE;
119 1 }
120
121 unsigned char GetUartRXData(unsigned char *ddata)
122 {
123 1 if( UartRXCount == 0 )
124 1 return FALSE;
125 1 *ddata = UartRXBuf[ UartRXHead ];
126 1 UartRXHead = ( UartRXHead +1 ) & UartRXBufTBL;
127 1 UartRXCount--;
128 1 return TRUE;
129 1 }
130
131 //
132 //void UartRead( unsigned char *Buf , unsigned char len )
133 //从串口读取数据,读出的数据存放在首地址为 Buf 的数组里
134 //读出数据的长度为 len
135 void UartRead( unsigned char *Buf , unsigned char len )
136 {
137 1 unsigned char i,temp;
138 1 for( i = 0;i < len; i++)
139 1 {
140 2 while( !GetUartRXData(&temp));
141 2 Buf[i]=temp;
142 2 }
143 1 }
144
145
146 //void UartWrite( unsigned char *Buf , unsigned char len )
147 //向串口写入数据,
148 void UartWrite( unsigned char *Buf , unsigned char len )
149 {
150 1 unsigned char i,temp;
151 1 for( i = 0;i < len; i++)
152 1 {
153 2 temp=Buf[i];
154 2 while( !PutUartTXData(temp));
155 2 }
156 1 if(UartTXCount==len)
157 1 SETTI;
158 1 }
159
160 #if CPU == MCS51
161 #if CPU_TIMER == TIMER1
162 void UartInit(unsigned int BandRate)
163 {
164 1 TMOD&=0X0F;
165 1 TMOD|=0x20; /*定时器1作为波特率发生器,工作于方式2,自动8位装载*/
166 1 SCON=0x50; /*工作方式 1*/
167 1 PCON|=0x80; /*波特率加倍*/
168 1 TH1=255-57600/BandRate+1;; /*按波特率计算初值 TH1=256-F*(SMOD+1)/(384*Band)=256-57600/Band*/
169 1 TL1=TH1;
170 1 TR1=1;
171 1 TI=1;
172 1 RI=0;
173 1 //ES=1;
174 1 //队列初始化
175 1 UartTXHead = 0; //串口发送缓冲区头指针
176 1 UartTXRear = 0; //串口发送缓冲区尾指针
177 1 UartTXCount = 0; //串口发送缓冲区数据个数
178 1
179 1 UartRXHead = 0; //串口接收缓冲区头指针
C51 COMPILER V7.50 SERIAL 01/06/2006 00:20:27 PAGE 4
180 1 UartRXRear = 0; //串口接收缓冲区尾指针
181 1 UartRXCount = 0; //串口接收缓冲区数据个数
182 1 }
183 #endif
184
185 #if CPU_TIMER == TIMER2
void UartInit(unsigned int BandRate)
{
//队列初始化
UartTXHead = 0; //串口发送缓冲区头指针
UartTXRear = 0; //串口发送缓冲区尾指针
UartTXCount = 0; //串口发送缓冲区数据个数
UartRXHead = 0; //串口接收缓冲区头指针
UartRXRear = 0; //串口接收缓冲区尾指针
UartRXCount = 0; //串口接收缓冲区数据个数
}
#endif
200
201 void UartInterrupt(void) interrupt 4 //reentrant
202 {
203 1 unsigned char temp;
204 1 if(RI)
205 1 {
206 2 RI=0;
207 2 PutUartRXData(SBUF);
208 2 }
209 1 if(TI)
210 1 {
211 2 TI=0;
212 2 if(UartTXCount != 0)
213 2 {
214 3 GetUartTXData(&temp);
215 3 SBUF=temp;
216 3 }
217 2 }
218 1 }
219
220 #endif
221
222 #if CPU == MSP430
void UartInit(unsigned int BandRate)
{
//只允许输入标准波特率
unsigned int temp;
UTCTL0=SSEL1;
temp = CPU_OSC / BandRate;
UBR00 = temp % 256;//波特率寄存器 低八位
UBR10 = temp / 256;//高八位
UMCTL0 = 0x0;//微调寄存器
UCTL0 = CHAR;
ME1 |= UTXE0+URXE0;
IE1 |= URXIE0+UTXIE0;
P2SEL |= 0x30;//选择RXD TXD
P2DIR |= 0x10;//设置TXD的输出
P2DIR &= ~0x20;//设置RXD的输入
//队列初始化
C51 COMPILER V7.50 SERIAL 01/06/2006 00:20:27 PAGE 5
UartTXHead = 0; //串口发送缓冲区头指针
UartTXRear = 0; //串口发送缓冲区尾指针
UartTXCount = 0; //串口发送缓冲区数据个数
UartRXHead = 0; //串口接收缓冲区头指针
UartRXRear = 0; //串口接收缓冲区尾指针
UartRxCount = 0; //串口接收缓冲区数据个数
}
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx(void)
{
PutUartRXData(RXBUF0);
}
#pragma vector = UART0TX_VECTOR
__interrupt void usart0_tx(void)
{
GetUartTXData(&TXBUF0);
}
#endif
263 #endif // end of UartQueueEN
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 326 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 38 8
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 + -