?? ckwl.lst
字號:
C51 COMPILER V7.06 CKWL 01/09/2008 15:27:20 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE CKWL
OBJECT MODULE PLACED IN ckwl.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ckwl.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1
2
3 //#include "stdarg.h"
4 #include <REG52.H>
5
6 #define Bit(i) (0x01<<i)
7 #define Motor P1
8
9 unsigned char code gDriveData[4]={0x03,0x06,0x0c,0x09};
10 unsigned char code bDriveData[4]={0x09,0x0c,0x06,0x03};
11 void mOtor(bit Way);
12 static bit tK;
13
14 #define MyAdd ('1')
15
16 sbit TX = P3^1;
17 sbit Light = P2^0;
18 static bit dRive,mDriv;
19 static unsigned char dRiveCnt;
20 void SerialInit()
21 {
22 1 TMOD |= 0x21;//選擇定時器T1模式2,計時方式,T1工作模式1
23 1 TH0 = 0xd8;
24 1 TL0 = 0xf0;
25 1 //TR0 = 1;
26 1 ET0 = 1;
27 1 TH1 = 0xf3;//波特率6M 2400
28 1 TL1 = 0xf3;
29 1 SCON = 0xf0;//串口工作方式3 SM2 = 1;接收的第9位數據必須為1,接收才有效
30 1 SM2 = 1;
31 1 PCON = 0x80;//SMOD=1
32 1 PS = 1;//設置串口中斷優先級
33 1 TR1 = 1;//啟動定時器T1
34 1 ES = 1;
35 1 EA = 1;
36 1 TX = 1;
37 1 }
38
39 //串口發送一個字節
40 void SerialSendData(const unsigned char Dat )
41 {
42 1 while(TI);
43 1 SBUF = Dat;
44 1 while(!TI);
45 1 TI = 0;
46 1 }
47
48 //串口接收一個字節
49 unsigned char SerialRecvData(const bit rEN)
50 {
51 1 unsigned char Temp;
52 1 REN = rEN;
53 1 while(!RI);
54 1 Temp = SBUF;
55 1 RI = 0;
C51 COMPILER V7.06 CKWL 01/09/2008 15:27:20 PAGE 2
56 1 return Temp;
57 1 }
58 //串口發送字符串
59 void SerialSendStr(unsigned char *ptr)
60 {
61 1 while(*ptr != '\0')
62 1 {
63 2 SerialSendData(*ptr);
64 2 ptr++;
65 2 }
66 1 }
67
68
69 void main(void)
70 {
71 1 SerialInit();
72 1 mDriv = 1;
73 1 while(1)
74 1 {
75 2 mOtor(tK);
76 2 }
77 1 }
78
79 void Note_Task(void)
80 {
81 1 switch(SerialRecvData(1))
82 1 {
83 2 case '4':Light = 0;//開LED
84 2 SerialSendStr("Light ON ");
85 2 break;
86 2 case '5':Light = 1;//關LED
87 2 SerialSendStr("Light OFF ");
88 2 break;
89 2 case 'a':dRive = 1;//電機正轉
90 2 TR0 = 1;
91 2 tK = 1;
92 2 SerialSendStr("Motor R ");
93 2 break;
94 2 case 'b':dRive = 1;//電機反轉
95 2 TR0 = 1;
96 2 tK = 0;
97 2 SerialSendStr("Motor L ");
98 2 break;
99 2 case 's':dRive = 0;//電機停止
100 2 TR0 = 0;
101 2 tK = 1;
102 2 SerialSendStr("Motor Stop ");
103 2 break;
104 2 default:break;
105 2 }
106 1 }
107
108 void Serial_ISR(void) interrupt 4 using 1
109 {
110 1 ES = 0;//關中斷
111 1 if(RI)//接收中斷
112 1 {
113 2 RI = 0;
114 2 if(SBUF == MyAdd)//地址匹配則返回從機名字
115 2 {
116 3 SM2 = 0;//退出監聽狀態
117 3 SerialSendStr("Slave-No.1: ");
C51 COMPILER V7.06 CKWL 01/09/2008 15:27:20 PAGE 3
118 3 Note_Task();
119 3 SM2 = 1;
120 3 }
121 2 else
122 2 { TX = 1;//鎖定TX腳
123 3 //SM2 = 1;//地址不匹配繼續監聽
124 3 }
125 2 }
126 1 if(TI)//發送中斷
127 1 {
128 2 TI = 0;
129 2 }
130 1 ES = 1;
131 1 }
132
133 void T0_ISR(void) interrupt 1 using 2
134 {
135 1
136 1 TH0 = 0xd8;
137 1 TL0 = 0xf0;
138 1
139 1 mDriv = 1;
140 1 if(++dRiveCnt == 4)
141 1 {
142 2 dRiveCnt = 0;//電機相位選擇
143 2 }
144 1
145 1 }
146
147 void mOtor(bit Way)
148 {
149 1 if(Way)
150 1 {
151 2 if(dRive && mDriv)//啟動命令dRive是否為1
152 2 {
153 3 mDriv = 0;
154 3 Motor = gDriveData[dRiveCnt];//電機正轉
155 3 }
156 2 if(!dRive)
157 2 {
158 3 Motor |= 0x00;//電機停止
159 3 }
160 2 }
161 1 else
162 1 {
163 2 if(dRive && mDriv)
164 2 {
165 3 mDriv = 0;
166 3 Motor = bDriveData[dRiveCnt];//電機反轉
167 3 }
168 2 if(!dRive)
169 2 {
170 3 Motor |= 0x00;//電機停止
171 3 }
172 2 }
173 1 }
174
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 307 ----
CONSTANT SIZE = 72 ----
C51 COMPILER V7.06 CKWL 01/09/2008 15:27:20 PAGE 4
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 ----
IDATA SIZE = ---- ----
BIT SIZE = 3 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -