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

📄 uhal.c

📁 44B0+8019系统
💻 C
字号:
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>


#include "uhal.h"
#include "..\inc\44b.h"

void Uart_SendByte(int data);

int Uart_printf(const char *fmt, ...)
{
    va_list ap;
    static char string[256];
	unsigned char *pStr = (unsigned char *)string;
    unsigned int i = 0;

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    va_end(ap);

	while( (*pStr) && i<256) {
		Uart_SendByte(*pStr);
		pStr++;	i++;
	}//while

	return 1;
}//uHALr_printf



//////////////////////////////////////////////////////////////////
//utilities 
//////////////////////////////////////////////////////////////////
void Delay(int time)
{
    int i;
    for( i = 0 ; i < time*5000 ; i++ );
}

void Uart_SendByte(int data)
{
		
	if(data=='\n')
    {
		while(!(rUTRSTAT0 & 0x2));
		Delay(10);	//because the slow response of hyper_terminal 
		WrUTXH0('\r');
	}//if
	while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
	Delay(10);
	WrUTXH0(data);
}//Uart_SendByte


void Uart_Init(int baud)
{
    int i,mclk = 66000000;

    rUFCON0=0x0;     //FIFO disable
    rUMCON0=0x0;
//UART0
    rULCON0=0x3;     //Normal,No parity,1 stop,8 bit
    rUCON0=0x5;    //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
    rUBRDIV0=( (int)(mclk/16/baud + 0.5) -1 );

    for(i=0;i<100;i++);
}

char Uart_Getch()
{
	while(!(rUTRSTAT0 & 0x1)); //Receive data read
	return rURXH0;
}

⌨️ 快捷键说明

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