📄 main.lst
字号:
C51 COMPILER V7.20 MAIN 10/15/2007 16:02:27 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN Main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Main.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*--------------------------------------------------------
2 DATE:
3 AUTHOR:
4 VERSION: V1.0
5 ---------------------------------------------------------*/
6 #include<reg52_r.h>
7 #include <intrins.h>
8
9 #define NOP _nop_( ); _nop_( ); _nop_( ); _nop_( )
10
11 #define uchar unsigned char
12 #define uint unsigned int
13 #define ulong unsigned long
14
15 #define SW_TEMP P33
16 #define C_POWER P37
17
18 #define TEST_PIN P34
19
20 #define P_TXD P31
21
22 #define INBUF_LEN 4 //数据长度
23
24 #define ID_H 0x80
25 #define ID_L 0x01
26
27
28 uchar code output_D[10]={0x30,0xF3,0x29,0x23,0xE2,0x26,0x24,0x73,0x20,0x22};
29
30 //uchar code cmd_long_key[1]={0xA3};
31 //uchar code cmd_shot_key[1]={0xA2};
32 //uchar code cmd_vshot_key[1]={0xA1};
33
34 uchar code cmd_long_key[7] ={0x02,0x05,ID_H,ID_L,0xA3,0x00,0x03}; //???????????
35 uchar code cmd_shot_key[7] ={0x02,0x05,ID_H,ID_L,0xA2,0x00,0x03}; //???????????
36 uchar code cmd_vshot_key[7]={0x02,0x05,ID_H,ID_L,0xA1,0x00,0x03}; //???????????
37
38 uchar idata i,k;
39 bit bdata f_working,f_100ms,f_40ms;
40 uchar idata work_mode;
41
42 uchar receive_buf[16],rcv_data[16];
43
44 uchar idata checksum,count3;
45 bit bdata read_flag=0;
46
47 uchar idata key_count,cmd_index;
48 bit bdata f_new_key,f_new_receive,f_new_data,f_receiving_0,f_0x10;
49
50 uchar idata chr;
51
52
53 ulong idata power_time;
54
55
C51 COMPILER V7.20 MAIN 10/15/2007 16:02:27 PAGE 2
56 uchar idata u_count;
57
58
59 uchar idata receive_time;
60
61 uchar idata dis_vol,dis_work_mode;
62 bit bdata f_dis_work_mode;
63
64 void delay(uint n)
65 {
66 1 uint i;
67 1 for(i=0;i<n;i++)
68 1 {NOP;
69 2
70 2 }
71 1
72 1 }
73
74
75 void timer0(void) interrupt 1
76 {
77 1 TH0=0x63; //T0 40MS
78 1 TL0=0xC1;
79 1
80 1 f_40ms=1;
81 1
82 1 if(receive_time)
83 1 receive_time--;
84 1
85 1 }
86
87 //向串口发送一个字符
88 void send_char_com(unsigned char ch)
89 {
90 1 SBUF=ch;
91 1 while(TI==0);
92 1 TI=0;
93 1 }
94
95 //向串口发送一个字符串,strlen为该字符串长度
96 void send_string_com(unsigned char *str,unsigned int strlen)
97 {
98 1
99 1 unsigned int k=0;
100 1 P_TXD=1;
101 1
102 1 delay(4000);
103 1
104 1 do
105 1 {
106 2 send_char_com(*(str + k));
107 2 k++;
108 2 } while(k < strlen);
109 1
110 1 P_TXD=0;
111 1 }
112
113
114 //串口接收中断函数
115 void serial () interrupt 4 using 3
116 { uint temp,i;
117 1 if(RI)
C51 COMPILER V7.20 MAIN 10/15/2007 16:02:27 PAGE 3
118 1 {
119 2 RI = 0;
120 2 temp = SBUF;
121 2 if((temp==0x02)&&(f_0x10==0))
122 2 { receive_buf[0]=0x02;
123 3 u_count=1;
124 3 f_receiving_0=1;
125 3 receive_time=60;
126 3 return;
127 3 }
128 2
129 2 if((temp==0x03)&&(f_0x10==0)&&(f_receiving_0==1))
130 2 { receive_buf[u_count]=0x03;
131 3 f_receiving_0=0;
132 3 f_new_receive=1;
133 3 u_count++;
134 3 for(i=0;i<u_count;i++)
135 3 {
136 4 rcv_data[i]=receive_buf[i];
137 4 }
138 3 u_count=0;
139 3 return;
140 3 }
141 2
142 2 if(((temp==0x10)||(temp==0x02)||(temp==0x03))&&(f_receiving_0==1)&&(f_0x10==1))
143 2 { receive_buf[u_count]=temp;
144 3 u_count++;
145 3 f_0x10=0;
146 3 return;
147 3 }
148 2
149 2 if((temp==0x10)&&(f_receiving_0==1)&&(f_0x10==0))
150 2 { f_0x10=1;
151 3 return;
152 3 }
153 2
154 2 if((f_receiving_0==1)&&(u_count<16))
155 2 { receive_buf[u_count++]=temp;
156 3 f_0x10=0;
157 3 }
158 2 else
159 2 if(u_count==16)
160 2 { u_count=0;
161 3 f_0x10=0;
162 3 f_receiving_0=0;
163 3 }
164 2 }
165 1
166 1 }
167
168 void init_timer0(void)
169 {
170 1 IP=0x00;
171 1 TMOD |=0x01; //T0 MODE 2,SOFT TIMER 0.5MS
172 1 TH0=0x63; //T0 40MS
173 1 TL0=0xC1;
174 1 TF0=0;
175 1 TR0=1;
176 1 ET0=1; //开T0中断
177 1 }
178
179 void init_serialcomm(void)
C51 COMPILER V7.20 MAIN 10/15/2007 16:02:27 PAGE 4
180 {
181 1 SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr
182 1 TMOD |= 0x20; //TMOD: timer 1, mode 2, 8-bit reload
183 1 PCON |= 0x80; //SMOD=1;
184 1 // TH1 = 0xD0; //Baud:2400 fosc=11.0592MHz
185 1 TH1 = 0xE0; //Baud:2400 fosc=11.0592MHz
186 1 IE |= 0x90; //Enable Serial Interrupt
187 1 TR1 = 1; // timer 1 run
188 1 // TI=1;
189 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -