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

📄 f91eval.c

📁 ucos_ii 在Z80系列单片机上的移植
💻 C
字号:
/*******************************************************/
/*                                                     */
/* F91eval.c --  eZ80F91 evaluation platform           */
/*                                                     */
/*  Copyright (C) 2004, Douglas Beattie Jr.            */
/*                                                     */
/*  Author:  Douglas Beattie Jr.                       */
/*******************************************************/

#define _F91EVAL_COMPILE_
#include "F91eval.h"


//NOTE: many constant values are type-cast to (unsigned char)
//      because ZiLOG's "optimizing compiler" generates code
//      for integers if they're not casted -- we cut the code
//      size in half and triple execution speed by casting.

#define NUL (unsigned char)'\000'

/* -- bit definitions for tx/rx */ 
#define   UART_DR   (unsigned char)(0x01)
#define   UART_THRE (unsigned char)(0x20)
 

int puts(char *str)
{
     while (*str != NUL)
          putch(*str++);
     return 0;
}

int putch(int ch)
{
     //Puts a char to the UART transmit register, does idle wait until Tx is ready

     while ((UART_LSR(CONSOLE_UART) & UART_THRE)==(unsigned char)0)
          ;
     UART_THR(CONSOLE_UART) =ch;

     if ((unsigned char)ch == (unsigned char)'\n') {
          while ((UART_LSR(CONSOLE_UART) & UART_THRE)==(unsigned char)0)
               ;
          UART_THR(CONSOLE_UART) = '\r';
     }
     return(0);
}

int console_status(void)
{
     /* -- returns True (non-zero) if character waiting */
     return ((UART_LSR(CONSOLE_UART) & UART_DR) != (unsigned char)0);
}

int getch(void)
{
     /* -- Gets a character from UART port identified by its base addr ChannelBase, */
     /* -- does polled mode idle wait till a character is available. */

     while ((UART_LSR(CONSOLE_UART) & UART_DR) == (unsigned char)0)
          ;
     return(UART_RBR(CONSOLE_UART));
}


void set_console_ULCR (int BitsPerChar , int StopBits, int Parity ) 
{ 
     unsigned char ch ;
     ch = 0 ; 
     ch |= (unsigned char) ( ( BitsPerChar - 5 ) & 3 ) ; 
     ch |= (unsigned char) ( ( ( StopBits - 1 ) & 1 ) << 2 ) ; 
     ch |= (unsigned char) ( Parity & 3 ) ; 
     UART_LCTL(CONSOLE_UART) = ch ; 
} 


void init_console_UART ( void ) 
{ 
     unsigned int baud_divisor;

     /* -- Set the Port bits D1,D0 to Alternate function mode */
     Px_ALT2(CONSOLE_PORT) = 0x03;
     Px_DR(CONSOLE_PORT) = 0x10;  /* RS232 buffer/drivers disabled */
     Px_ALT1(CONSOLE_PORT) = 0x30;
     Px_DDR(CONSOLE_PORT) = 0x23;

     /* Init UART to selected baud, 8 bits, no parity, 2 stop bits. */
     baud_divisor = (unsigned int) ((CPU_FREQ / CONSOLE_BAUD_RATE) / 16);
 
     UART_LCTL(CONSOLE_UART) |= (unsigned char) 0x80 ;   /* Set DLAB, don't disturb other bits */
     BRG_DLR_L(CONSOLE_UART) = (unsigned char) baud_divisor;  /* Load divisor low */
     BRG_DLR_H(CONSOLE_UART) = (unsigned char) (baud_divisor >> 8); /* Load divisor high */
     UART_LCTL(CONSOLE_UART) &= (unsigned char) 0x7F;       /* Reset DLAB, dont disturb other bits */
     set_console_ULCR (8, 2, 0) ;
 
}

void select_console(void)
{
     //TBD //Px_DR(CONSOLE_PORT) = (0xCF & Px_DR(CONSOLE_PORT))  | 0x20;

}

void select_IrDA(void)
{
     //TBD //Px_DR(CONSOLE_PORT) = (0xCF & Px_DR(CONSOLE_PORT))  | 0x10;
}
 

⌨️ 快捷键说明

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