C8051F330 16*16點陣(SPI 、SMBus、I2C)PCF8563
/****************初始化檢測pcf8563****************/本文引用地址:http://m.butianyuan.cn/article/201611/324045.htm
pio_int();
TIME01_INT();
TIME2_INT();
TIME3_INT();
SPI_INT(); //SPI0DAT是SPI的數(shù)據(jù)寄存
SMB_INT();
spit_time();
EIE1|=0x01;
EA=1;
dat_int();
led=0;
TR0=0;
delay(1000);
write_pcf8563();
while(1)
{
TR0=0;
BUSY=0;
read_pcf8563();
spit_time();
TR0=1;
//Jump_Word(sg);
//Jump_Word(sd);
//Jump_Word(fg);
//Jump_Word(fd);
//Jump_Word(md);
//M_Word(md);
M_Word(4);
delay(10*TIME);
M_Words(TOTAL);
UP_Run(TOTAL);
M_Black();
delay(10*TIME);
L_Removeout(TOTAL);
delay(3*TIME);
M_Black();
delay(10*TIME);
R_Removeout(TOTAL);
delay(3*TIME);
}//總while循環(huán)的結(jié)束
}//main函數(shù)的結(jié)束
void t0(void) interrupt 1 //定時器0的中斷服務(wù)程序
{
register uchar m,n=BLKN;
TH0 = 0xfc;
TL0 = 0x18;
m = CONIO;
m = (++m)&0x0f;
for(n=0;n
SPI0DAT = dispram[30-m*2+n];//dispram[((BLKN-)n/2+1)*30-m*2-(n/2)*30+n]
while(!SPIF);
SPIF=0;
}
CONIO &= 0xf0;
CLK = 1;
CONIO |= m;
CLK = 0;
scyx=1;
}
void SMBus_ISR (void) interrupt 7
{
bit FAIL = 0;
if (ARBLOST == 0) //如果贏得總線
{
switch (SMB0CN & 0xF0) //確定中斷來源
{
case 0xe0: //主發(fā)送方式下產(chǎn)生開始條件
SMB0DAT = send;
SMB0DAT &= 0xFE;
SMB0DAT |= SMB_RW; //對發(fā)送的數(shù)據(jù)進行處理
STA = 0;
break;
case 0xc0: //主方式下發(fā)送
if (ACK)
{
if (SMB_RW == 0)
{
if(send_number<=3)
{
if(control==0)
{
SMB0DAT = send;
send_number+=5;
}
else
{
SMB0DAT = send1[send_number];
send_number++;
}
}
else
{
send_number=0;control=0;
STO = 1;
BUSY = 0;
}
}
else {;} //BUSY=0
}
else
{
STO = 1;
STA = 1;
}
break;
case 0x80: //主方式下接收
if (receive_number-1>0) //控制接收3個數(shù)據(jù)就結(jié)束
{
receive1[receive_number-1] = SMB0DAT;
ACK = 1;
receive_number--;
}
else
{
receive1[receive_number-1] = SMB0DAT;
receive_number=3;
BUSY = 0;
ACK = 0;
STO = 1;
}
break;
default:
FAIL = 1;
break;
}
}
else //輸?shù)艨偩€
{
FAIL = 1;
}
if (FAIL) //SMBUS通訊失敗后的處理
{
SMB0CF &= ~0x80;
SMB0CF |= 0x80;
STA = 0;
STO = 0;
ACK = 0;
BUSY = 0;
FAIL = 0;
}
SI = 0;
}
void T3_ISR() interrupt 14 //定時器3中斷服務(wù)程序 用于檢測SMBus是否超時
{
SMB0CF &= ~0x80;
SMB0CF |= 0x80;
TMR3CN &=~0x80;
STA = 0;
BUSY = 0;
pcf8563_scl=1;
}
評論