#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
static uchar Digit[5]; //数据发送缓冲区 static uchar F0;
void delay_us(uint time) { uint i,j;
for(i=0 ; i<time ; i++ ) for(j=0 ; j<15; j++ );
}
//起始条件 void start() { SDA = 1; delay_us(10); SCL = 1; delay_us(50); SDA = 0; delay_us(50); SCL = 0 ; }
//停止条件 void stop() { SDA = 0 ; delay_us(10); SCL = 1 ; delay_us(50); SDA = 1 ; delay_us(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_us(10); SCL = 1; delay_us(50); SCL = 0; delay_us(20); temp = temp<< 1; } delay_us(1); SDA = 1; delay_us(1);
EALLOW; SDADIR = 0; EDIS;
SCL = 1; delay_us(20); F0 = 0; if( SDA == 1) { F0 = 1; } delay_us(10); SCL = 0; }
void clearlcd(void) { start(); //启动I2C 总线 sendbyte(0x70); //送器件地址 sendbyte(0x50); //显示模式1:1/3偏压、1:4背极、节电方式及清除显示(清屏) stop(); } void pcf8576set(void) { start(); sendbyte(0x70); //送器件地址 sendbyte(0x58); //显示模式2:1/3偏压、1:4背极、节电方式及允许显示 stop(); }
void senddata(){ uchar i; start(); sendbyte( 0x70 ); //工作方式 if( F0 == 1 ) return; sendbyte( 0x80 ); //子地址 if( F0 == 1 ) return; sendbyte( 0xC8 ); //工作模式 if( F0 == 1 ) return; for( i=0 ; i<5 ; i++ ) { sendbyte( Digit ) ; if( F0 == 1 ) return; } stop(); delay_us(5000); }
void test_lcd() { Digit[0]=0x71; //闪烁方式 Digit[1]=0x7E; //0 Digit[2]=0x18; //1 Digit[3]=0xB6; //2 Digit[4]=0xBC; //3
senddata(); }
|