📄 rs232.lst
字号:
C51 COMPILER V8.05a RS232 10/15/2006 22:08:32 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE RS232
OBJECT MODULE PLACED IN RS232.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE RS232.C OMF2 BROWSE DEBUG
line level source
1 #include <config.h>
2
3
4 #define IN_UART
5
6 #define RECEBUFFER_COUNT 8
7 #define SENDBUFFER_COUNT 16
8
9 unsigned char idata rs232_recedata=0x00; //从接收缓冲中取得的数据
10
11 unsigned char idata rs232_recerece=0x00; // 发送位置的标志
12 unsigned char idata rs232_recesend=0x00; // 已经处理的位置标志
13 unsigned char idata rs232_recebytes=0x00; // 缓冲区还存在的字节数
14 #if XDATA_USING
unsigned char xdata rs232_recebuff[RECEBUFFER_COUNT];
#else
17 unsigned char idata rs232_recebuff[RECEBUFFER_COUNT];
18 #endif
19
20 unsigned char idata rs232_sendrece=0x00; // 发送位置的标志
21 unsigned char idata rs232_sendsend=0x00; // 已经处理的位置标志
22 unsigned char idata rs232_sendbytes=0x00; // 缓冲区还存在的字节数
23 #if XDATA_USING
unsigned char xdata rs232_sendbuff[SENDBUFFER_COUNT];
#else
26 unsigned char idata rs232_sendbuff[SENDBUFFER_COUNT];
27 #endif
28
29 void rs232_initialize(void)
30 { AUXR &=0x3f; //设定定时器0,1为普通的12时钟速度 T0x12=0,T1x12=0
31 1 SCON = 0x50;
32 1 PCON = 0x80;
33 1 TMOD &=0x0f;
34 1 TMOD |=0x20;
35 1
36 1 // TH1 = 0xf8; /* 11.0592MHz晶振, 38400bps */
37 1 // TL1 = 0xf8; /* 11.0592MHz晶振, 38400bps */
38 1
39 1 TH1 = 0xfe; /* 22.1184MHz晶振, 57600bps */
40 1 TL1 = 0xfe; /* 22.1184MHz晶振, 57600bps */
41 1 // TH1 = 0xfc; /* 22.1184MHz晶振, 57600bps */
42 1 // TL1 = 0xfc; /* 22.1184MHz晶振, 57600bps */
43 1 // TH1 = 0xfa; /* 22.1184MHz晶振, 38400bps */
44 1 // TL1 = 0xfa; /* 22.1184MHz晶振, 38400bps */
45 1 // TH1 = 0xf4; /* 22.1184MHz晶振, 19200bps */
46 1 // TL1 = 0xf4; /* 22.1184MHz晶振, 19200bps */
47 1 // TH1 = 0xe8; /* 22.1184MHz晶振, 9600bps */
48 1 // TL1 = 0xe8; /* 22.1184MHz晶振, 9600bps */
49 1
50 1
51 1 TF1 = 0X00; // 定时器1的溢出标志
52 1 TR1 = 0x01;
53 1 TI = 0x00;
54 1 RI = 0x00;
55 1 ET1 = 0x01; // 定时器1的中断使能
C51 COMPILER V8.05a RS232 10/15/2006 22:08:32 PAGE 2
56 1 ES = 0x01; // 开放串口
57 1 // PS = 0x01; // 将串口的优先级设定为最高
58 1 }
59
60
61
62 // rs232 sendbuffer 的自动处理和安排
63 void rs232_senddata(unsigned char ch)
64 {
65 1 #if RS232_USING
if(rs232_sendbytes==0x00) //如果缓冲区已经发送完毕,则要启动发送
{rs232_sendbytes++;
SBUF=ch;
}
else // 如果缓冲区还有其他数据等待发送
{if(rs232_sendrece>=SENDBUFFER_COUNT)
rs232_sendrece=0x00;
rs232_sendbuff[rs232_sendrece]=ch;
rs232_sendbytes++;
rs232_sendrece++;
}
#endif
78 1 }
*** WARNING C280 IN LINE 63 OF RS232.C: 'ch': unreferenced local variable
79 #if RS232_USING
#if RS232GET_USING
bit rs232_getdata(void)
{
bit returan_val=0x00;
if(rs232_recebytes==0x00)
returan_val=0; // 如果没有数据则反馈为空
else
{rs232_recedata=rs232_recebuff[rs232_recesend];
rs232_recesend++;
if(rs232_recesend>=RECEBUFFER_COUNT)
rs232_recesend=0x00;
if(rs232_recebytes>0x00)
rs232_recebytes--;
returan_val=0x01;
}
return returan_val;
}
#endif
#endif
101
102 // 串行的中断处理程序
103 void rs232r_isr(void) interrupt 4
104 {
105 1 #if RS232_USING
if(TI!=0x00)
{ TI = 0x00;
TB8 =0x00;
if(rs232_sendbytes>0x00) //本次发送完毕的处理
rs232_sendbytes--;
if(rs232_sendbytes>0x00) //如果还需要发送
{if(rs232_sendsend>=SENDBUFFER_COUNT)
rs232_sendsend=0x00;
SBUF=rs232_sendbuff[rs232_sendsend];
rs232_sendsend++;
}
C51 COMPILER V8.05a RS232 10/15/2006 22:08:32 PAGE 3
else //全部归位,以防止错误一直发生
{rs232_sendsend=0x00;
rs232_sendrece=0x00;
}
}
if(RI!=0x00)
{ RI = 0x00; //清除接收标志
RB8 =0x00;
if(rs232_recerece>=RECEBUFFER_COUNT)
rs232_recerece=0x00;
rs232_recebuff[rs232_recerece++] = SBUF;
rs232_recebytes++;
}
#else
131 1 TI = 0x00;
132 1 RI = 0x00; //清除接收标志
133 1 RB8 =0x00;
134 1 #endif
135 1 }
136
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 47 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 1
IDATA SIZE = 31 ----
BIT SIZE = ---- ----
EDATA SIZE = ---- ----
HDATA SIZE = ---- ----
XDATA CONST SIZE = ---- ----
FAR CONST SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -