今天捣鼓了一下串口。
代码:
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <SI_EFM8BB1_Register_Enums.h>
#include "retargetserial.h"
#include "InitDevice.h"
//-----------------------------------------------------------------------------
// SiLabs_Startup() Routine
// ----------------------------------------------------------------------------
// This function is called immediately after reset, before the initialization
// code is run in SILABS_STARTUP.A51 (which runs before main() ). This is a
// useful place to disable the watchdog timer, which is enable by default
// and may trigger before main() in some instances.
//-----------------------------------------------------------------------------
void SiLabs_Startup (void)
{
// Disable the watchdog here
}
//-----------------------------------------------------------------------------
// Main Routine
//-----------------------------------------------------------------------------
void main (void)
{
unsigned char inputcharacter; // Used to store character from UART
enter_DefaultMode_from_RESET();
SCON0_TI = 1; // This STDIO library requires TI to
// be set for prints to occur
while (1)
{
RETARGET_PRINTF ("\nEnter character: ");
inputcharacter = getchar();
RETARGET_PRINTF ("\nCharacter entered: %c", inputcharacter);
RETARGET_PRINTF ("\n Value in Hex: %bx", inputcharacter);
}
}
效果图:
|