uart1.h

来自「UART 8051 C」· C头文件 代码 · 共 84 行

H
84
字号
/////////////////////////////////////
//  Generated Initialization File  //
/////////////////////////////////////

#include "c8051F120.h"

// Peripheral specific initialization functions,
// Called from the Init_Device() function
//------------------------------------------------------------------------------------
// Timer1_Init
//------------------------------------------------------------------------------------
//
// Configure Timer1 to auto-reload and generate an interrupt at interval
// specified by <counts> using SYSCLK as its time base.
//
//
void Timer_Init ()
{
   char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page

   SFRPAGE   = TIMER01_PAGE;
   TCON      = 0x40;
   TMOD      = 0x20;
   CKCON     = 0x10;
   TH1       = 0xF3;
   
   SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
}

//------------------------------------------------------------------------------------
// PORT_Init
//------------------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports
//
void Port_Init (void)
{

   char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page   

    SFRPAGE   = CONFIG_PAGE;
    P1MDOUT   = 0x40;
    XBR2      = 0x44;

 
   SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
   
}
//------------------------------------------------------------------------------------
// UART1_Init
//------------------------------------------------------------------------------------
//
// Configure the UART1 using Timer1, for <baudrate> and 8-N-1.
//
void UART1_Init(void)
{
    char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page

	SFRPAGE   = UART1_PAGE;
    SCON1     = 0x50;					// UART1 enable & can read and write

    TI1 = 1;                            // Indicate TX1 ready
	RI1 = 0; 

    SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
}

void Interrupts_Init()
{
    IE        = 0x80;
    EIE2      = 0x40;
}

// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
    Timer_Init();
    UART1_Init();
    Port_Init();
    Interrupts_Init();

}

⌨️ 快捷键说明

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