CH454D的DIG0-DIG5分别连接指示灯的负极,SEG4-SEG6分别连接指示灯的正极 现在想让所有的指示灯全部点亮,可指示灯却没反应,请工程师帮我看看我哪里做的不对?,单片机是lpc1768,程序是照你们的例程改的,程序如下: int main(void) { SystemInit(); //系统初始化函数 ----20110626 LPC_GPIO0->FIODIR |= (1<<28); //24脚P0.28用作io,输出K_CLK LPC_GPIO0->FIOSET |= (1<<28); LPC_PINCON->PINSEL1 &= ~(3<<24);
//LPC_PINCON->PINSEL1 |= ((uint32_t)1<<23); //25脚用作USB_SDA LPC_GPIO0->FIODIR |= (1<<27); //25脚P0.27用作io,输出K_DIO LPC_GPIO0->FIOSET |= (1<<27); LPC_PINCON->PINSEL1 &= ~(3<<22);
ch454_write(0x443);//开显示键盘 ch454_write(0x500);//直接译码
while(1) { ch454_write(0x06ff);//指示灯全闪烁 } }
void Start_I2c() { LPC_GPIO0->FIOSET |= 1<<27; //SDA=1; //发送起始条件的数据信号 LPC_GPIO0->FIODIR |= 1<<27; //设置P0.27为输出 //KEY_DIO Zlg7290Delay(20); LPC_GPIO0->FIOSET |= 1<<28; //SCL=1; LPC_GPIO0->FIODIR |= 1<<28; //设置P0.28为输出 //KEY_CLK Zlg7290Delay(20);//Zlg7290Delay(10);//_Nop(); 500ns LPC_GPIO0->FIOCLR |= 1<<27; //SDA=0; //发送起始信号 Zlg7290Delay(20);//Zlg7290Delay(10); LPC_GPIO0->FIOCLR |= 1<<28; //SCL=0; ///钳住I2C总线,准备发送或接收数据 Zlg7290Delay(20);// Zlg7290Delay(10); }
void Stop_I2c() { LPC_GPIO0->FIOCLR |= 1<<27; //SDA=SDA_CLR; //发送结束条件的数据信号 LPC_GPIO0->FIODIR |= 1<<27; //设置P0.27为输出 //KEY_DIO Zlg7290Delay(20);//Zlg7290Delay(10); LPC_GPIO0->FIOSET |= 1<<28; //SCL=SCL_SET; //结束条件建立时间大于4μs Zlg7290Delay(20);//Zlg7290Delay(10); LPC_GPIO0->FIOSET |= 1<<27; //SDA=SDA_SET; //发送I2C总线结束信号 Zlg7290Delay(20);//Zlg7290Delay(10);
LPC_GPIO0->FIODIR &= ~(1<<27); //设置为P0.27 DIO 数据口为输入
}
void SendByte(uchar c) { uchar BitCnt,i;
LPC_GPIO0->FIODIR |= 1<<27; //设置P0.27为输出 //KEY_DIO Zlg7290Delay(20); //i=1; while(i--); //Zlg7290Delay(1); for(BitCnt=0;BitCnt!=8;BitCnt++) //输出8位数据 { if(c&0x80) {LPC_GPIO0->FIOSET |= 1<<27;} else {LPC_GPIO0->FIOCLR |= 1<<27;} Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1);
LPC_GPIO0->FIOSET |= 1<<28; //SCL=1 c<<=1; Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1);
LPC_GPIO0->FIOCLR |= 1<<28; //SCL=0; Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1); } LPC_GPIO0->FIODIR &= ~(1<<27); //设置为P0.27 DIO 数据口为输入 //设置SDA为输入方向 LPC_GPIO0->FIOSET |= 1<<27; //SDA=1; //8位发送完后释放数据线,准备接收应答位; Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1);
LPC_GPIO0->FIOSET |= 1<<28; //SCL=1; //接收应答 Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1);
LPC_GPIO0->FIOCLR |= (1<<28); //SCL=0; Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1); }
uchar RcvByte() { uchar retc,i; uchar BitCnt; retc=0; LPC_GPIO0->FIOSET |= 1<<27; //SDA=1; LPC_GPIO0->FIODIR &= ~(1<<27); /*置数据线为输入方式*/ Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1); for(BitCnt=0;BitCnt<8;BitCnt++) { LPC_GPIO0->FIOSET |= 1<<28; //SCL=1; /*置时钟线为高使数据线上数据有效*/ Zlg7290Delay(50);//_Nop(); retc=retc<<1; //LPC_GPIO1->FIODIR &= ~(1<<4); //设置为P1.4 DIO数据口为输入 if((LPC_GPIO0->FIOPIN & 0x08000000) == 0x08000000)retc=retc+1; /*读数据位,接收的数据位放入retc中 */
LPC_GPIO0->FIOCLR |= 1<<28; //SCL=0; Zlg7290Delay(50);//_Nop(); } LPC_GPIO0->FIODIR |= 1<<27; //设置为P0.27 DIO数据口为输出 //20110801 LPC_GPIO0->FIOSET |= 1<<27; //SDA=1; Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1); LPC_GPIO0->FIOSET |= 1<<28; //SCL=1; /*置时钟线为高使数据线上数据有效*/ Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1);//_Nop(); LPC_GPIO0->FIOCLR |= 1<<28; //SCL=0; Zlg7290Delay(20);//i=1; while(i--); //Zlg7290Delay(1);//_Nop();
return(retc); }
void ch454_write(unsigned short cmd) //写命令 { uchar i;
Start_I2c(); //启动总线
SendByte((unsigned char)(cmd>>7)&CH454_I2C_MASK|CH454_I2C_ADDR0); //(suba);
SendByte((unsigned char)cmd); //发送数据 //(Data);
Stop_I2c(); //结束总线
}
unsigned char CH454_Read(void) //读取按键 BYTE IRcvStr() { uchar i;
Start_I2c(); //启动总线 SendByte((unsigned char)(0x0700>>7)&CH454_I2C_MASK|CH454_I2C_ADDR0|0x01);//(0x4f); //发送器件地址 i=RcvByte();
Stop_I2c(); //结束总线 return i; }