pc_io_t1.c

来自「Embedded C 这本书的范例光碟程式」· C语言 代码 · 共 45 行

C
45
字号
/*------------------------------------------------------------------*-
   PC_IO_T1.C (v1.00)
   PC link library. Bidirectional. T1 used for baud rate generation.
   Uses the UART, and Pins 3.1 (Tx) and 3.0 (Rx) 
-*------------------------------------------------------------------*/

#include "Main.h"
#include "PC_IO_T1.h"
extern tByte In_read_index_G;     
extern tByte In_waiting_index_G;  
extern tByte Out_written_index_G;  
extern tByte Out_waiting_index_G;  

/*  This (generic) version uses T1 for baud rate generation. */

void PC_LINK_IO_Init_T1(const tWord BAUD_RATE)
{
   PCON &= 0x7F;   // Set SMOD bit to 0 (don't double baud rates)
   //  Receiver enabled.
   //  8-bit data, 1 start bit, 1 stop bit, 
   //  Variable baud rate (asynchronous)
   //  Receive flag will only be set if a valid stop bit is received
   //  Set TI (transmit buffer is empty)
   SCON = 0x72;
   TMOD |= 0x20;   // T1 in mode 2, 8-bit auto reload
   TH1 = (256 - (tByte)((((tLong)OSC_FREQ / 100) * 3125) 
            / ((tLong) BAUD_RATE * OSC_PER_INST * 1000)));
   TL1 = TH1;  
   TR1 = 1;  // Run the timer
   TI = 1;   // Send first character (dummy)

   // Set up the buffers for reading and writing
   In_read_index_G = 0;
   In_waiting_index_G = 0;
   Out_written_index_G = 0;
   Out_waiting_index_G = 0;
   // Interrupt *NOT* enabled
   ES = 0;
}





⌨️ 快捷键说明

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