PIC16F877A驱动AT24C512弄了好久都没有结果,求大神给我知道一下
/*-----------------------------------------------------------------------------
调用方式: init_port()
函数说明:初始化端口
-----------------------------------------------------------------------------*/
void init_port()
{
TRISA=0B00001011;
TRISB=0B11111111;
TRISC=0B10000010;
TRISD=0B00000000;
TRISE=0B00000000;
PWM=0;
BK=0;
ALI=0;
x2=0;
SSPSTAT=0x80;
SSPCON=0x38;
SSPCON2=0;
SSPADD=0x09;
}
/*-----------------------------------------------------------------------------
调用方式:lcdini(void)
函数说明:液晶初始化
-----------------------------------------------------------------------------*/
void lcdini()
{
delayms(10);
E1=0;
E2=0;
RW=0;
A0=0;
OUTMI(0XAF);//推出休闲模式
OUTMI(0XA4);//1/32占空比
OUTMI(0XCD);//正向排列
OUTMI(0xA1);
OUTMI(0xA0);
OUTMI(0X00);
OUTSI(0XAF);//推出休闲模式
OUTSI(0XA4);//1/32占空比
OUTSI(0XCD);//正向排列
OUTSI(0xA1);
OUTSI(0xA0);
OUTSI(0X00);
}
/*-----------------------------------------------------------------------------
调用方式:dis_init()
函数说明:显示汉字
-----------------------------------------------------------------------------*/
void dis_init()
{
uchar i=0;
Draw_word(1,bmp001);
__delay_ms(30);
Draw_word(25,bmp002);
__delay_ms(30);
Draw_word(49,bmp003);
__delay_ms(30);
Draw_word(73,bmp005);
__delay_ms(30);
Draw_word(97,bmp004);
for(i=0;i<20;i++)
{
__delay_ms(100);
}
}
/*-----------------------------------------------------------------------------
调用方式:clrscr(void)
函数说明:清屏。(内函数,私有,用户不直接调用)
-----------------------------------------------------------------------------*/
void clrscr()
{
uchar i;
uchar page;
for (page=0;page<4;page++)
{
SetPage(page,page);
SetAddress(0,0);
for (i=0;i<61;i++)
{
PutCharL(0);
PutCharR(0);
}
}
}
/*-----------------------------------------------------------------------------
调用方式:weeprom_write()
函数说明:
-----------------------------------------------------------------------------*/
void weeprom_write()
{
uchar i;
SSPIF=0;
SEN=1;
while(!SSPIF);
SSPIF=0;
SSPBUF=0xA0;
while(!SSPIF);
SSPIF=0;
SSPBUF=0xAA;
while(!SSPIF);
SSPIF=0;
for(i=0;i<6;i++)
{
SSPBUF=ee_data[i];
while(!SSPIF);
SSPIF=0;
}
PEN=1;
while(!SSPIF);
SSPIF=0;
}
/*-----------------------------------------------------------------------------
调用方式:weeprom_read())
函数说明:初始化按键
-----------------------------------------------------------------------------*/
void weeprom_read()
{
uchar i;
SSPIF=0;
SEN=1;
while(!SSPIF);
SSPIF=0;
SSPBUF=0xA0;
while(!SSPIF);
SSPIF=0;
SSPBUF=0xAA;
while(!SSPIF);
SSPIF=0;
SSPIF=0;
RSEN=1;
while(!SSPIF);
SSPIF=0;
SSPBUF=0xA1;
while(!SSPIF);
SSPIF=0;
for(i=0;i<6;i++)
{
RCEN=1;
while(!SSPIF);
read_data[i]=SSPBUF;
while(!SSPIF);
SSPIF=0;
if(i>=5)
{
ACKDT=1;
}
else
{
ACKDT=0;
}
ACKEN=1;
while(!SSPIF);
SSPIF=0;
}
PEN=1;
while(!SSPIF);
SSPIF=0;
}
void main()
{
init_port();//初始化端口
lcdini(); //显示初始化
clrscr(); //清屏
dis_init();//显示黄山斯特尔
weeprom_write();
delayms(1000);
weeprom_read();
clrscr();
Draw_word(1,bmp012);
__delay_ms(100);
Draw_word(25,bmp013);
__delay_ms(100);
rdot(52);
__delay_ms(100);
Draw_math(read_data[i],62,11,math);
__delay_ms(100);
Draw_math(read_data[i],75,11,math);
__delay_ms(100);
Draw_math(read_data[i],88,11,math);
__delay_ms(100);
Draw_math(read_data[i],101,11,math);
__delay_ms(100);
while(1);
} |