📄 config.c
字号:
/******************************************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + MCU and audio configuration module *
* *** + + *** *
* *** +++ *** *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************************************
* *
*******************************************************************************************************
* Compiler: Keil C51 *
* Target platform: 8051F005 *
*******************************************************************************************************
* Revision history: *
* Initial release, HKI, 01.08.2004 *
******************************************************************************************************/
#pragma REGISTERBANK(0)
#include <Cinclude.h>
/******************************************************************************************************
* MCU Setup (generated by Cygnal Config) *
******************************************************************************************************/
void mcuConfig (void) {
UINT8 n = 0; //Crystal config wait loop
/***************************************** Watchdog Timer Configuration ******************************/
// WDTCN.[7:0]: WDT Control
// Writing 0xA5 enables and reloads the WDT.
// Writing 0xDE followed within 4 clocks by 0xAD disables the WDT
// Writing 0xFF locks out disable feature.
//
// WDTCN.[2:0]: WDT timer interval bits
// NOTE! When writing interval bits, bit 7 must be a 0.
//
// Bit 2 | Bit 1 | Bit 0
//------------------------
// 1 | 1 | 1 Timeout interval = 1048576 x Tsysclk
// 1 | 1 | 0 Timeout interval = 262144 x Tsysclk
// 1 | 0 | 1 Timeout interval = 65636 x Tsysclk
// 1 | 0 | 0 Timeout interval = 16384 x Tsysclk
// 0 | 1 | 1 Timeout interval = 4096 x Tsysclk
// 0 | 1 | 0 Timeout interval = 1024 x Tsysclk
// 0 | 0 | 1 Timeout interval = 256 x Tsysclk
// 0 | 0 | 0 Timeout interval = 64 x Tsysclk
//
//------------------------
WDTCN = 0x07; // Watchdog Timer Control Register
WDTCN = 0xDE; // Disable WDT
WDTCN = 0xAD;
WDTCN = 0xFF; // Disable WDT Lockout
/************************************ CROSSBAR REGISTER CONFIGURATION ********************************/
XBR0 = 0x03; // XBAR0: Initial Reset Value
XBR1 = 0x94; // XBAR1: Initial Reset Value
XBR2 = 0x40; // XBAR2: Initial Reset Value
// Port configuration (1 = Push Pull Output)
PRT0CF = 0x14; // Output configuration for P0
PRT1CF = 0x61; // Output configuration for P1
PRT2CF = 0xFF; // Output configuration for P2
if (!M_MASTER) { // Output configuration for P3
PRT3CF = 0x9F;
} else {
PRT3CF = 0x9E; // with CRC_OK: 0x8E, without 0x8F
}
// Port pinout description
// Port 0
// P0.0 = SMBus SDA
// P0.1 = SMBus SCL
// P0.2 = SPI Bus SCK
// P0.3 = SPI Bus MISO
// P0.4 = SPI Bus MOSI
// P0.5 = SPI Bus NSS
// P0.6 = /INT0
// P0.7 = /INT1
// Port 1
// P1.0 = M_SYSCLK
// P1.1 = A_LRCK
// P1.2 = A_BCLK/16
// P1.3 = FIFO
// P1.4 = PKT
// P1.5 = R_TX
// P1.6 = R_RX
// P1.7 = R_GIO1
// Port 2 (A_PDATA)
// P2.0 = GP I/O
// P2.1 = GP I/O
// P2.2 = GP I/O
// P2.3 = GP I/O
// P2.4 = GP I/O
// P2.5 = GP I/O
// P2.6 = GP I/O
// P2.7 = GP I/O
// Port 3
// P3.0 = R_GIO6
// P3.1 = /M_SPI_CS
// P3.2 = M_BLED
// P3.3 = A_OE4094
// P3.4 = /S_RST
// P3.5 = /M_MASTER
// P3.6 = M_BTN
// P3.7 = M_GLED
/********************************* Comparators Register Configuration *********************************/
// Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0
//------------------------------------------------------------------
// R/W | R | R/W | R/W | R/W | R/W | R/W | R/W
//------------------------------------------------------------------
// Enable | Output | Rising | Falling| Positive | Negative
// | State | Edge | Edge | Hysterisis | Hysterisis
// | Flag | Int. | Int. | 00: Disable | 00: Disable
// | | Flag | Flag | 01: 5mV | 01: 5mV
// | | | | 10: 10mV | 10: 10mV
// | | | | 11: 20mV | 11: 20mV
// ----------------------------------------------------------------
CPT0CN = 0x00; // Comparator 0 Control Register
CPT1CN = 0x00; // Comparator 1 Control Register
/***************************************** Oscillator Configuration ***********************************/
OSCXCN = 0x67; // EXTERNAL Oscillator Control Register
for (n = 0; n < 255; n++) ; // wait for osc to start
while ( (OSCXCN & 0x80) == 0 ); // wait for xtal to stabilize
OSCICN = 0x08; // Internal Oscillator Control Register - disable internal
/********************************* Reference Control Register Configuration ***************************/
REF0CN = 0x00; // Reference Control Register
/***************************************** SPI Configuration ******************************************/
SPI0CN = 0x00; // SPI Control Register
SPI0CFG = 0x00; // SPI Configuration Register
SPI0CKR = 0x00; // SPI Clock Rate Register
SPI0CN |= 0x01;
/***************************************** DAC Configuration ******************************************/
DAC0CN = 0x00; // DAC0 Control Register
DAC0L = 0x00; // DAC0 Low Byte Register
DAC0H = 0x00; // DAC0 High Byte Register
DAC1CN = 0x00; // DAC1 Control Register
DAC1L = 0x00; // DAC1 Low Byte Register
DAC1H = 0x00; // DAC1 High Byte Register
/***************************************** UART Configuration *****************************************/
SCON = 0x00; // Serial Port Control Register
PCON = 0x00; // Power Control Register
/***************************************** SMBus Configuration ****************************************/
SMB0CN = 0x40; // SMBus Control Register
SMB0ADR = 0x00; // SMBus Address Register
SMB0CR = 0x00; // SMBus Clock Rate Register
/***************************************** PCA Configuration ******************************************/
PCA0MD = 0x00; // PCA Mode Register
PCA0CN = 0x00; // PCA Control Register
PCA0H = 0x00; // PCA Counter/Timer High Byte
PCA0L = 0x00; // PCA Counter/Timer Low Byte
//Module 0
PCA0CPM0 = 0x00; // PCA Capture/Compare Register 0
PCA0CPL0 = 0x00; // PCA Counter/Timer Low Byte
PCA0CPH0 = 0x00; // PCA Counter/Timer High Byte
//Module 1
PCA0CPM1 = 0x00; // PCA Capture/Compare Register 1
PCA0CPL1 = 0x00; // PCA Counter/Timer Low Byte
PCA0CPH1 = 0x00; // PCA Counter/Timer High Byte
//Module 2
PCA0CPM2 = 0x00; // PCA Capture/Compare Register 2
PCA0CPL2 = 0x00; // PCA Counter/Timer Low Byte
PCA0CPH2 = 0x00; // PCA Counter/Timer High Byte
//Module 3
PCA0CPM3 = 0x00; // PCA Capture/Compare Register 3
PCA0CPL3 = 0x00; // PCA Counter/Timer Low Byte
PCA0CPH3 = 0x00; // PCA Counter/Timer High Byte
//Module 4
PCA0CPM4 = 0x00; // PCA Capture/Compare Register 4
PCA0CPL4 = 0x00; // PCA Counter/Timer Low Byte
PCA0CPH4 = 0x00; // PCA Counter/Timer High Byte
/***************************************** ADC Configuration ******************************************/
AMX0CF = 0x60; // AMUX Configuration Register
AMX0SL = 0x00; // AMUX Channel Select Register
ADC0CF = 0x00; // ADC Configuration Register
ADC0CN = 0x00; // ADC Control Register
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -