📄 f236fullc.c
字号:
//---------------------------------------------------------------
// CYGNAL Integrated Products
//
// C Code Configuration Tool: F236 INITIALIZATION/CONFIGURATION CODE
//----------------------------------------------------------------
// This file is read only. To insert the code into your
// application, simply cut and paste or use the "Save As"
// command in the file menu to save the file in your project
// directory.
//----------------------------------------------------------------
//----------------------------------------------------------------
// INCLUDES
//----------------------------------------------------------------
#include <8051F200.h> // Register definition file.
//------------------------------------------------------------------------------------
// Global CONSTANTS
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Function PROTOTYPES
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Config Routine
//------------------------------------------------------------------------------------
void config (void) {
//Local Variable Definitions
//----------------------------------------------------------------
// 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
// Configure the PRTnMX Registers
PRT0MX = 0x00; // PRT0MX: Initial Reset Value
PRT1MX = 0x00; // PRT1MX: Initial Reset Value
PRT2MX = 0x00; // PRT2MX: Initial Reset Value
PRT3MX = 0x00; // PRT3MX: Initial Reset Value
// Select Pin I/0
// NOTE: Some peripheral I/O pins can function as either inputs or
// outputs, depending on the configuration of the peripheral. By default,
// the configuration utility will configure these I/O pins as push-pull
// outputs. If the I/O direction changes to input once the peripheral is
// configured, the peripheral hardware will override the PRTnCF register
// setting and change the pin configuration to input.
// Port configuration (1 = Push Pull Output)
PRT0CF = 0x00; // Output configuration for P0
PRT1CF = 0x00; // Output configuration for P1
PRT2CF = 0x00; // Output configuration for P2
PRT3CF = 0x00; // Output configuration for P3
// View port pinout
// The current MUX configuration results in the
// following port pinout assignment:
// Port 0
// P0.0 = GP I/O (Open-Drain Output/Input)
// P0.1 = GP I/O (Open-Drain Output/Input)
// P0.2 = GP I/O (Open-Drain Output/Input)
// P0.3 = GP I/O (Open-Drain Output/Input)
// P0.4 = GP I/O (Open-Drain Output/Input)
// P0.5 = GP I/O (Open-Drain Output/Input)
// P0.6 = GP I/O (Open-Drain Output/Input)
// P0.7 = GP I/O (Open-Drain Output/Input)
// Port 1
// P1.0 = GP I/O (Open-Drain Output/Input)
// P1.1 = GP I/O (Open-Drain Output/Input)
// P1.2 = GP I/O (Open-Drain Output/Input)
// P1.3 = GP I/O (Open-Drain Output/Input)
// P1.4 = GP I/O (Open-Drain Output/Input)
// P1.5 = GP I/O (Open-Drain Output/Input)
// P1.6 = GP I/O (Open-Drain Output/Input)
// P1.7 = GP I/O (Open-Drain Output/Input)
// Port 2
// P2.0 = GP I/O (Open-Drain Output/Input)
// P2.1 = GP I/O (Open-Drain Output/Input)
// P2.2 = GP I/O (Open-Drain Output/Input)
// P2.3 = GP I/O (Open-Drain Output/Input)
// P2.4 = GP I/O (Open-Drain Output/Input)
// P2.5 = GP I/O (Open-Drain Output/Input)
// P2.6 = GP I/O (Open-Drain Output/Input)
// P2.7 = GP I/O (Open-Drain Output/Input)
// Port 3
// P3.0 = GP I/O (Open-Drain Output/Input)
// P3.1 = GP I/O (Open-Drain Output/Input)
// P3.2 = GP I/O (Open-Drain Output/Input)
// P3.3 = GP I/O (Open-Drain Output/Input)
// P3.4 = GP I/O (Open-Drain Output/Input)
// P3.5 = GP I/O (Open-Drain Output/Input)
// P3.6 = GP I/O (Open-Drain Output/Input)
// P3.7 = GP I/O (Open-Drain Output/Input)
//----------------------------------------------------------------
// 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
//Comp1 marker
//----------------------------------------------------------------
// Oscillator Configuration
//----------------------------------------------------------------
OSCXCN = 0x30; // EXTERNAL Oscillator Control Register
OSCICN = 0x04; // Internal Oscillator Control Register
//----------------------------------------------------------------
// 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
//----------------------------------------------------------------
// UART Configuration
//----------------------------------------------------------------
SCON = 0x00; // Serial Port Control Register
PCON = 0x00; // Power Control Register
//----------------------------------------------------------------
// Timer Configuration
//----------------------------------------------------------------
CKCON = 0x00; // Clock Control Register
TH0 = 0x00; // Timer 0 High Byte
TL0 = 0x00; // Timer 0 Low Byte
TH1 = 0x00; // Timer 1 High Byte
TL1 = 0x00; // Timer 1 Low Byte
TMOD = 0x00; // Timer Mode Register
TCON = 0x00; // Timer Control Register
RCAP2H = 0x00; // Timer 2 Capture Register High Byte
RCAP2L = 0x00; // Timer 2 Capture Register Low Byte
TH2 = 0x00; // Timer 2 High Byte
TL2 = 0x00; // Timer 2 Low Byte
T2CON = 0x00; // Timer 2 Control Register
//----------------------------------------------------------------
// Reset Source Configuration
//
// Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0
//------------------------------------------------------------------
// | R | R/W | R/W | R | R | R/W | R
//------------------------------------------------------------------
//Reserved|NOT | Comp.0 | S/W | WDT | Miss. | POR | HW
// |USED | Reset/ | Reset | Reset | Clock | Force | Pin
// | | Enable | Force | Flag | Detect| & | Reset
// | | Flag | & | | Flag | Flag | Flag
// | | | Flag | | |
//------------------------------------------------------------------
// NOTE! : Comparator 0 must be enabled before it is enabled as a
// reset source.
//------------------------------------------------------------------
RSTSRC = 0x00; // Reset Source Register
//----------------------------------------------------------------
// Interrupt Configuration
//----------------------------------------------------------------
IE = 0x00; //Interrupt Enable
IP = 0x00; //Interrupt Priority
EIE1 = 0x00; //Extended Interrupt Enable 1
EIE2 = 0x00; //Extended Interrupt Enable 2
EIP1 = 0x00; //Extended Interrupt Priority 1
EIP2 = 0x00; //Extended Interrupt Priority 2
// other initialization code here...
} //End of config
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main (void) {
config();
while (1)
{
PCON |= 0x01; // set IDLE mode
}
} //End of Main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -