www.pudn.com > SCI_1.0.rar > Init_SCI_.h, change:2011-09-23,size:2007b


/*************** 
作者:xpj007 
时间:2011-4-12   
 
 
SCI模块的初始化 
****************/ 
typedef unsigned int uint; 
typedef unsigned char uchar; 
 
uchar tx0_data=0,rx0_data=0; 
uchar table[]="I Love You!"; 
uchar table2[]="xpj007 is good!"; 
uchar num[]="0123456789"; 
uchar ff[]={5,2,0,1,3,1,4}; 
uchar rx[10]=""; 
uchar transform_data[10]={0}; 
uint i,j=0; 
 
 
 
void init_SCI0() 
{ 
  SCI0CR1=0x00;//正常8位模式  无奇偶校验 
  SCI0CR2=0X2C;//使能SCI0发送接收,并且使能接收中断 
   
  //SCI0BDH=0; 
  //SCI0BDL=52;//8MHz设置波特率9600 
   
  //SCI0BDH=0; 
  //SCI0BDL=13;//8MHz设置波特率38400  
   
  SCI0BDH=0; 
  SCI0BDL=130;//80MHZ设置波特率38400 , 
   
  //SCI0BDH=0; 
  //SCI0BDL=43;//80MHZ设置波特率115200 
} 
 
void SCI0_set_byte(uchar byte_ch)//发送单个字符 
{ 
   while(!(SCI0SR1_TDRE)); 
   SCI0DRL=byte_ch; 
} 
void SCI0_TX_bytes(uchar *buf)//发送字符串 
{ 
  unsigned char *p; 
  p=buf; 
  while(*p) 
  { 
    SCI0_set_byte(*p); 
    p++;  
  } 
} 
 
 
void SCI0_TX_datas_sequence(uchar *buf,int n)//按‘顺序’发送数组中的数(以ASCII码发送) 
{ 
  unsigned char *p; 
  p=buf; 
  for(i=0;i<n;i++) 
  { 
    SCI0_set_byte(*p+'0'); 
    p++;  
  } 
} 
void SCI0_TX_datas_n_sequence(uchar *buf,int n)//按‘逆序’发送数组中的数(以ASCII码发送) 
{ 
  unsigned char *p; 
  p=buf; 
  for(i=n-1;i>0;i--) 
    p++;  
  for(i=n;i>0;i--) 
  { 
    SCI0_set_byte(*p+'0'); 
    p--;  
  } 
} 
void SCI0_set_return()//发送回车操作 
{ 
  SCI0_set_byte(13); 
  SCI0_set_byte(10);   
} 
 
void SCI0_TX_datas(uint data)//发送数组中的数(以ASCII码发送) 
{ 
  uchar data_c=0; 
  while(data) 
  { 
    transform_data[data_c]=data%10; 
    data/=10; 
    data_c++;   
  } 
  SCI0_TX_datas_n_sequence(transform_data,data_c); 
} 
 
   
 
#pragma CODE_SEG NON_BANKED 
void interrupt 20 SCI0() 
{ 
  if(SCI0SR1_RDRF==1)//检测接收到有效数据 
  { 
    SCI0SR1_RDRF=1; 
    rx0_data=SCI0DRL; 
     
    //rx[j]=rx0_data; 
    //j++; 
    //PORTB=~j; 
    PORTB=~rx0_data; 
    SCI0_set_byte(rx0_data); 
  } 
}