⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pec.c

📁 英飞凌XC164CS系列单片机的源码
💻 C
字号:
/*--------------------------------------------------------- 
PECDEF reserves space for PEC channel 0 pointers.  Note
that this must be the first line of the program.
---------------------------------------------------------*/
#pragma PECDEF (0)

#include <reg167.h>
#include <intrins.h>
#include <stdio.h>
#include <string.h>

const char string1 [] = "0123456789\n";

/*--------------------------------------------------------- 
This function initializes PEC Channel 0 to move the data 
from STRING1 to the serial transmit buffer. 
---------------------------------------------------------*/
void serial_PEC0_setup (void)
{
PECC0 = 0x0500 | strlen (string1);     // Move Bytes, Inc Src Ptr
SRCP0 = _sof_ (string1);               // Source is STRING1
DSTP0 = (unsigned int) &S0TBUF;        // Destination is the serial output
}

/*--------------------------------------------------------- 
The Serial TX interrupt just resets PEC 0 and transfers 
another copy of STRING 1.
---------------------------------------------------------*/
void serial_TX_irq (void) interrupt S0TINT = 42
{
serial_PEC0_setup ();
}

/*--------------------------------------------------------- 
The setup routine for the serial port initializes the
PEC 0 transfer and sets a TX interrupt request.
---------------------------------------------------------*/
void serial_setup (unsigned int baud)
{
                                   // Setup the Baudrate
S0BG = (20000000UL / (32UL * (unsigned long) baud)) -1;

P3 |= 0x0400;                      // Set TXD high
DP3 |= 0x0400;                     // Set TXD for output
DP3 &= ~0x0800;                    // Set RXD for input

S0CON = 0x8011;
S0TIC = 0x00F8;                    // Serial TX IRQ = Level 14, Priority 0 (PEC 0)

serial_PEC0_setup ();
IEN = 1;                           // Enable interrupts
}

/*--------------------------------------------------------- 
Main C Function
---------------------------------------------------------*/
void main (void)
{
serial_setup (19200);

while (1) 
  {
  }
}

/*--------------------------------------------------------- 
---------------------------------------------------------*/

⌨️ 快捷键说明

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