www.pudn.com > C8051F020ANDads1255.rar > ADS1255.c, change:2007-11-14,size:4202b


///////////////////////////////////// 
//  Generated Initialization File  // 
///////////////////////////////////// 
 
#include "C8051F060.h" 
#include "model.h" 
unsigned char data FLAG_SAMPLE; 
unsigned char data COMOK,BUF; 
unsigned int data i; 
unsigned char data *combuf = 0x20; 
// Peripheral specific initialization functions, 
// Called from the Init_Device() function 
 
void EMI_Init() 
{ 
    SFRPAGE   = EMI0_PAGE; 
    EMI0CF    = 0x37;     // EMIF 在P4-P7。非复用方式 
                          // 带块选择的分片方式。寻址低于4K 边界的地址时访问片内存储器,寻址 
						  // 高于4K 边界的地址时访问片外存储器。8 位片外MOVX 操作使用EMI0CN 
                          // 的内容作为地址的高字节。 
                           //11:ALE 高和ALE 低脉冲宽度 = 4 个SYSCLK 周期。 
} 
 
void Port_IO_Init() 
{ 
    // P0.0  -  TX0 (UART0), Push-Pull,  Digital 
    // P0.1  -  RX0 (UART0), Open-Drain, Digital 
    // P0.2  -  SDA (SMBus), Open-Drain, Digital 
    // P0.3  -  SCL (SMBus), Open-Drain, Digital 
    // P0.4  -  TX1 (UART1), Open-Drain, Digital 
    // P0.5  -  RX1 (UART1), Open-Drain, Digital 
    // P0.6  -  Unassigned,  Open-Drain, Digital 
    // P0.7  -  Unassigned,  Open-Drain, Digital 
 
    // P1.0  -  Unassigned,  Open-Drain, Digital 
    // P1.1  -  Unassigned,  Open-Drain, Digital 
    // P1.2  -  Unassigned,  Open-Drain, Digital 
    // P1.3  -  Unassigned,  Open-Drain, Digital 
    // P1.4  -  Unassigned,  Open-Drain, Digital 
    // P1.5  -  Unassigned,  Open-Drain, Digital 
    // P1.6  -  Unassigned,  Open-Drain, Digital 
    // P1.7  -  Unassigned,  Open-Drain, Digital 
 
    // P2.0  -  Unassigned,  Open-Drain, Digital 
    // P2.1  -  Unassigned,  Open-Drain, Digital 
    // P2.2  -  Unassigned,  Open-Drain, Digital 
    // P2.3  -  Unassigned,  Open-Drain, Digital 
    // P2.4  -  Unassigned,  Open-Drain, Digital 
    // P2.5  -  Unassigned,  Open-Drain, Digital 
    // P2.6  -  Unassigned,  Open-Drain, Digital 
    // P2.7  -  Unassigned,  Open-Drain, Digital 
 
    // P3.0  -  Unassigned,  Open-Drain, Digital 
    // P3.1  -  Unassigned,  Open-Drain, Digital 
    // P3.2  -  Unassigned,  Open-Drain, Digital 
    // P3.3  -  Unassigned,  Open-Drain, Digital 
    // P3.4  -  Unassigned,  Open-Drain, Digital 
    // P3.5  -  Unassigned,  Open-Drain, Digital 
    // P3.6  -  Unassigned,  Open-Drain, Digital 
    // P3.7  -  Unassigned,  Open-Drain, Digital 
 
    SFRPAGE   = CONFIG_PAGE; 
    P0MDOUT   = 0x01; 
    XBR0      = 0x05; 
    XBR2      = 0x44; 
} 
 
 
void Reset_Sources_Init() 
{   EA=0; 
    WDTCN     = 0xDE; 
    WDTCN     = 0xAD; 
	EA=1; 
} 
 
void Oscillator_Init() 
{ 
    int i = 0; 
    SFRPAGE   = CONFIG_PAGE; 
    OSCXCN    = 0x67; 
    for (i = 0; i < 5000; i++);  // Wait 1ms for initialization 
    while ((OSCXCN & 0x80) == 0); 
    CLKSEL    = 0x01;  
	 
} 
 
void Interrupts_Init() 
{ 
    IE        = 0x90; 
     
} 
// Initialization function for device, 
// Call Init_Device() from your main program 
void Init_Device(void) 
{ 
 
    Oscillator_Init();  
	EMI_Init(); 
    Reset_Sources_Init(); 
	Port_IO_Init();	 
	Interrupts_Init(); 
    UART_Init();  
     
} 
 
void xiaozheng() 
{ 
     BUF=0xf1; 
	 WRADS1255C(); 
	 for(i=0;i<4000;i++){;} 
} 
 
 
void main() 
{ 
    unsigned char data cmd,cmd2; 
	WDTCN     = 0xDE; 
    WDTCN     = 0xAD;  
   
	SP=0x30; 
	Init_Device(); 
	INITADS(); 
   
    LOAD(); 
 
	while(1) 
	{ 
	 
	if(COMOK == 0x01) 
		{    
			ES0 = 0; 
			cmd = *(combuf+3);			 
			switch(cmd) 
			{ 
			case  0:  //采样 
				 
				PUCLEAR();  
				SAMPLE();			 
				TXDPUXIAN(); 
			    COMOK=0;  
				break; 
			case  1:   //谱线清0 
				PUCLEAR();  
				 
				break; 
			case  2:  //SFR设置 1个命令字 
				//WR1CMD(*(combuf+4)); 
				break; 
			case  3:   // write to command  port 
				cmd2 = *(combuf+4) & 0xf0; 
				cmd2 = cmd2 >> 4 ; 
 
				//WR2CMD(cmd2 | 0x50, *(combuf+4) & 0x0F); 
				break; 
			case  4:   //read from command port 
				cmd2 = *(combuf+4) & 0xf0; 
				cmd2 = cmd2 >> 4 ; 
				//WR2CMD(cmd2 | 0x10, *(combuf+4) & 0x0f); 
				break; 
			case  5: 
			    xiaozheng(); 
                COMOK=0;  
				break; 
			} 
 
			COMOK = 0x00; 
			ES0 = 1; 
		}	 
	} 
}