第一次提交计算机温控
This commit is contained in:
261
UART1.C
Normal file
261
UART1.C
Normal file
@@ -0,0 +1,261 @@
|
||||
//****************************************************************************
|
||||
// @Module UART1 (Serial Interface)
|
||||
// @Filename UART1.C
|
||||
// @Project CL2.0.dav
|
||||
//----------------------------------------------------------------------------
|
||||
// @Controller Infineon XC886CLM-8FF
|
||||
//
|
||||
// @Compiler Keil
|
||||
//
|
||||
// @Codegenerator 1.3
|
||||
//
|
||||
// @Description: This file contains functions that use the UART1 module.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Date 2024/10/31 19:17:02
|
||||
//
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,1)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Project Includes
|
||||
//****************************************************************************
|
||||
|
||||
#include "MAIN.H"
|
||||
|
||||
// USER CODE BEGIN (UART1_General,2)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Macros
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,3)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Defines
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,4)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Typedefs
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,5)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Imported Global Variables
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,6)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Global Variables
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,7)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @External Prototypes
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,8)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Prototypes Of Local Functions
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_General,9)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Function void UART1_vInit(void)
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Description This is the initialization function of the UART1 function
|
||||
// library. It is assumed that the SFRs used by this library
|
||||
// are in their reset state.
|
||||
//
|
||||
// The following SFR fields will be initialized:
|
||||
// - register SCON
|
||||
// - bits SMOD and EX2
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Returnvalue None
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Parameters None
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Date 2024/10/31
|
||||
//
|
||||
//****************************************************************************
|
||||
|
||||
// USER CODE BEGIN (UART1_Init,1)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
void UART1_vInit(void)
|
||||
{
|
||||
// USER CODE BEGIN (UART1_Init,2)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
/// -----------------------------------------------------------------------
|
||||
/// UART1 settings
|
||||
/// -----------------------------------------------------------------------
|
||||
/// Pin TXD1_1 (P3.1) is selected for transmission
|
||||
/// Pin RXD1_1 (P3.2) is selected for reception
|
||||
/// Receiver enabled
|
||||
/// UART1 interrupt is enabled
|
||||
/// Ignore Normal divider overflow interrupt
|
||||
/// Mode 1: 8-bit data, 1 start bit, 1 stop bit, variable baud rate
|
||||
/// Receiver interrupt flag RI_1 will only be activated if a valid stop
|
||||
/// bit was received
|
||||
/// BRG is selected for baudrate generation
|
||||
|
||||
SFR_PAGE(_pp2, noSST); // switch to page 2 without saving
|
||||
P3_ALTSEL0 |= (ubyte)0x02; // configure alternate function register 0
|
||||
P3_ALTSEL1 |= (ubyte)0x02; // configure alternate function register 1
|
||||
SFR_PAGE(_pp0, noSST); // switch to page 0 without saving
|
||||
P3_DIR |= (ubyte)0x02; // set output direction
|
||||
|
||||
|
||||
SFR_PAGE(_su3, noSST); // switch to page 3 without saving
|
||||
MODPISEL1 |= (ubyte)0x08; // configure peripheral input select register
|
||||
SFR_PAGE(_su0, noSST); // switch to page 0 without saving
|
||||
|
||||
SET_RMAP();
|
||||
|
||||
UART1_BCON = 0x00; // reset baudrate timer/reload register
|
||||
UART1_SCON = 0x50; // load serial channel control register
|
||||
|
||||
/// -----------------------------------------------------------------------
|
||||
/// Baudrate generator settings
|
||||
/// -----------------------------------------------------------------------
|
||||
/// input clock = fPCLK
|
||||
/// Fractional divider is disabled
|
||||
/// baudrate = 9.6154 kbaud
|
||||
|
||||
UART1_BG = 0x9B; // load baudrate timer/reload register
|
||||
UART1_BCON |= 0x01; // load baud rate control register
|
||||
|
||||
|
||||
RESET_RMAP();
|
||||
|
||||
|
||||
// USER CODE BEGIN (UART1_Init,3)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
} // End of function UART1_vInit
|
||||
|
||||
|
||||
//****************************************************************************
|
||||
// @Function ubyte UART1_ubGetData8(void)
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Description This function returns the last received 8-bit data unit.
|
||||
// Interrupt flag RI_1 will be cleared.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Returnvalue received data unit
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Parameters None
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Date 2024/10/31
|
||||
//
|
||||
//****************************************************************************
|
||||
|
||||
ubyte UART1_ubGetData8(void)
|
||||
{
|
||||
|
||||
ubyte ubData;
|
||||
|
||||
_push_(SYSCON0); // push the current RMAP
|
||||
SET_RMAP();
|
||||
|
||||
// Clear the receiver interrupt flag
|
||||
UART1_SCON &= ~(ubyte)0x01;
|
||||
|
||||
|
||||
// Read the received data bits 0..7
|
||||
ubData = (ubyte)UART1_SBUF;
|
||||
|
||||
|
||||
_pop_(SYSCON0); // restore the old RMAP
|
||||
|
||||
// Return the received data byte
|
||||
return(ubData);
|
||||
|
||||
} // End of function UART1_ubGetData8
|
||||
//****************************************************************************
|
||||
// @Function void UART1_vSendData8(ubyte ubData)
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Description This function transmits an 8-bit data unit. At first
|
||||
// interrupt flag TI_1 is cleared, then buffer SBUF is written.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Returnvalue None
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Parameters ubData:
|
||||
// data to be transmitted
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// @Date 2024/10/31
|
||||
//
|
||||
//****************************************************************************
|
||||
|
||||
void UART1_vSendData8(ubyte ubData)
|
||||
{
|
||||
|
||||
_push_(SYSCON0); // push the current RMAP
|
||||
SET_RMAP();
|
||||
|
||||
// Clear the transmitter interrupt flag
|
||||
UART1_SCON &= ~(ubyte)0x02;
|
||||
|
||||
// Write the transmit data byte, this initiates the transmission.
|
||||
UART1_SBUF = ubData;
|
||||
|
||||
_pop_(SYSCON0); // restore the old RMAP
|
||||
|
||||
} // End of function UART1_vSendData8
|
||||
|
||||
|
||||
// USER CODE BEGIN (UART1_General,10)
|
||||
|
||||
// USER CODE END
|
||||
|
||||
Reference in New Issue
Block a user