/******************************************** MODE:1602 LCD IC:AIP31068 + SN3193(0xD6) 接口:IIC (31068最大时钟频率是400KHz, 3193最大可以达到400KHz.) MCU:W78E516D 12MHZ 更新:2024-4-20 *********************************************/ #include #include #define uchar unsigned char #define uint8_t unsigned char #define uint unsigned int #define ulong unsigned long sbit SCL=P3^0; sbit SDA=P3^1; // IIC_ADDRESS #define LCD_IIC_ADDRESS 0x7C //AIP31068 SLAVE ADDRESS #define SN3193_IIC_ADDRESS 0xD6 //SN3193 SLAVE ADDRESS(AD=1): 0xD6 AD=0: 0xD0 //============================================================== // SN3193 Register definitions #define SHUTDOWN_REG 0x00 //Set software shutdown mode #define BREATING_CONTROL_REG 0x01 //Set the breathing function #define LED_MODE_REG 0x02 //Set operation mode #define CURRENT_SETTING_REG 0x03 //Set output current #define PWM_1_REG 0x04 //3 channels PWM duty cycle data #define PWM_2_REG 0x05 //3 channels PWM duty cycle data #define PWM_3_REG 0x06 //3 channels PWM duty cycle data #define PWM_UPDATE_REG 0x07 //Load PWM Registers and LED Control Register’ data #define T0_1_REG 0x0A //Set the T0 time #define T0_2_REG 0x0B //Set the T0 time #define T0_3_REG 0x0C //Set the T0 time #define T1T2_1_REG 0x10 //Set the T1&T2 time #define T1T2_2_REG 0x11 //Set the T1&T2 time #define T1T2_3_REG 0x12 //Set the T1&T2 time #define T3T4_1_REG 0x16 //Set the T3&T4 time #define T3T4_2_REG 0x17 //Set the T3&T4 time #define T3T4_3_REG 0x18 //Set the T3&T4 time #define TIME_UPDATE_REG 0x1C //Load time registers’ data #define LED_CONTROL_REG 0x1D //OUT1~ OUT3 enable bit #define RESET_REG 0x2F //Reset all registers to default value //==================================== unsigned char code CUSTOM[]; void delay(int i); void IIC_start(void); void IIC_stop(void); void IIC_Ack(void); void transfer(unsigned char data1); void LCD_command(uchar com); void LCD_data(uchar dat); void initial_lcd(void); void SetCGRAM(unsigned char *puts); void FullDDRAM(unsigned char fillchar); void disp_char(int line,int column,char code *dp); void Disp_XY( char posx,char posy); void DispOneChar(uchar x,uchar y,uchar Wdata); void write3193(unsigned char address2,unsigned char info); void initial_3193(void); void SN3193_IIC_PWM(void); unsigned char code CUSTOM[]={ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, //全黑 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //全白 }; //=============delay time===================== void delay(int i) { int j,k; for(j=0;j