📄 rs232.lst
字号:
C51 COMPILER V7.06 RS232 11/15/2007 09:02:21 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE RS232
OBJECT MODULE PLACED IN Rs232.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Rs232.c OPTIMIZE(2,SIZE) BROWSE NOAREGS DEBUG OBJECTEXTEND
stmt level source
1 /***************************************************************************
2 //Actpro International (SZ) Ltd
3 //Project :
4 //File :Rs232.c Compiler:Keil
5 //Editor: LIUYI
6 //Data: 25-12-26 Ver:可设置定时器T1、T2来产生波特率
7 //General Function
8 1、void rs232loop(); //串口数据循环处理函数
9 2、void Rs232Init(); //串口初始化
10 3、void rs232write(char watch_data);//串口发送接口
11 4、void rs232receive(); //中断接收
12 */
13
14 #include <switch.h>
15
16 #define rs_rece_buff_length 0x20
17 #define rs_send_buff_length 0x20
18
19 void rs232loop();
20 void Rs232Init();
21 void rs232write(UCHAR watch_data);
22 UCHAR ReadCCR(UCHAR item);
23 void WriteCCR(UCHAR item,UCHAR num);
24 UCHAR ReadCCS(UCHAR item);
25 void WriteCCS(UCHAR item,UCHAR num);
26 UCHAR ReadSYSTEM(UCHAR item);
27 void WriteSYSTEM(UCHAR item,UCHAR num);
28 void CCSInit();
29 void CCRInit();
30
31 xdata UCHAR rs_rece_buff_readptr _at_ 0x100;
32 xdata UCHAR rs_rece_buff_writerptr _at_ 0x101;
33 xdata UCHAR rs_rece_buff[rs_rece_buff_length] _at_ 0x120;
34
35 bit rs_send_wait_flag;
36 xdata UCHAR rs_send_buff_writeptr _at_ 0x102;
37 xdata UCHAR rs_send_buff_readptr _at_ 0x103;
38 xdata UCHAR rs_send_buff[rs_send_buff_length] _at_ 0x140;
39
40 #define CCS_step 8
41 #define CCS_type 7
42 #define CCS_command 6
43 #define CCS_data5 5
44 #define CCS_data4 4
45 #define CCS_data3 3
46 #define CCS_data2 2
47 #define CCS_data1 1
48 #define CCS_data0 0
49 xdata UCHAR CCS[9] _at_ 0x160; //发送控制命令数组
50
51 #define CCR_step 4
52 #define CCR_type 3
53 #define CCR_command 2
54 #define CCR_data1 1
55 #define CCR_data0 0
C51 COMPILER V7.06 RS232 11/15/2007 09:02:21 PAGE 2
56 xdata UCHAR CCR[5] _at_ 0x170; //接收控制命令数组
57
58 xdata UCHAR SYSTEM_PARAMETER[20] _at_ 0x180;
59
60 /*
61 xdata UCHAR test_step _at_ 0x104;
62 xdata UCHAR test_step2 _at_ 0x105;
63 xdata UCHAR test_step3 _at_ 0x106;
64 xdata UCHAR test_step4 _at_ 0x107;
65 xdata UCHAR test_temp _at_ 0x108;
66 xdata UCHAR test_temp2 _at_ 0x109;
67 xdata UCHAR test_temp3 _at_ 0x10A;
68 xdata UCHAR test_temp4 _at_ 0x10B;
69 xdata UCHAR test_step5 _at_ 0x10c;
70 xdata UCHAR test_temp5 _at_ 0x10d;
71 */
72 void Rs232Init()
73 {
74 1 idata UCHAR i;
75 1
76 1 SCON=SCON|0x50; //串口工作与方式一
77 1 PCON=PCON|0x80; //波特率倍频
78 1
79 1 #ifdef BoradRateUse_T2
80 1 //使用T2产生波特率
81 1 T2CON=0X30;
82 1 T2MOD=0;
83 1 RCAP2H=ProfitRate_T2>>8;
84 1 RCAP2L=ProfitRate_T2; //DE;
85 1 TR2=1; //启动波特率发生器
86 1
87 1 #else
//使用T1产生波特率
TMOD=TMOD|0x20; //T1为波特率发生器,工作于方式二
TH1=ProfitRate_T1; //12M晶振,2400B/S
TL1=ProfitRate_T1;
TR1=1; //启动T1
#endif
94 1
95 1 PORT_STORE=PORT;
96 1 RCON=RCON_Bank1;
97 1 rs_rece_buff_readptr=0;
98 1 rs_rece_buff_writerptr=0;
99 1 rs_send_wait_flag=0;
100 1 rs_send_buff_writeptr=0;
101 1 rs_send_buff_readptr=0;
102 1
103 1 for(i=0;i<rs_rece_buff_length;i++)
104 1 {rs_rece_buff[i]=0;}
105 1 for(i=0;i<rs_send_buff_length;i++)
106 1 {rs_send_buff[i]=0;}
107 1
108 1 PORT=PORT_STORE;
109 1
110 1 ES=1;
111 1 CCSInit();
112 1 CCRInit();
113 1 }
114
115 void rs232receive() interrupt 4
116 {
117 1 if(TI)
C51 COMPILER V7.06 RS232 11/15/2007 09:02:21 PAGE 3
118 1 {
119 2 TI=0;
120 2 rs_send_wait_flag=0;
121 2 }
122 1 if(RI)
123 1 {
124 2 RI=0;
125 2 PORT_STORE=PORT;
126 2 RCON=RCON_Bank1;
127 2 rs_rece_buff[rs_rece_buff_writerptr]=SBUF;
128 2 rs_rece_buff_writerptr++;
129 2 if(rs_rece_buff_writerptr>=rs_rece_buff_length){rs_rece_buff_writerptr=0;}
130 2
131 2 PORT=PORT_STORE;
132 2 }
133 1 }
134
135 void rs232loop()
136 {
137 1 idata UCHAR temp,i,j;
138 1 if(rs_send_buff_readptr!=rs_send_buff_writeptr)
139 1 {//发送处理
140 2 if(!rs_send_wait_flag)
141 2 {
142 3 PORT_STORE=PORT;
143 3 RCON=RCON_Bank1;
144 3
145 3 SBUF=rs_send_buff[rs_send_buff_readptr];
146 3 rs_send_wait_flag=1;
147 3
148 3 rs_send_buff_readptr++;
149 3 if(rs_send_buff_readptr>=rs_send_buff_length){rs_send_buff_readptr=0;}
150 3
151 3 PORT=PORT_STORE;
152 3 }
153 2 }
154 1
155 1 if(rs_rece_buff_readptr!=rs_rece_buff_writerptr)
156 1 {//接收数据处理
157 2 PORT_STORE=PORT;
158 2 RCON=RCON_Bank1;
159 2
160 2 temp=rs_rece_buff[rs_rece_buff_readptr];
161 2
162 2 rs_rece_buff_readptr++;
163 2 if(rs_rece_buff_readptr>=rs_rece_buff_length){rs_rece_buff_readptr=0;}
164 2
165 2 PORT=PORT_STORE;
166 2
167 2 //在此处添加接收数据处理函数****************
168 2 //rs232write(temp);
169 2 if(ReadCCR(CCR_step)==0)
170 2 {
171 3 if(temp==0xD0)
172 3 {//查询状态
173 4 if(ReadSYSTEM(sp_SystemState)==c_SS_none)
174 4 {//交换机空闲状态
175 5 rs232write(0x21);
176 5 WriteCCR(CCR_step,0);
177 5 return;
178 5 }
179 4 if(ReadSYSTEM(sp_SystemState)==c_SS_intoautosystem)
C51 COMPILER V7.06 RS232 11/15/2007 09:02:21 PAGE 4
180 4 {//进入智能控制系统 (动作)
181 5 rs232write(0x03);
182 5
183 5 WriteCCR(CCR_step,0);
184 5 return;
185 5 }
186 4 if(ReadSYSTEM(sp_SystemState)==c_SS_inautosystem)
187 4 {//处于智能控制系统
188 5 rs232write(0x04);
189 5 WriteCCR(CCR_step,0);
190 5 return;
191 5 }
192 4 }
193 3 if(temp==0xD1)
194 3 {//电话铃声
195 4 rs232write(temp);
196 4 WriteCCR(CCR_step,1);
197 4 return;
198 4 }
199 3 if(temp==0xd2)
200 3 {//退出智能家居
201 4
202 4 WriteCCR(CCR_step,0);
203 4 return;
204 4 }
205 3 if(temp==0xd3)
206 3 {//智能家居已准备好
207 4 if(ReadSYSTEM(sp_SystemState)==c_SS_intoautosystem)
208 4 {
209 5 WriteSYSTEM(sp_SystemState,c_SS_inautosystem); //系统由进入状态转变为处于智能系统控制状态
210 5 }
211 4 rs232write(0xff);
212 4 WriteCCR(CCR_step,0);
213 4 return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -