📄 receive.lst
字号:
C51 COMPILER V8.02 RECEIVE 08/23/2007 09:06:17 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE RECEIVE
OBJECT MODULE PLACED IN receive.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE receive.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include<c8051f020.h>
2
3 /*SET 16bit REGISTER*/
4 sfr16 TMR3 = 0x94;
5 sfr16 TMR3RL = 0x92;
6
7 #define EXT_OSCIL 1
8 #define INFRA_IN P3^7
9 #define T_3MS 0xf533
10 #define T_0_8MS 0xfd1f
11
12
13 void Port_IO_Init()
14 {
15 1 // P0.0 - TX0 (UART0), Open-Drain, Digital
16 1 // P0.1 - RX0 (UART0), Open-Drain, Digital
17 1 // P0.2 - SCK (SPI0), Open-Drain, Digital
18 1 // P0.3 - MISO (SPI0), Open-Drain, Digital
19 1 // P0.4 - MOSI (SPI0), Open-Drain, Digital
20 1 // P0.5 - NSS (SPI0), Open-Drain, Digital
21 1 // P0.6 - SDA (SMBus), Open-Drain, Digital
22 1 // P0.7 - SCL (SMBus), Open-Drain, Digital
23 1
24 1 // P1.0 - TX1 (UART1), Open-Drain, Digital
25 1 // P1.1 - RX1 (UART1), Open-Drain, Digital
26 1 // P1.2 - CEX0 (PCA), Open-Drain, Digital
27 1 // P1.3 - CEX1 (PCA), Open-Drain, Digital
28 1 // P1.4 - CEX2 (PCA), Open-Drain, Digital
29 1 // P1.5 - CEX3 (PCA), Open-Drain, Digital
30 1 // P1.6 - CEX4 (PCA), Open-Drain, Digital
31 1 // P1.7 - CP1 (Cmpr1), Open-Drain, Digital
32 1
33 1 // P2.0 - T0 (Timer0), Open-Drain, Digital
34 1 // P2.1 - INT0 (Tmr0), Open-Drain, Digital
35 1 // P2.2 - T2EX (Tmr2), Open-Drain, Digital
36 1 // P2.3 - Unassigned, Open-Drain, Digital
37 1 XBR0 = 0x2F;
38 1 XBR1 = 0x47;
39 1 XBR2 = 0x44;
40 1 }
41
42 void Reset_Sources_Init()
43 {
44 1 WDTCN = 0xDE;
45 1 WDTCN = 0xAD;
46 1 }
47
48 void Timer3_Init()
49 {
50 1 TMR3CN &=0xfb; //关定时器3
51 1 TMR3RL = T_3MS; //延时3ms
52 1 TMR3 = T_3MS;
53 1 }
54
55
C51 COMPILER V8.02 RECEIVE 08/23/2007 09:06:17 PAGE 2
56 void Oscillator_Init()
57 {
58 1 int i = 0;
59 1 OSCXCN = 0x77;
60 1 for (i = 0; i < 3000; i++); // Wait 1ms for initialization
61 1 while ((OSCXCN & 0x80) == 0);
62 1 OSCICN = 0x08;
63 1 }
64
65
66 void Init_Device(void)
67 {
68 1 Reset_Sources_Init();
69 1 Port_IO_Init();
70 1 Timer3_Init();
71 1
72 1
73 1 #if EXT_OSCIL
74 1 Oscillator_Init();
75 1 #endif
76 1 }
77
78 sbit P37=P3^7;
79 unsigned char val[8]=0,i=0,j=0,n=0;
80 bit h=0,new=0,head_ok=0,got=0;
81
82 void main()
83 {
84 1 unsigned char num;
85 1 Init_Device();
86 1 IE=0x80; //开总中断
87 1 EIE2|=0x21;//开中断7和定时器3中断
88 1 while(1)
89 1 {
90 2 while(!got);
91 2 if(val[2]+val[3]==0xff)
92 2 num=val[2];
93 2 got=0;
94 2 }
95 1 }
96
97
98 void ex_interrupt() interrupt 19 //下降沿中断,收到低电平开始
99 {
100 1
101 1 if(!new)
102 1 {
103 2 EIE2&=0xdf;//关中断7
104 2 P3IF&=0x7f;//清中断7的中断标志
105 2 Timer3_Init();//定时器3初始化
106 2 TMR3CN|=0x04; //开定时器3
107 2 }
108 1 else
109 1 {
110 2 while(P37==0&&TMR3CN<0x80); //等待变高
111 2 if(TMR3CN<0x80)
112 2 {
113 3 P3IF&=0x7f;//清中断7的中断标志
114 3 TMR3 = T_0_8MS;//延时0.8ms
115 3 TMR3CN|=0x04; //开定时器3
116 3 }
117 2 }
C51 COMPILER V8.02 RECEIVE 08/23/2007 09:06:17 PAGE 3
118 1 }
119
120 void T3_inter() interrupt 14
121 {
122 1 TMR3CN&=0x7f; //清中断标志
123 1
124 1 if(head_ok==0&&h==0&&P37==0) h=1;
125 1 else if(head_ok==0&&h==1&&P37==1)
126 1 {
127 2 EIE2|=0x20; //开中断7
128 2 TMR3CN&=0xfb; //关定时器3
129 2 new=1;h=0;head_ok=1;return;
130 2 }
131 1 else if(head_ok)
132 1 {
133 2 TMR3CN&=0xfb; //关定时器3
134 2
135 2 if(P37)
136 2 {
137 3 val[n]=val[n]>>1;
138 3 val[n]|=0x80;
139 3 }
140 2 else
141 2 val[n]=val[n]>>1;
142 2 n=++i/8;
143 2 if(n==4)
144 2 {
145 3 i=0;n=0;new=0; head_ok=0;
146 3 got=1;
147 3 }
148 2 }
149 1 else //还原为最原始状态
150 1 {
151 2 EIE2|=0x20;//开中断7
152 2 Timer3_Init();
153 2 h=0;new=0;
154 2 }
155 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 294 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 11 1
IDATA SIZE = ---- ----
BIT SIZE = 4 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -