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

📄 main.c

📁 mpc55**系列芯片的例程 包括SCI,SPI,TIMER,FIT,EDMA等几乎所有功能的实现
💻 C
字号:
/* main.c: Simple eSCI LIN program */
/* Rev 0.1 Oct 10, 2007 S.Mihalik- Initial version */
/* Rev 0.2 Jun 04 2008 SM - initSysclk changed for MPC5633M support */
/* Rev 0.3 Aug 16 2008 SM - changed baud rate to 10.417K */
/* Copyright Freescale, 2007. All Rights Reserved */
/* Notes: 1 MMU not initialized; must be done by debug scripts or BAM */
/*        2 SRAM not initialized; must be done by debug scripts or in a startup file*/

#include "mpc563m.h" /* Use proper include file such as mpc5510.h or mpc5554.h */

  const uint8_t FrameSpecAndData[] = {0x35,0x08,0xD0,'H','e','l','l','o',' ',' ',' '}; 

void initSysclk (void) {
/* MPC551x: Use the next 6 lines     */
/*  CRP.CLKSRC.B.XOSCEN = 1;         */ /* Enable external oscillator */
/*  FMPLL.ESYNCR2.R = 0x00000006;    */ /* Set ERFD to initial value of 6 */
/*  FMPLL.ESYNCR1.R = 0xF0000020;    */ /* Set CLKCFG=PLL, EPREDIV=0, EMFD=0x20*/
/*  while (FMPLL.SYNSR.B.LOCK != 1) {};*/ /* Wait for PLL to LOCK  */
/*  FMPLL.ESYNCR2.R = 0x00000005;    */ /* Set ERFD to final value for 64 MHz sysclk */
/*  SIU.SYSCLK.B.SYSCLKSEL = 2;      */ /* Select PLL for sysclk */
/* MPC563x: Use the next line        */
  FMPLL.ESYNCR1.B.CLKCFG = 0X7;       /* Change clk to PLL normal mode from crystal */  
/* MPC555x including MPC563x: use the next 3 lines   for either 8 or 40 MHz crystal */
  FMPLL.SYNCR.R = 0x16080000;         /* 8 MHz xtal: 0x16080000; 40MHz: 0x46100000 */
  while (FMPLL.SYNSR.B.LOCK != 1) {}; /* Wait for FMPLL to LOCK  */
  FMPLL.SYNCR.R = 0x16000000;         /* 8 MHz xtal: 0x16000000; 40MHz: 0x46080000 */
}

void initESCI_B (void) {
  ESCI_B.CR2.R = 0x6240;      /* Module is enabled, 13 bit break, stop on errors */
  ESCI_B.CR1.R = 0x0180000C;  /* 10417 baud, 8 bits, no parity, Tx & Rx enabled */
  ESCI_B.LCR.R = 0x01000000;  /* eSCI put in LIN mode */
/* Use the following two lines for MPC551x */
/*  SIU.PCR[56].R = 0x400;   */   /* Configure pad for primary func: TxDB */
/*  SIU.PCR[57].R = 0x400;   */   /* Configure pad for primary func: RxDB */
/* Use the following two lines for MPC555x */
  SIU.PCR[91].R = 0x400;      /* Configure pad for primary func: TxDB */
  SIU.PCR[92].R = 0x400;      /* Configure pad for primary func: RxDB */
}

void TransmitData (void) {
uint8_t	j;                                          /* Dummy variable */
  for (j=0; j< sizeof (FrameSpecAndData); j++) {    /* Loop for character string */
    while (ESCI_B.SR.B.TXRDY == 0) {}               /* Wait for LIN transmit ready = 1 */
    ESCI_B.SR.R = 0x00004000;                       /* Clear TXRDY flag */
	ESCI_B.LTR.R = FrameSpecAndData[j]  << 24;      /* Write byte to LIN Trans Reg. */
  }
}

void main(void) {
  initSysclk();       /* Set sysclk = 64MHz running from PLL */
  initESCI_B();       /* Enable Tx for 10417 baud, 8 bits, no parity */
  TransmitData();     /* Transmit string of characters on eSCI B */
  while (1) {}        /* Wait forever */
}

⌨️ 快捷键说明

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