uart.c

来自「SDT环境下」· C语言 代码 · 共 69 行

C
69
字号
//******************************************************
//Chinese Academy of Sciences, Institute of Automation
//File Name:	main.c
//Description: 	
//Author:	JuGuang,Li
//Date:		2003-3-20
//******************************************************	

#include "s3c4510b_add.h"
void Delay(unsigned int);
void InitUART(int Port,int Baudrate);
void PrintUART(int Port,char *s);

int Main()
{
	unsigned long LED;
	InitUART(1,0x500);  //19200bps  50MHz 0=COM1;1=COM2
	PrintUART(1,"This is a Test!");
	IOPMOD=0xff;
	IOPDATA=0x01;
	Delay(10);
	for(;;){
		LED=IOPDATA;
		LED=(LED<<1);
		IOPDATA=LED;
		Delay(10);
		if(!(IOPDATA&0x07))
			IOPDATA=0x01;
		PrintUART(1,"This is a Test!");
		}
	return(0);	
}

void PrintUART(int Port,char *s)
{
	if(Port==0)
		for(;*s!='\0';s++)
			{for(;(!(USTAT0&0x40)););
			UTXBUF0=*s;}
	if(Port==1)
		for(;*s!='\0';s++)
			{for(;(!(USTAT1&0x40)););
			UTXBUF1=*s;}			
}


void InitUART(int Port,int Baudrate)
{
	if(Port==0)
		{ULCON0=0x03;
		UCON0=0x09;
		UBRDIV0=Baudrate;   
		}
	if(Port==1)
		{ULCON1=0x03;
		UCON1=0x09;
		UBRDIV1=Baudrate;   
		}

}


void Delay(unsigned int x)
{
	unsigned int i,j,k;
	for(i=0;i<=x;i++)
		for(j=0;j<0xff;j++)
			for(k=0;k<0xff;k++);
}

⌨️ 快捷键说明

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