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

📄 44blib.c

📁 一个基于S3C44B0芯片的示例代码,实现利用定时器中断点亮LED指示灯,UART通信功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************************************
* File:		44blib.c
* Author:	embest
* Desc:		s3c44b0 function library 
* History:	
*********************************************************************************************/
#include <stdarg.h>
#include "44b.h"
#include "44blib.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include<stdio.h>
/*------------------------------------------------------------------------------------------*/
/*	 								constant define						 				    */
/*------------------------------------------------------------------------------------------*/
void (*run)(void) = (void (*)(void))0x0;
void uhal_init_interrupts(void)	;
void uhal_init_timers(void);
/*------------------------------------------------------------------------------------------*/
/*	 								global variable						 				    */
/*------------------------------------------------------------------------------------------*/
static int f_nDelayLoopCount = 400;
static int f_nWhichUart = 0;
int f_nDownloadAddr = 0x0C000000;

					//----------------------------------------------------------//
					//							SYSTEM							//
					//----------------------------------------------------------//
					
/*********************************************************************************************
* name:		delay
* func:		delay time
* para:		nTime -- input, nTime=0: nAdjust the delay function by WatchDog timer.
*						    nTime>0: the number of loop time, 100us resolution.
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void delay(int nTime)
{
	int nAdjust;
	int i;

	nAdjust = 0;

	if(nTime == 0)
	{
		nTime = 200;
		nAdjust = 1;
		f_nDelayLoopCount = 400;
		rWTCON = ((MCLK/1000000-1)<<8)|(2<<3);			// 1M/64, Watch-dog, nRESET, interrupt disable
		rWTDAT = 0xffff;
		rWTCNT = 0xffff;	 
		rWTCON = ((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); 	// 1M/64, Watch-dog enable, nRESET, interrupt disable
	}

	for(; nTime>0; nTime--)
	{
		for(i=0; i<f_nDelayLoopCount; i++)
			;
	}

	if(nAdjust==1)
	{
		rWTCON = ((MCLK/1000000-1)<<8)|(2<<3);
		i = 0xffff-rWTCNT;   							// 1count/16us?????????
		f_nDelayLoopCount = 8000000/(i*64);				// 400*100/(i*64/200)
	}
}


//----------------------------------------------------------//
//							PORTS							//
//----------------------------------------------------------//
					
/*********************************************************************************************
* name:		port_init
* func:		initialize io port for Embest teach kit ii
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void port_init(void)
{
	// CAUTION:Follow the configuration order for setting the ports. 
	// 1) setting value 
	// 2) setting control register 
	// 3) configure pull-up resistor.  

	//16bit data bus configuration  

	// PORT A GROUP
	// 	9	8	7	6	5	4	3	2	1	0
	// 	A24	A23	A22	A21	A20	A19	A18	A17	A16	A0
	//	0	1	1	1	1	1	1	1	1	1
	rPCONA = 0x1ff;	

	// PORT B GROUP
	// 	10		9		8		7		6		5		4		3		2		1		0
	//	/CS5	/CS4	/CS3	/CS2	/CS1	GPB5	GPB4	/SRAS	/SCAS	SCLK	SCKE
	//	EXT		NIC		USB		IDE		SMC		NC		NC		Sdram	Sdram	Sdram	Sdram
	//	?		?		?		?		?		Out		Out		?		?		?		?
	//  1 		1   	1   	1    	1    	0       0     	1    	1    	1   	1	
	rPCONB = 0x1cf;
	rPDATB = 0x7ff&~(1<<10);				
    
	// PORT C GROUP, BUSWIDTH=16
	//  15		14		13		12		11		10		9		8		7		6		5		4		3		2		1		0
	//	NC		NC		Uart1	Uart1	NC		NC		NC		NC		NC		NC		NC		NC		out		out		out		out
	//	?		?		?		?		?		?		?		?		?		?		?		?		*		*		*		*																													*						
	//	00		00		11		11		00		00		01		01		00		00		00		00		01		01		01		01
	rPDATC = 0xfc00;
	rPCONC = 0x0FF5FF55;	
//	rPCONC = 0x0ff0ff55;	// EduKit-II
//	rPCONC = 0x0ff0ffff;	// S3CEV40
	rPUPC  = 0x30ff;										// PULL UP RESISTOR should be enabled to I/O

	// PORT D GROUP
	// 	BIT7	6		5		4		3		2		1		0
	//	VF		OUT		VLINE	VCLK	VD3		VD2		VD1		VD0
	//	10		01		10		10		10		10		10		10
	rPDATD = 0xbf;
	rPCOND = 0x9aaa;	
	rPUPD  = 0x0;
	// These pins must be set only after CPU's internal LCD controller is enable
	
	// PORT E GROUP 
	// 	8		7		6		5		4		3			2		1		0
	// 	CODECLK	Out		Out		Out		TOUT1	Out(Beep)	RXD0	TXD0	?
	//  *		*		*		*				*			*		*
	// 	10		01		01		01		10		01			10		10		00
	rPDATE = 0x1ff;
	rPCONE = 0x25668;	
	rPUPE  = 0x6;
	
	// PORT F GROUP
	// 	8		7		6		5		 4		3		2		1		0
	// 	IISCLK	IISDI	IISDO	IISLRCK	Out		Out		Input	IICSDA	IICSCL
	//	*		*		*		*		*		*		*		*		*
	// 	100		100		100		100		01		01		00		10		10
	rPDATF = 0xe7;
	rPCONF = 0x24914A;										// PF3:LED4 PF4:LED3 PF2:nWait
//	rPCONF = 0x252A; //S3CEV40
	rPUPF  = 0x0;

	// PORT G GROUP
	// 	7		6		5		4		3		2		1		0
	// 	INT7	INT6	INT5	INT4	INT3	INT2	INT1	INT0
	//	S3		S4		S5		S6		NIC				IDE		USB
	//											*
	//	11      11      11      11      11      11      11      11
	rPDATG = 0xff;
	rPCONG = 0xffff;
	rPUPG  = 0x0;											// should be enabled  
	rSPUCR = 0x7;  											// D15-D0 pull-up disable

	// Non Cache area
	//rNCACHBE0 = ((NON_CACHE_END>>12)<<16) | (NON_CACHE_START>>12); 
	rNCACHBE0 = 0xc0002000;
	// Low level default
	rEXTINT = 0x0;
}

void beep(int BeepStatus)
{
	if (BeepStatus==0)
		rPDATE=rPDATE|0x8;
	else
		rPDATE=rPDATE&0x1f7;

}

					//----------------------------------------------------------//
					//							UART							//
					//----------------------------------------------------------//
					
/*********************************************************************************************
* name:		uart_init
* func:		initialize uart channel
* para:		nMainClk	-- 	input, 
*							nBaud, 
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_init(int nMainClk, int nBaud)
{
    int i;

    if(nMainClk==0)
		nMainClk=MCLK;

    rUFCON0=0x0;     								//FIFO disable
    rUFCON1=0x0;
    rUMCON0=0x0;
    rUMCON1=0x0;

	//UART0
    rULCON0	 = 0x3;     							// Normal, No parity, 1 stop, 8 bit
    rUCON0	 = 0x245;   	 						// rx=edge, tx=level, disable timeout int., enable rx error int., normal,interrupt or polling
    rUBRDIV0 = ((int)(nMainClk/16./nBaud + 0.5) -1);

	//UART1
    rULCON1  = 0x3;
    rUCON1   = 0x245;
    rUBRDIV1 = ((int)(nMainClk/16./nBaud + 0.5) -1);

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

/*********************************************************************************************
* name:		uart_change_baud
* func:		Change uart baud rate
* para:		nChannel	-- 	input, UART0 or UART1
*			nBaud		--	input, baud rate
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_change_baud(int nChannel, int nBaud)
{
    if (nChannel == UART0)
	    rUBRDIV0=( (int)(MCLK/16./nBaud + 0.5) -1 );
    
    if (nChannel == UART1)
	    rUBRDIV1=( (int)(MCLK/16./nBaud + 0.5) -1 );
}

/*********************************************************************************************
* name:		uart_select
* func:		change uart channel
* para:		nChannel	-- 	input, UART0 or UART1
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_select(int nChannel)
{
    f_nWhichUart=nChannel;
}

/*********************************************************************************************
* name:		uart_txempty
* func:		Empty uart channel
* para:		nChannel	-- 	input, UART0 or UART1
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_txempty(int nChannel)
{
    if(nChannel == 0)
		while(!(rUTRSTAT0 & 0x4)); 						// wait until tx shifter is empty.
    else
    	while(!(rUTRSTAT1 & 0x4)); 						// wait until tx shifter is empty.
}

/*********************************************************************************************
* name:		uart_getch
* func:		Get a character from the uart
* para:		none
* ret:		get a char from uart channel
* modify:
* comment:		
*********************************************************************************************/
char uart_getch(void)
{
    if(f_nWhichUart==0)
    {	    
		while(!(rUTRSTAT0 & 0x1)); 						// Receive data read
		return RdURXH0();
    }
    else
    {
		while(!(rUTRSTAT1 & 0x1)); 						// Receive data ready
		return	rURXH1;
    }
}

/*********************************************************************************************
* name:		uart_getkey
* func:		Get a character from the uart
* para:		none
* ret:		get a char from uart channel
* modify:
* comment:		
*********************************************************************************************/
char uart_getkey(void)
{
    if(f_nWhichUart==0)
    {	    
		if(rUTRSTAT0 & 0x1)    //Receive data ready
    	    return RdURXH0();
		else
		    return 0;
    }

⌨️ 快捷键说明

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