?? com.lst
字號:
C51 COMPILER V7.08 COM 02/27/2006 16:50:28 PAGE 1
C51 COMPILER V7.08, COMPILATION OF MODULE COM
OBJECT MODULE PLACED IN .\output\com.obj
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE com.c BROWSE DEBUG OBJECTEXTEND OBJECT(.\output\com.obj)
line level source
1 #define _com_
2 #include "general.h"
3 #include "state.h"
4 #include "protocol.h"
5
6 #define INLEN 0x32 //40,固定幀長10 的倍數為宜
7 uchar idata r_buf[INLEN/*+0x0a*/]; //接收緩沖區
8 uchar *p_wrecibuf=r_buf; //接收時緩沖區寫入指針
9 uchar *p_rrecibuf=r_buf; //解析時緩沖區讀出指針
10
11 uchar cnt_reci;
12 //uchar idata t_buf[32];
13 uchar *pSTX,*pETX; //定位幀頭、幀尾指針
14 //uchar r_in,r_out,t_in,t_out; //FIFO
15 bit r_full,r_notempty; //標志:接收緩沖滿、緩沖不空
16 bit f_stx_ok=0; //
17 bit f_etx_ok=0;
18 //f_rxbit f_etx=0;
19
20 ///////////////////初始化///////////////////////////////////////////////////////
21 void init_com(void)
22 {
23 1 //Timer1
24 1 TMOD=0x20; /*定時器1工作方式2*/
25 1 TH1=0xfd; /*裝253,波特率=9600bit/s*@11.0592MHz*/
26 1 TCON=0x40; //啟動Timer1
27 1 //COM
28 1 //EA=0;
29 1 //TI=0;
30 1 SCON=0x50; //0101,串口工作方式1 SM2=0,REN=1,允許接收
31 1 //PCON=0x00;
32 1 //PS=1; //串口優先級
33 1 //buf
34 1 r_notempty=0;
35 1 r_full=0;
36 1 //r_out=t_in=t_out=0;
37 1 //r_in=1;
38 1 //IE
39 1 //ES=1;//開串口中斷
40 1 //EA=1;//開中斷
41 1 IE=0x90;
42 1 }
43 ////////////////////////發送部分(非中斷)//////////////////////////////////////////
44 void put_char(uchar ch){//發送一個字符,非中斷方式
45 1 SBUF=ch;
46 1 while(TI==0);
47 1 TI=0; //查詢硬件置位,發送完畢
48 1 }
50 void put_string(uchar *str,uchar strlen){//發送一個字符串,非中斷方式,strlen長度,注意本案中是從數組 高位
-開始送
51 1 uchar k=strlen;
52 1 do {
53 2 if(*(str+k-1)>=0&&*(str+k-1)<=9) put_char(*(str+k-1)+'0'); //數字碼
54 2 else put_char(*(str+k-1)); //非數字
C51 COMPILER V7.08 COM 02/27/2006 16:50:28 PAGE 2
55 2 k--;
56 2 } while(k>0);
57 1 }
58
59
60
61 /////////////////////////////////////////////////////////////////////////////////////////////////////////
62 /*
63 void loadmsg(uchar *msg){ // 將字符串裝入緩沖區子程序發
64 while((*msg!=0)&&((((t_in+1)^t_out)&0x1f)!=0)){ // 檢查緩沖區滿
65 t_buf[t_in]=*msg;
66 msg++;
67 t_in=++t_in&0x1f; // if t_in+1大于緩沖區0x1f,t_in=0
68 if (t_done){ // 啟動發送
69 TI=1;
70 t_empty=0;
71 t_done=0;
72
73 }
74 }
75 }
76 */
77 ///////////////////////////接收部分(中斷)///////////////////////////////////////
78 void serial_int() interrupt 4 using 1{
79 1
80 1 if (RI&~r_full){ // 接收并且接收緩沖區未滿 ,full就不再收了
81 2 //uchar ch;
82 2 //ch=SBUF;
83 2 RI=0;
84 2 //if(SBUF=FR_STX){
85 2 *p_wrecibuf=SBUF; // 接收數據寫入
86 2 r_notempty=1;
87 2
88 2 if(p_wrecibuf==(r_buf+INLEN-1)) p_wrecibuf=r_buf;//循環
89 2 else p_wrecibuf++;
90 2 //cnt_reci++;
91 2
92 2 if (p_wrecibuf==p_rrecibuf) r_full=1; // 置緩沖區滿標志
93 2 //if(*(p_wrecibuf-1)==FR_ETX) f_etx=1;
94 2 //}
95 2 }
96 1 /*else if (TI&&~t_empty){ // 發送并且發送緩沖區未空
97 1
98 1 SBUF=t_buf[t_out]; TI=0;
99 1 t_out=++t_out&0x1f; // t_out+1大于緩沖區,則t_out=0
100 1 if (t_out==t_in) t_empty=1; // 要發送的數據還未送入緩沖區數據,緩沖區空
101 1 }
102 1 else if (t_empty){ // 等待緩沖區裝入數據
103 1 TI=0;
104 1 t_done=1;
105 1 }*/
106 1 }
107
108
109 /*
110 void process(uchar ch)
111 {
112 return;
113 }
114 */
115 /*
116 void processmsg(void){
C51 COMPILER V7.08 COM 02/27/2006 16:50:28 PAGE 3
117 /* // 處理接收緩沖區字符子程序
118 while (((r_out+1)^r_in)!=0){ // 不空即可處理
119
120 if(r_buf[r_out+1]=='@'){ //定位幀頭
121 pSTX=&(r_buf[r_out+1]);
122 f_stx_ok=1; //幀定位開始,可以unwrap
123 }
124 if((r_buf[r_out+1]=='\n')&&(f_stx_ok=1)){ //定位幀尾
125 pETX=&(r_buf[r_out+1]);
126 f_stx_ok=0;
127 f_etx_ok=1; //幀定位好,可以應答(同時f_stx=1)
128 }
129
130 r_out=++r_out&0x1f; //取緩沖計數
131 }
132 */
133 /* uchar i;
134 i=*p_rrecibuf;
135
136 if(i==FR_STX){ //定位幀頭
137 pSTX=p_rrecibuf;
138 f_stx_ok=1;
139 }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -