www.pudn.com > TCPmodbushy.rar > init.c


/****************************************************************************** 
 * Project     : DP-210 
 * Module Name : ETC.C 
 * CPU Type    : C8051F350 
 * 
 * Description : 
 * 
 * History        Author     Version       Comment 
 * 2002.12.22       HY       V0.0         Original version 
 * 
 * Copyright (C) 2002 ZJY. All rights reserved. 
 ******************************************************************************/ 
#include	"o:\sysdef.h" 
 
static void CloseWatchDog( void ); 
static void InitOscillate( void ); 
static void  InitExternOscillate(void); 
static void InitUart0Port( void ); 
static void InitNon_multiplexed( void ); 
static void InitPort( void ); 
static void InitINT0Port( void ); 
 
/******************************************************************** 
* Name:  
********************************************************************/ 
void InitCPU( void ) 
{ 
	InitOscillate(); 
	CloseWatchDog(); 
	InitPort(); 
	InitExternOscillate(); 
	InitTimer0(); 
} 
 
/******************************************************************** 
*  
*********************************************************************/ 
void InitLwip( void ) 
{ 
	/* Software */ 
	mem_init(); 
	memp_init(); 
	pbuf_init(); 
	/* allocate a space for a net */ 
#if LWIP_TCP 
	tcp_init(); 
#endif 
	/* before netif_Init TCP's variable mest be init( tcp_init() caller )  */ 
	netif_Init(); 
#if LWIP_UDP 
	Init_UDP_Conncet(); 
#endif 
	/* hardware */ 
	while( ethernetif_init() != ERR_OK ); 
} 
/******************************************************************** 
* Name: CloseWatchDog 
********************************************************************/ 
static void CloseWatchDog( void ) 
{ 
	PCA0MD = 0x00; 
} 
 
/******************************************************************** 
* Name: InitOscillate 
* Function: use internel oscill / 1 
********************************************************************/ 
static void InitOscillate( void ) 
{ 
	//OSCICN = 0x83; 
	OSCICN = 0xC3; 
	OSCICL = 0x00; 
} 
 
void  InitExternOscillate(void) 
{ 
int i; 
	/*use external*/ 
	OSCXCN = 0x67; 
 
	for( i=0; i<10000; i++ ) 
		i++; 
 
	while(!(OSCXCN & 0x80)); 
	CLKSEL = 0x01; 
//	OSCICN = 0x03; 
	 
} 
 
/********************************************************************** 
* Name: InitUart0Port 
* Note: Use P0.4&P0.5 
***********************************************************************/ 
static void InitUart0Port( void ) 
{ 
	/* set Uart's Out Port's out mode   */ 
	P0MDOUT = (P0MDOUT&0xCF) | 0x30;	 
	/* open Uart0 port */ 
	XBR0 = (XBR0&0xFE) | 0x01; 
} 
 
/********************************************************************** 
* Name: InitPort 
* Note: Use P2&P3&P4&P1.6&P1.7&P1.0( RST )&P0.3 
***********************************************************************/ 
static void InitNon_multiplexed( void ) 
{ 
	/* set Port Outmode as Open drain */ 
	P1MDOUT |= 0xc0; 
	P1MDOUT &= ~0x01;                   // RST Port is open-drain 
	P2MDOUT = 0xff; 
	P3MDOUT = 0xff; 
	P4MDOUT = 0xff; 
	P0MDIN = 0x3F; 
	/* set these port as not mutil port */ 
//	P0SKIP |= 0xc0; 
	P1SKIP |= 0xc0; 
	P2SKIP = 0xff; 
	P3SKIP = 0xff; 
	 
	/* Non-multiplexed Configuration */ 
	EMI0TC = 0x49; 
	EMI0CF = 0x14; 
 
	/* set port Parting Hight logical */ 
	P0 |= 0x30; 
	P2 = 0xff; 
	P3 = 0xff; 
	P4 = 0xff; 
} 
 
/****************************************************************************** 
* Name: InitPort 
******************************************************************************/ 
static void InitPort( void ) 
{ 
	InitUart0Port(); 
	InitNon_multiplexed(); 
	 
	/* Enable the Crossbar */ 
	XBR1 = (XBR1&0xBF)|0x40; 
	InitINT0Port(); 
} 
 
/****************************************************************************** 
* Name: InitINT0Port( use P0.3 as INT0 input ) 
******************************************************************************/ 
static void InitINT0Port( void ) 
{  
	IT01CF = ( IT01CF & 0xf0 ) | 0x03;  // Enable Interrupt 0 on P0.3 
	IT0 = 1;                            // Make /INT0 level triggered, EX0 = 1 as enbale key 
	EX0 = 1; 
} 
 
/***************************************************************************** 
function:initLED state 
*****************************************************************************/ 
void InitLED( void ) 
{ 
	COM_ERROR_LED = LED_OFF; 
	COM_LED = LED_OFF; 
}