?? 0361.c
字號:
#pragma sfr
#pragma DI
#pragma EI
#pragma nop
void LcdDrvCtrWrite1Byte( unsigned char addr, unsigned char data );
void LcdDrvSegWrite( unsigned char *src, unsigned char addr, unsigned char size );
void I2cPutData( unsigned char data );
unsigned char I2cPutAddress( unsigned char data );
void LcdDrvClkOut( void );
void I2cWait( void );
unsigned char I2cStartCondition( void );
void I2cStopCondition( void );
void I2cInit( void );
void LcdDrvInit( void ) ;
void LcdDrvOnWait( void );
void I2cGetDataAckSet( unsigned char *src );
void I2cGetDataNackSet( unsigned char *src );
void EeprgSegWrite( unsigned char *src, unsigned char addr, unsigned char size );
void EeprgSegRead( unsigned char *src, unsigned char addr, unsigned char size );
void movdata1(unsigned char *mptr,unsigned char *dptr,unsigned char no,unsigned char xishu);
void movdata1(unsigned char *mptr,unsigned char *dptr,unsigned char no,unsigned char xishu)
{
char i,tmp;
for(i=0;i<no;i++)
{
tmp=*mptr;
tmp+=xishu;
*dptr=tmp;
dptr++;
mptr++;
}
}
void I2cGetDataNackSet( unsigned char *src )
{
if( !TRC0 )
{
/* Receive data exists */
/*-- Cancels wait and sets ACK transmission --*/
WREL0 = 1; /* Cancels wait */
// WTIM0=0;
ACKE0 = 0; /* Sets ACK transmission */
/*-- Wait for completion of reception --*/
I2cWait();
/*-- Data reception --*/
*src = IIC0;
}
}
void I2cGetDataAckSet( unsigned char *src )
{
if( !TRC0 )
{
/* Received data exists */
/*-- Cancels wait and sets ACK transmission --*/
WREL0 = 1; /* Cancels wait */
//WTIM0=0;
ACKE0 = 1; /* Sets ACK transmission */
/*-- Wait for completion of reception --*/
I2cWait();
/*-- Data reception --*/
*src = IIC0;
}
}
void LcdDrvCtrWrite1Byte( unsigned char addr, unsigned char data )
{
// IICE0 = 1; // I2cEnable();
// LcdDrvClkOut();
/*-- Start condition --*/
I2cStartCondition();
/*-- Slave ID LCDSEG --*/
I2cPutAddress( 0X70 );
/*-- Data address --*/
I2cPutData( addr );
I2cPutData( data);
/*-- Transmits stop condition --*/
I2cStopCondition();
}
void LcdDrvSegWrite( unsigned char *src, unsigned char addr, unsigned char size )
{
unsigned char cnt;
/*-- Enables I2C operations and clock output (possible when OFF)--*/
IICE0 = 1; // I2cEnable();
/*-- Enables clock output to LCD chip --*/
LcdDrvClkOut();
/*-- Start condition --*/
I2cStartCondition();
I2cPutAddress(0X72);
I2cPutData(addr) ;
/*-- Writes segment data --*/
for( cnt = 0; cnt < size; cnt++ )
{
I2cPutData( *src & 0x0f );
I2cPutData(( *src >> 4 ) & 0x0f );
src++;
}
/*-- Transmits stop condition --*/
I2cStopCondition();
}
void I2cPutData( unsigned char data )
{
/*-- Sets data --*/
IIC0 = data;
/*-- Wait for transmission completion --*/
I2cWait();
/*-- ACK detection --*/
}
unsigned char I2cPutAddress( unsigned char data )
{
if( STD0 ){
I2cPutData( data );
}
return 1;
}
void LcdDrvClkOut( void )
{
PM14.0=0;
CKS.4= 1;
}
void I2cWait( void )
{
while( !IICIF0 ){
}
IICIF0 = 0;
}
unsigned char I2cStartCondition( void )
{
if( !IICBSY ){
/* Bus release status */
/*-- Sets start condition --*/
STT0 = 1;
return 0;
}
while(!STD0)
;
STT0 = 1;
}
void I2cStopCondition( void )
{
SPT0 = 1;
}
void I2cInit( void )
{
PM6.0=0;
PM6.1=0;
IICE0=0;
IICX0=0;
IICCL0=0;
IICRSV=1;
STCEN=0;
IICC0=0X88;
SPT0=1;
}
void LcdDrvInit( void )
{
I2cInit();
P13.0=1;
CKS=0X07;
LcdDrvClkOut();
LcdDrvCtrWrite1Byte(0x00, 0x82 );
/*-- Selects display mode --*/
LcdDrvCtrWrite1Byte( 0x01,0);
LcdDrvCtrWrite1Byte( 0x02, 0xc0);
}
void LcdDrvOnWait( void )
{
unsigned char i; /*-- Enables I2C operation --*/
IICE0 = 1; // I2cEnable();
/*-- Enables clock output to LCD chip --*/
LcdDrvClkOut();
/*-- Sets LCD step-up level and contrast--*/
LcdDrvCtrWrite1Byte( 0x03, 0x00);
/*-- Enables LCD step-up --*/
LcdDrvCtrWrite1Byte( 0x01, 0x20);
for(i=0;i<255;i++)
{
NOP();
NOP();
NOP();
}
LcdDrvCtrWrite1Byte( 0x01, 0x60);
LcdDrvCtrWrite1Byte( 0x01, 0xe0);
}
unsigned char aa[5]={0xff,0xff,0xff,0xff,0xff};
unsigned char buff[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void main(void)
{
unsigned char i;
DI();// EI();
movdata1(buff,aa,3,0x33);
// IMS=0XC6;
LcdDrvInit();
LcdDrvOnWait();
EI(); // enable all interrupts
LcdDrvSegWrite( aa, 0x00,0x05);
while(1)
{
LcdDrvSegWrite( aa, 0x00,0x05);
//for(i=0;i<20;i++)
// buff[i]=0x55;
// EeprgSegWrite(buff,0,10 );
EeprgSegRead(buff,0,10);
for(i=0;i<20;i++)
buff[i]=0x88;
//EeprgSegWrite(buff,0,10 );
LcdDrvSegWrite( aa, 0x6,0x05);
DI();
EeprgSegRead(buff,0,20);
for(i=0;i<10;i++)
buff[i]=0x55;
EeprgSegWrite(buff,6,10 );
}
}
void EeprgSegWrite( unsigned char *src, unsigned char addr, unsigned char size )
{
unsigned char cnt;
/*-- Enables I2C operations and clock output (possible when OFF)--*/
IICE0 = 1; // I2cEnable();
/*-- Enables clock output to LCD chip --*/
//LcdDrvClkOut();
/*-- Start condition --*/
PM0.0=0;
P0.0=0;
I2cStartCondition();
I2cPutAddress(0Xa0);
I2cPutData(addr) ;
/*-- Writes segment data --*/
for( cnt = 0; cnt < size; cnt++ )
{
I2cPutData(*src);
src++;
}
/*-- Transmits stop condition --*/
I2cStopCondition();
}
void EeprgSegRead( unsigned char *src, unsigned char addr, unsigned char size )
{
unsigned char i;
/*-- Enables I2C operations and clock output (possible when OFF)--*/
IICE0 = 1; // I2cEnable();
/*-- Enables clock output to LCD chip --*/
//LcdDrvClkOut();
/*-- Start condition --*/
I2cStartCondition();
I2cPutAddress(0Xa0);
I2cPutData(addr) ;
STT0 = 1;
while(!STD0)
;
I2cPutData(0xA1) ;// IIC0 = 0xA1;
//I2cStartCondition();
//I2cPutAddress(0Xa1);
/*-- Writes segment data --*/
for(; size>0 ; size-- )
{
I2cGetDataAckSet( src );
src++;
}
I2cGetDataNackSet(src);
/*-- Transmits stop condition --*/
I2cStopCondition();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -