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

📄 uart.c

📁 用来计算不同oscillator下
💻 C
字号:
/*------------------------------------------------------------------------------
;  This file is part of the RLC instruction
;  Copyright (c)
;  Version: 1.0 
;-------------------------------------------------------------------------------
;  Filename:
;  main.c
;  Function:   
;
;  Author:
;  pirate
;     
;  Writedate:
;  Oct.15 2005
;  Moddate(latest):
;  Oct.15 2005
;-------------------------------------------------------------------------------
*/

//--------------------------------------
// Included files
//--------------------------------------
#include <reg52.h>
#include ".\HEAD\dtype.h"
#include ".\HEAD\externf.h"
#include ".\HEAD\sdefine.h"

//--------------------------------------
// Local Definitions and Types
//--------------------------------------



/*******************************************************************************
//*   
//*!  Function:    UART_init
//*!
//*!  Description: 
//*!               - initialize the UART communiction modle
//*!               
//*!  Inputs:      None
//*!
//*!  Returns:     None
//*
/*******************************************************************************
/*/
/*
void Uart_init(void)
{
    TMOD = 0x20;		//apply timer1 to generate baud rate
	SCON = 0x50;		//UART modle 1
	PCON = 0x00;		//single baud rate
	TH1 = 0xFD;		  	//baude rate = 9600bps @11.0592MHz
	TL1 = 0xFD;
}  */

/*******************************************************************************
//*   
//*!  Function:    CalBaudrate
//*!
//*!  Description: 
//*!               - by changing the value of TH1 & TL1 to find initiate value 
//*!               of timer2
//*!              
//*!  Inputs:      None
//*!
//*!  Returns:     None
//*
/*******************************************************************************
/*/
void CalBaudrate(uchar inival)
{
    T2CON = 0x30;	    //use timer2 to generate baudrate, and permitted it to receive data
    //TMOD = 0x20;		//apply timer1 to generate baud rate
	SCON = 0x50;
	//PCON = 0x00;		//double baud rate
	TH2 =  0xFF;	 	
	TL2 =  inival;
	RCAP2H = 0xFF;
	RCAP2L = inival;
	//TH1 = inival;
	//TL1 = inival;
}

/*******************************************************************************
//*   
//*!  Function:    UART_send char
//*!
//*!  Description: 
//*!               - A newdata can write into the SBUF of the UART, then it is 
//*!               transfered to a destination soon.
//*!
//*!  Inputs:      newdata
//*!
//*!  Returns:     none
//*
/*******************************************************************************
/*/
void UartSendChar(uchar dat)
{
    TI = 0;			    //clear Transmition symbol 
    SBUF = dat;
	for(;;)
	{
	  if(TI)
	  break;
	  else
	  ;
	}
	TI = 0;
}

/*******************************************************************************
//*   
//*!  Function:    UART_receive char
//*!
//*!  Description: 
//*!               - This function can receive a char using the SBUF of UART from 
//*!               RXD pin of AP180
//*!              
//*!  Inputs:      None
//*!
//*!  Returns:     newdata
//*
/*******************************************************************************
/*/
/*
uchar UartReceiveChar(void)
{
	uchar z;
	RI = 0;
	for(;;)
	{
		if(RI)
			break;
	}
	z = SBUF;
	RI = 0;
	return(z);
}

*/

⌨️ 快捷键说明

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