c51f350.txt

来自「c51 对P2.0端口进行简单编程 通过P0.1端口的按键控制P2.0引脚电平的」· 文本 代码 · 共 74 行

TXT
74
字号
//-----------------------------------------------------------------------------
// 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引脚设为推挽方式.
  P0SKIP    = 0xCF;     //只保留串口,其余全部被交叉跳过.
  P2MDOUT   = 0x01;     //P2.0引脚设为推挽方式.

  XBR0     = 0x01;      //UART TX0,RX0连到端口引脚P0.4 和P0.5
  XBR1     = 0x40;      //交叉开关使能.
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?