www.pudn.com > TG12864.rar > tlv5638.c, change:2002-09-08,size:1401b


#include               
#include                               
#include                
////////////////////////////////////////////////////////////////////////////////// 
#define uchar unsigned char 
#define uint  unsigned int 
#define ulong unsigned long 
 
sbit din  =  P0^0; 
sbit sclk =  P0^1; 
sbit ss   =  P0^2; 
//-------------------------------------------------------- 
void DelayNS(uchar Count) 
{  
   uchar  i,Timer_Count; 
   Timer_Count = Count; 
   for(;Timer_Count > 0;Timer_Count--) 
      for(i = 100;i > 0;i--) 
	     {;} 
} 
 
void wdac(uint dat,bit dot) 
{ 
//	bit temp1; 
	uchar count;		/* bit counter */ 
	uint  temp;	        /* temporarily store the data */ 
	sclk  = 1; 
	ss    = 1; 
// 	temp1 = dot; 
    temp  = dat; 
//	SS    = 0; 
	if(dot==1) 
	  { 
	   temp=temp|0xd000; 
	  } 
	else 
	  { 
	   temp=temp|0xc000; 
	  } 
	ss    = 0; 
//	DelayNS(2);  
	for (count=0; count<16; count++) 
	{         
	    sclk = 1; 
	    //if(temp&0x8000==0x8000) 
	    //  {din = 1;} 
	    //else 
	    //  {din = 0;} 
		temp= temp<<1; 
		din = CY; 
		 
		DelayNS(2); 
		sclk = 0; 
		DelayNS(2); 
        
     } 
	//DelayNS(1); 
	sclk= 1; 
	DelayNS(2); 
    ss   = 1; 
}  
 
void main() 
{ 
  uint i; 
 
  P0M1=0x00;P0M2=0x00; 
  //DelayNS(1); 
  wdac(0x0000,1); 
  while(1) 
     { 
      for(i=0;i<0x0fff;i++) 
	     {  
		  wdac(i,0) ; 
	     } 
	 } 
}