📄 main.lst
字号:
C51 COMPILER V6.23a MAIN 04/15/2002 18:18:04 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\keil\C51\BIN\c51.exe main.c DB OE
stmt level source
1 #include "TestSerial.h" // SFR declarations
2 #include "serial.h"
3 #include "serial1.h"
4 #include "SoftUart.h"
5 #define TIMER0 1000 //1000us
6 #define TIMER0_COUNT SYSCLK/1000*TIMER0/1000
7
8 #include <stdio.h>
9
10 sfr16 DP = 0x82; // data pointer
11 sfr16 TMR3RL = 0x92; // Timer3 reload value
12 sfr16 TMR3 = 0x94; // Timer3 counter
13 sfr16 ADC0 = 0xbe; // ADC0 data
14 sfr16 ADC0GT = 0xc4; // ADC0 greater than window
15 sfr16 ADC0LT = 0xc6; // ADC0 less than window
16 sfr16 RCAP2 = 0xca; // Timer2 capture/reload
17 sfr16 T2 = 0xcc; // Timer2
18 sfr16 RCAP4 = 0xe4; // Timer4 capture/reload
19 sfr16 T4 = 0xf4; // Timer4
20 sfr16 DAC0 = 0xd2; // DAC0 data
21 sfr16 DAC1 = 0xd5; // DAC1 data
22
23
24 #define SAMPLE_RATE 500 // Sample frequency in Hz
25 #define INT_DEC 256 // integrate and decimate ratio
26
27
28
29 void SYSCLK_Init (void);
30 void PORT_Init (void);
31 void ADC0_Init (void);
32 void Timer0_Init (int counts);
33 void Timer3_Init (int counts);
34
35 //-----------------------------------------------------------------------------
36 // Global VARIABLES
37 //-----------------------------------------------------------------------------
38
39 long result; // ADC0 decimated value
40
41 bit Flag1ms,Flag100ms,Flag1s,Flag10s;
42
43 extern bit FlagRecComm,FlagRecComm1;
44 extern bit FlagRecComm2,FlagRecComm3;
45
46 bit RecDataFlag,RecDataStart,EnableSendFlag;
47 bit SendGPSFlag,GPSDataValid,GPSWorkStatus;
48 bit SendTempFlag;
49 unsigned char TimerCount,TimerCount10;
50 unsigned char Count1ms,Count100ms,Count1s;
51
52 xdata unsigned char DataBuf1[255];
53 xdata unsigned char DataBuf2[255];
54
55 void SYSCLK_Init (void)
C51 COMPILER V6.23a MAIN 04/15/2002 18:18:04 PAGE 2
56 {
57 1 int i; // delay counter
58 1 OSCXCN = 0x67; // start external oscillator with
59 1 // 11.059MHz crystal
60 1 for (i=0; i < 256; i++) ; // XTLVLD blanking interval (>1ms)
61 1
62 1 while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
63 1 OSCICN = 0x88; // select external oscillator as SYSCLK
64 1 // source and enable missing clock
65 1 // detector
66 1 }
67 // Configure the Crossbar and GPIO ports
68 void PORT_Init (void)
69 {
70 1
71 1 XBR0 = 0x2C; // Enable UART0
72 1 XBR1 = 0x00;
73 1 XBR2 = 0x44; // Enable crossbar and weak pull-ups,Enable UART1
74 1 P0MDOUT |= 0x85; // enable TX0 TX1 as a push-pull output
75 1 P1MDOUT |= 0x02; //P1.1 output
76 1 P3MDOUT = 0x73;
77 1 }
78 void ADC0_Init (void)
79 {
80 1 ADC0CN = 0x05; // ADC0 disabled; normal tracking
81 1 // mode; ADC0 conversions are initiated
82 1 // on overflow of Timer3; ADC0 data is
83 1 // left-justified
84 1 REF0CN = 0x07; // enable temp sensor, on-chip VREF,
85 1 // and VREF output buffer
86 1 AMX0SL = 0x0f; // Select TEMP sens as ADC mux output
87 1 ADC0CF = (SYSCLK/2500000) << 3; // ADC conversion clock = 2.5MHz
88 1 ADC0CF |= 0x01; // PGA gain = 2
89 1
90 1 EIE2 |= 0x02; // enable ADC interrupts
91 1
92 1 DAC0CN = 0x80; // DAC0 Control Register
93 1 DAC0L = 0x00; // DAC0 Low Byte Register
94 1 DAC0H = 0x00; // DAC0 High Byte Register
95 1
96 1 DAC1CN = 0x80; // DAC1 Control Register
97 1 DAC1L = 0xFF; // DAC1 Low Byte Register
98 1 DAC1H = 0xFF; // DAC1 High Byte Register
99 1 }
100
101 void Timer3_Init (int counts)
102 {
103 1 TMR3CN = 0x02; // Stop Timer3; Clear TF3;
104 1 // use SYSCLK as timebase
105 1 TMR3RL = -counts; // Init reload values
106 1 TMR3 = 0xffff; // set to reload immediately
107 1 EIE2 &= ~0x01; // disable Timer3 interrupts
108 1 TMR3CN |= 0x04; // start Timer3
109 1 }
110
111 void Timer0_Init (int counts)
112 {
113 1 CKCON|=0x8;
114 1 TMOD|=0x1; //16Bit
115 1 TH0=(65536-counts)/256;
116 1 TL0=(65536-counts)%256;
117 1 IE|= 0x2;
C51 COMPILER V6.23a MAIN 04/15/2002 18:18:04 PAGE 3
118 1 TR0=1;
119 1 }
120
121 //-----------------------------------------------------------------------------
122 // Interrupt Service Routines
123 //-----------------------------------------------------------------------------
124
125 unsigned char Month,Date,Hour,Minute,second;
126
127 void Timer0_ISR (void) interrupt 1
128 {
129 1 TH0=(65536-TIMER0_COUNT)/256;
130 1 TL0=(65536-TIMER0_COUNT)%256;
131 1 Flag1ms=1;
132 1 if (Count1ms) Count1ms--;
133 1 TimerCount--;
134 1 if (!TimerCount)
135 1 {
136 2 TimerCount=100;
137 2 TimerCount10--;
138 2 Flag100ms=1;
139 2 if (Count100ms) Count100ms--;
140 2 if (!TimerCount10)
141 2 {
142 3 TimerCount10=10;
143 3 Flag1s=1;
144 3 if (Count1s) Count1s--;
145 3 second=(second+1)%60;
146 3 if (!second)
147 3 {
148 4 Minute=(Minute+1)%60;
149 4 if (!Minute)
150 4 {
151 5 Hour=(Hour+1)%24;
152 5 if (!Hour)
153 5 {
154 6 Date=(Date+1)%31;
155 6 if (!Date)
156 6 {
157 7 Month=(Month+1)%12;
158 7 }
159 6 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -