微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > C8051F330 16*16点阵(SPI 、SMBus、I2C)PCF8563

C8051F330 16*16点阵(SPI 、SMBus、I2C)PCF8563

时间:11-30 来源:互联网 点击:

pio_int();
TIME01_INT();
TIME2_INT();
TIME3_INT();
SPI_INT(); //SPI0DAT是SPI的数据寄存
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循环的结束
}//main函数的结束

void t0(void) interrupt 1 //定时器0的中断服务程序
{
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: //主发送方式下产生开始条件
SMB0DAT = send;
SMB0DAT &= 0xFE;
SMB0DAT |= SMB_RW; //对发送的数据进行处理
STA = 0;
break;

case 0xc0: //主方式下发送
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个数据就结束
{
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 //输掉总线
{
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中断服务程序 用于检测SMBus是否超时
{
SMB0CF &= ~0x80;
SMB0CF |= 0x80;
TMR3CN &=~0x80;

STA = 0;
BUSY = 0;
pcf8563_scl=1;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top