📄 initializes.lst
字号:
C51 COMPILER V7.20 INITIALIZES 11/15/2005 18:46:53 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE INITIALIZES
OBJECT MODULE PLACED IN Initializes.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil Uvision V7.20\C51\BIN\C51.EXE Initializes.C BROWSE DEBUG OBJECTEXTEND SYMBOLS
line level source
1 //*************************************************************************************************
2 // Module Name : Initializes.C
3 // CreateDate : 2005-01-09
4 // ModifData : 2005-05-04
5 // Description : Initializes Program For C8051F022
6 // Author : 李远正
7 // Version : V1.0
8 //*************************************************************************************************
9
10 #include <C8051F020.H>
11 #include "Initializes.H"
12
13 //-------------------------------------------------------------------------------------------------
14 // Initialization Subroutines
15 //-------------------------------------------------------------------------------------------------
16
17 //=================================================================================================
18 // SYSCLK_Init
19 //=================================================================================================
20 //
21 // This routine initializes the system clock to use an 11.0592MHz crystal
22 // as its clock source.
23 //
24 void SYSCLK_Init( void )
25 {
26 1 int i; // delay counter
27 1
28 1 OSCXCN = 0x67; // start external oscillator with
29 1 // 11.0592MHz crystal
30 1
31 1 for (i=0; i < 256; i++) ; // wait for XTLVLD to stabilize
32 1
33 1 while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
34 1
35 1 OSCICN = 0x88; // select external oscillator as SYSCLK
36 1 // source and enable missing clock
37 1 // detector
38 1 }
39
40 //=================================================================================================
41 // PORT_Init
42 //=================================================================================================
43 //
44 // Configure the Crossbar and GPIO ports
45 //
46 void PORT_Init( void )
47 {
48 1 // Disable Watchdog timer
49 1 WDTCN = 0xDE;
50 1 WDTCN = 0xAD;
51 1
52 1 // Watchdog timer
53 1 // WDTCN = 0x07; // 设顶喂狗最大时间间隔为94.8mS
54 1 // WDTCN = 0xA5; // 允许看门狗工作;
55 1
C51 COMPILER V7.20 INITIALIZES 11/15/2005 18:46:53 PAGE 2
56 1 //-------------------------------------------------------------------------------------------------
57 1 // XRAM
58 1 // EMI0CN = 0x00; // ASM 编程时需要详解, EMI高8位地址值
59 1 EMI0CF = 0x2A; // EMIF在P4~P7,工作于复用方式,接口工作于模式3,ALE为 3 个SYSCLK
60 1 // EMIF工作于模式3,带块选择的分片方式,
61 1 // 0x0000~0x0fff为内部XRAM,0x1000~0xffff为外部XRAM
62 1 EMI0TC = 0xD7; // EAS:11 EMIF 地址建立时间: 3 个 SYSCLK 周期
63 1 // EWR:0101 /WR 和 /RD 脉冲宽度: 6 个 SYSCLK 周期
64 1 // EAH:11 EMIF 地址保存时间: 3 个 SYSCLK 周期
65 1
66 1 //-------------------------------------------------------------------------------------------------
67 1 // PORT Configure
68 1 XBR2 = 0x40; // 交叉开关允许
69 1
70 1 // PORT 0
71 1 XBR0 |= 0x04; // 打开 UART0 : P0.0---TX0, P0.1---RX0
72 1 XBR0 |= 0x02; // 打开 SPI口 : P0.2---SCK, P0.3---MISO, P0.4---MOSI, P0.5---NSS
73 1 XBR0 |= 0x01; // 打开 IIC口 : P0.6---SDA, P0.7---SCL (SMBus)
74 1
75 1 // PORT 1
76 1 XBR2 |= 0x04; // 打开 UART1 : P1.0---TXD1, P1.1---RXD1
77 1 XBR0 |= 0x28; // 打开 PCA : P1.2---CEX0, P1.3---CEX1, P1.4---CEX2, P1.5---CEX3, P1.6---CEX4
78 1 XBR1 |= 0x02; // 打开 T0 : P1.7---T0
79 1
80 1 // PORT 2
81 1 XBR1 |= 0x04; // 打开 INT0 : P2.0---INT0
82 1 XBR1 |= 0x08; // 打开 T1 : P2.1---T1
83 1 XBR1 |= 0x10; // 打开 INT1 : P2.2---INT1
84 1
85 1 //-------------------------------------------------------------------------------------------------
86 1 //
87 1 P74OUT |= 0x30; // P6 (A8--A15) 输出引脚
88 1
89 1 P0MDOUT|= 0x01; // 设置 TX0 为推挽输出(否则将强制为输入方式)
90 1 P1MDOUT|= 0x01; // 设置 TX1 为推挽输出(否则将强制为输入方式)
91 1
92 1 P4 &= 0xFE; // 485 Recieve
93 1 P4 &= 0xF7; // LED0 Disable
94 1 }
95
96 //=================================================================================================
97 // Function_Init
98 //=================================================================================================
99 //
100 void FUNCTION_Init(void)
101 {
102 1 //------------------------------------------------------------------------------------
103 1 // VOLTAGE REFERENCE
104 1 //------------------------------------------------------------------------------------
105 1 REF0CN = 0x07; // Temperature Sensor Enable, ADC/DAC Bias Generator Enable
106 1 // Voltage reference from VREF0 pin.
107 1 //
108 1 // Bit4: AD0VRS: ADC0 Voltage Reference Select
109 1 // 0: ADC0 voltage reference from VREF0 pin.
110 1 // 1: ADC0 voltage reference from DAC0 output.
111 1 //
112 1 // Bit3: AD1VRS: ADC1 Voltage Reference Select
113 1 // Bit2: TEMPE: Temperature Sensor Enable Bit.
114 1 // Bit1: BIASE: ADC/DAC Bias Generator Enable Bit. (Must be ‘1’ if using ADC or DAC).
115 1 // Bit0: REFBE: Internal Reference Buffer Enable Bit.
116 1 //
117 1
C51 COMPILER V7.20 INITIALIZES 11/15/2005 18:46:53 PAGE 3
118 1 //------------------------------------------------------------------------------------
119 1 // DAC0_Init
120 1 //------------------------------------------------------------------------------------
121 1 // Configure DAC0 to DAC output updates occur on a write to DAC0H.
122 1 //
123 1 //
124 1 DAC0CN = 0x80; // DAC0CN: DAC0 Enable, Output updates occur on a write to DAC0H.
125 1 //
126 1 // Bit 7: DAC0EN : DAC0 Enable Bit.
127 1 // Bits4-3: DAC0MD1-0: DAC0 Mode Bits.
128 1 // 00: DAC output updates occur on a write to DAC0H.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -