資源簡介
AD7745/1D7746 c程序 已經調試成功,放心使用
代碼片段和文件信息
//?mcu?stc89c52
//?fsoc=11.0592M
///////////////////////////
#include
#include
#define?uchar?unsigned?char
#define?uint??unsigned?int
sfr?P1M1=0X91;
sfr?P1M0=0X90;
sbit?SCL=P1^0;
sbit?SDA=P1^1;
uchar?Ans=0;
uchar?Cap_Range=0;
//const?uchar?OffSet_Cap[2]={0xD20xF0};
const?uchar?OffSet_Cap[2]={0xD20xF0};
uchar??i_receiveTC35_RECE_MAX=10i_TC35_RECE=0;//COM_Flg=1;
uchar??TC35_RECE[10];
//////////////////////////////
void?Delay_1(int?i)
{?
???while(i--);
}
/////////////////////
/*void?delay(unsigned?char?ms)
{ //?延時子程序
unsigned?char?i;
while(ms--)
{
for(i?=?0;?i250;?i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
/***********************************************************?
函數名稱:Ini_UART?
函數功能:串口初始化設置????????入口參數:無?????????出口參數:無?
***********************************************************/?
void???uart_int(void)?
{?
?????//???AUXR???=???0x40;???//timer0?12T???ang????timer1?1T
????SCON???=???0x50;???//UART方式1:8位UART;???REN=1:允許接收?
????????PCON???=???0x00;???//SMOD=0:波特率不加倍?
????????TMOD???=???0x20;???//T1方式2用于UART波特率?
????????TH1????=???0xFD;?
????????TL1????=???0xFD;???//UART波特率設置:9600?
????????TR1????=???1;?
?? EA=1;
?? ES=1;
}?
/***********************************************************?
函數名稱??:delay
函數功能??:延時????入口參數:z????出口參數:無??
***********************************************************/?
/*void?delay_SMS(uint?z)
{
uint?xy;
for(x=z;x>0;x--)
??for(y=55;y>0;y--);
}
/***********************************************************?
函數名稱???:send
函數功能???:入口參數:tab???出口參數?:無?
***********************************************************/?
void?send(uchar?*tab)?
{?
????while((*tab)!=?‘\0‘)
????{?
????????????SBUF?=*tab;?
????????????while(TI?==0);?
????????????TI?=?0;?
????????????tab++;???
?????}?
}
/***********************************************************?
函數名稱???:receive?
函數功能???:入口參數:無??出口參數?:無?
***********************************************************/?
void?serial()?interrupt?4?using?3?
{?
????if?(RI)?
??????{??
?????????RI?=?0?;?
?????????i_receive=SBUF; ????????????
?????????if(i_TC35_RECE ???{
??TC35_RECE[i_TC35_RECE++]=i_receive;
???}
???????}
}?
/*******************************************************************************
**函數名稱:void?IIC_Stop()
**函數功能:結束IIC通信
//Precondition:?after?reading?or?sending?the?data?the?SCL?is?in?low?state
********************************************************************************/
?void?IIC_Start()
{?
??SDA=1;SCL=1;
??_nop_();
???Delay_1(5)?;
??SDA=0;????????????????//SDA?low?first
???_nop_();
????Delay_1(5)?;???????????
??SCL=0;????????????//set?SCL?low
???_nop_();
????Delay_1(5)?;
}
/*******************************************************************************
**函數名稱:void?IIC_Stop()
**函數功能:結束IIC通信
//Precondition:?after?reading?or?sending?the?data?the?SCL?is?in?low?state
****************
評論
共有 條評論