?? c51f350.txt
字號:
//-----------------------------------------------------------------------------
// Main.c
//-----------------------------------------------------------------------------
// 程序說明:對P2.0端口進行簡單編程
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f350.h> // SFR declarations
//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
sbit LED20 = P2^0; // LED='1' means ON
sbit Pin01 = P0^1; // 端口P0.1
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void SYSCLK_Init();
void PORT_Init();
//-----------------------------------------------------------------------------
// MAIN Routine
//
// 通過P0.1端口的按鍵控制P2.0引腳電平的高低。
//
//-----------------------------------------------------------------------------
void main() {
// disable watchdog timer
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer)
// WDTE = 1 (enable)
SYSCLK_Init (); // Initialize system clock
PORT_Init (); // Initialize crossbar and GPIO
TEST:
if (Pin01 == 0) {
LED20 = 0; //=0, 點亮!
}
else {
LED20 = 1; //=1, 熄滅!
};
goto TEST;
} //End of main()
//-----------------------------------------------------------------------------
// SYSCLK_Init
// This routine initializes the system clock to use the internal 24.5MHz
// oscillator as its clock source. Also enables missing clock detector reset.
//-----------------------------------------------------------------------------
void SYSCLK_Init () {
OSCICN = 0x83; // configure internal oscillator 24.5MHz // its lowest frequency
RSTSRC = 0x04; // enable missing clock detector
}
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
void PORT_Init (void) { //使用LED顯示的配置.
P0MDOUT = 0x30; //P0.4, 0.5引腳設(shè)為推挽方式.
P0SKIP = 0xCF; //只保留串口,其余全部被交叉跳過.
P2MDOUT = 0x01; //P2.0引腳設(shè)為推挽方式.
XBR0 = 0x01; //UART TX0,RX0連到端口引腳P0.4 和P0.5
XBR1 = 0x40; //交叉開關(guān)使能.
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -