单步跟踪了时序,能写入PCF8576,有应答,但LCD显示不变,即PCF8576输出引脚电位保持不变,为3.3V。请高手指点: #include "DSP28_Device.h"
#define uint unsigned int #define uchar unsigned char
#define SDA GpioDataRegs.GPADAT.bit.GPIOA11 #define SCL GpioDataRegs.GPADAT.bit.GPIOA12 #define SDADIR GpioMuxRegs.GPADIR.bit.GPIOA11 #define SCLDIR GpioMuxRegs.GPADIR.bit.GPIOA12
uchar SlvAdr; uchar SubAdr; uchar PCF8576 ; uchar MODE1 ; uchar MODE2; uchar Digit[8]; //数据发送缓冲区 uchar F0;
void delay(uint time) { uint i,j;
for(i=0 ; i<time ; i++ ) for(j=0 ; j<50; j++ );
}
//起始条件 void start() { SDA = 1; delay(10); SCL = 1; delay(50); SDA = 0; delay(50); SCL = 0 ; }
//停止条件 void stop() { SDA = 0 ; delay(10); SCL = 1 ; delay(50); SDA = 1 ; delay(50); }
void sendbyte(uchar ch) { uchar i; uchar temp = ch;
EALLOW; SDADIR = 1; EDIS;
for(i=0 ; i<8 ; i++ ) { if( ( temp&0x80) == 0x80 ) { SDA = 1 ; } else { SDA = 0; } delay(10); SCL = 1; delay(50); SCL = 0; delay(20); temp = temp<< 1; } delay(1); SDA = 1; delay(1);
EALLOW; SDADIR = 0; EDIS;
SCL = 1; delay(20); F0 = 0; if( SDA == 1) { F0 = 1; } delay(10); SCL = 0; }
void ClearLcd(void) { start(); //启动I2C 总线 sendbyte(0x1070); //送器件地址 sendbyte(0x50); //显示模式1:1/3偏压、1:4背极、节电方式及清除显示(清屏) stop(); } void PCF8576SET(void) { start(); sendbyte(0x1070); //送器件地址 sendbyte(0x58); //显示模式2:1/3偏压、1:4背极、节电方式及允许显示 stop(); }
void senddata(){ uchar i;
//ClearLcd(); start(); sendbyte( 0x1070 ); if( F0 == 1 ) return; sendbyte( 0x1080 ); if( F0 == 1 ) return; for( i=0 ; i<5 ; i++ ) { sendbyte( Digit ) ; if( F0 == 1 ) return; } stop(); delay(5000); }
void test_lcd() { Digit[0]=0x71; //闪烁方式 Digit[1]=0x7E; //0 Digit[2]=0x18; //1 Digit[3]=0xB6; //2 Digit[4]=0xBC; //3
senddata(); }
|