📄 i2c.c
字号:
#include"pic.h"
unsigned char jdate;
unsigned char code;
void i2cint(void)//iic设置
{
TRISC3=1;//input setting for iic work
TRISC4=1;// same as above
SSPCON=0X28;//iic setting word
STAT_SMP=1;//iic setting bit
SSPADD=0X05;//iic bit rate setting
GIE=0; //turn off the interrupt
SSPIF=0; //clear mssp flag bit
}
void tem_read()//读温度
{
STAT_CKE=1;
SEN=1; //start bit
while(SEN==1);
SSPBUF=0X9A;//address for writing
while(STAT_RW==1); //wait for sending finished
while(ACKSTAT==1);//wait for the slave acknowledge
SSPBUF=code; //send the control word
while(STAT_RW==1);//wait for finishing
while(ACKSTAT==1);//wait for the slave acknowledge
RSEN=1;
while(RSEN==1); //send the start bit again
SSPBUF=0X9B; // address for reading
while(STAT_RW==1);//wait for finishing
while(ACKSTAT==1);//wait for the slave acknowledge
RCEN=1; //receive enable
while(RCEN==1); //wait for getting all the receive date
jdate=SSPBUF; //
ACKDT=1; // the non-ack bit
ACKEN=1; // non-ack bit sending enable
while(ACKEN==1);//wair for finish
PEN=1;//send stop bit
while(PEN==1);//wait for finish
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -