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

📄 main.c

📁 富士通90420系列F2MC-16LX的UART1驱动例程。
💻 C
字号:
/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
/* ELIGIBILITY FOR ANY PURPOSES.                                             */
/*                 (C) Fujitsu Microelectronics Europe GmbH                  */

/*---------------------------------------------------------------------------
  MAIN.C
  - description
  - See README.TXT for project description and disclaimer.

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

#include "mb90425.h"

/* Note:
   The -A and -B versions include a CPU Detection Reset Circuit. 
   This must be cleared periodically to prevent program reset.

   The conditions for clearing the counter of this circuit are given below:
   1. Writing 0 to CL bit of LVRC register
   2. Internal reset
   3. Stopping main oscillation clock
   4. Transition to sleep mode
   5. Transition to time-base timer mode or timer mode
   6. Starting hold
*/

void clear_CPU_operation_detection (void)
{
 LVRC = 0x35;	        /* clears CPU operation detection */
}

/*---------------------------------------------------------------------------
  UART-Procedures
/*---------------------------------------------------------------------------*/
void InitUart1(void)
{
  /* initialize UART1 e.g. mode, baud rate, stop bit, data length etc. */
	
  CDCR1 = 0x80;	   /* UART1 prescaler control register */
  SMR1  = 0x1B;	   /* serial mode register (mode 0, 9600Baud, SOE enable) */
  SCR1  = 0x13;    /* Serial control register */
}


void Putch (char ch)            /* sends a char */
{
  while (SSR1_TDRE == 0);       /* wait for transmit buffer empty */
  SODR1 = ch;                   /* put ch into buffer */
}


char Getch(void)	        /* waits for and returns incomming char	*/
{
  unsigned ch;

  while(SSR1_RDRF == 0)               /* wait for data received... */
    clear_CPU_operation_detection();  /* ... but clear CPU operation detection  */        
    
  if (SSR1_ORE)      	        /* overrun error */
  {
    ch = SIDR1;	                /* reset error flags */
    return (-1);
  }
  else
    return (SIDR1);	        /* return char */
}


void puts (const char *Name2)	/* Puts a String to UART */
{
  unsigned int i;
	
  for (i=0; i<strlen(Name2); i++)   /* go through string                     */
  {
    if (Name2[i] == 10)
      Putch(13);
    Putch(Name2[i]);              /* send it out                           */

    clear_CPU_operation_detection();  /* ... but clear CPU operation detection  */        
  }
}


/*---------------------------------------------------------------------------
  MAIN.C
/*---------------------------------------------------------------------------*/

void main(void)
{
  InitIrqLevels();
  __set_il(7);                /* allow all levels */
  __EI();                     /* globaly enable interrupts */

  InitUart1();

  puts("Welcome to FUJITSU\n");   /* Output welcome string */
  Putch(10);
  Putch(13);

  while(1)                    /* Echo received characters */
  {
    Putch(Getch());    	
  }

}

⌨️ 快捷键说明

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