我板子上的8段数码管是用zlg7290芯片驱动的。芯片上的IICSDA管脚连接S3C2410的IICSDA/GPE14管脚,IICSCL管脚与S3C2410的IICSCL/GPE15管脚相连。这块芯片的读写好像要用到I2C总线,对I2C总线的读写操作我一直搞不明白。
下面的程序是板子的例子,它是循环显示0---9十个数字(共阴极的)
zlg7290的从地址是0x70 显示寄存器地址是0x10 -- 0x17
/**************************************************************************
* File: 8led.c
* Author: Embest
* Desc: 8-segment digit LED control functions
* History:
***************************************************************************
/*-----------------------------------------------------------------------*/
/*include files*/
/*-----------------------------------------------------------------------*/
#include "2410lib.h"
/*-----------------------------------------------------------------------*/
/*global variables*/
/*-----------------------------------------------------------------------*/
unsigned char f_szDigital[10] ={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6}; // 0 ~ 9
/*-----------------------------------------------------------------------*/
/*functions declare*/
/*-----------------------------------------------------------------------*/
void led8_test(void);
/*************************************************************************
* name: led8_test()
* func: test 8led
* para: none
* ret: none
* modify:
* comment: write data to display buffer of ZLG7290,then we can see figure scrolling on LED.
**************************************************************************/
void led8_test(void)
{
int i, j, k;
uart_printf("\n 8-segment Digit LED Test Example (Please look at LED)\n");
iic_init_8led();
for(;;)
{
for(j=0; j<10; j++)
{
for(i=0; i<8; i++)
{
k = 9-(i+j)%10;
//write to DpRam0~DpRam7 of ZLG7290
iic_write_8led(0x70, 0x10+i, f_szDigital[k]);
}
delay(10000);
}
}
}
/**************************************************************************
* File: iic.c
* Author: Embest
* Desc: iic source code
* History:
* Y.J.Guo, Programming modify, April 2, 2005
**************************************************************************/
/*-----------------------------------------------------------------------*/
/*include files*/
/*-----------------------------------------------------------------------*/
#include "2410lib.h"
#include "iic_8led.h"
/*-----------------------------------------------------------------------*/
/*global variables */
/*-----------------------------------------------------------------------*/
int f_nGetACK;
/*-----------------------------------------------------------------------*/
/*function declare */
/*-----------------------------------------------------------------------*/
void iic_int_8led(void) __attribute__ ((interrupt ("IRQ")));
void iic_init_8led(void);
void iic_write_8led(UINT32T unSlaveAddr, UINT32T unAddr, UINT8T ucData);
void iic_read_8led(UINT32T unSlaveAddr, UINT32T unAddr, UINT8T *pData);
/*************************************************************************
* name: iic_init_8led()
* func: initialize iic
* para: none
* ret: none
* modify:
* comment:
**************************************************************************/
void iic_init_8led(void)
{
f_nGetACK = 0;
// Enable interrupt
rINTMOD = 0x0;
rSRCPND = rSRCPND; // clear all interrupt
rINTPND = rINTPND; // clear all interrupt
rINTMSK &= ~BIT_IIC;
pISR_IIC= (unsigned)iic_int_8led;
// Initialize iic
rIICADD = 0x10; // S3C2410X slave address
rIICCON = 0xef; // Enable ACK, interrupt, set IICCLK=MCLK/512
rIICSTAT= 0x10; // Enable TX/RX
}
/************************************************************************
* name: iic_write_8led()
* func: write data to iic
* para: unSlaveAddr --- input, chip slave address
* unAddr --- input, data address
* ucData --- input, data value
* ret: none
* modify:
* comment:
**************************************************************************/
void iic_write_8led(UINT32T unSlaveAddr,UINT32T unAddr,UINT8T ucData)
{
f_nGetACK = 0;
// Send control byte
rIICDS = unSlaveAddr; // 0x70
rIICSTAT = 0xf0; // Master Tx,Start 这里会使IICCON = 0xff ???
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
// Send address
rIICDS = unAddr;
rIICCON = 0xef; // Resumes IIC operation.这里会使IICSTAT=0xf1 ?
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
// Send data
rIICDS = ucData;
rIICCON = 0xef; // Resumes IIC operation.
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
// End send
rIICSTAT = 0xd0; // Stop Master Tx condition
rIICCON = 0xef; // Resumes IIC operation.这里会改变IICDS的值!!
delay(5); // Wait until stop condtion is in effect.
}
/************************************************************************
* name: iic_read_8led()
* func: read data from iic
* para: unSlaveAddr --- input, chip slave address
* unAddr --- input, data address
* pData --- output, data pointer
* ret: none
* modify:
* comment:
*************************************************************************/
void iic_read_8led(UINT32T unSlaveAddr,UINT32T unAddr,UINT8T *pData)
{
char cRecvByte;
f_nGetACK = 0;
// Send control byte
rIICDS = unSlaveAddr; // Write slave address to IICDS
rIICSTAT = 0xf0; // Master Tx,Start
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
// Send address
rIICDS = unAddr;
rIICCON = 0xef; // Resumes IIC operation.
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
// Send control byte
rIICDS = unSlaveAddr; // 0x70
rIICSTAT = 0xb0; // Master Rx,Start
rIICCON = 0xef; // Resumes IIC operation.
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
// Get data
cRecvByte = rIICDS;
rIICCON = 0x2f;
delay(1);
// Get data
cRecvByte = rIICDS;
// End receive
rIICSTAT = 0x90; // Stop Master Rx condition
rIICCON = 0xef; // Resumes IIC operation.
delay(5); // Wait until stop condtion is in effect.
*pData = cRecvByte;
}
/*************************************************************************
* name: iic_int_8led()
* func: IIC interrupt handler
* para: none
* ret: none
* modify:
* comment:
**************************************************************************/
void iic_int_8led(void)
{
ClearPending(BIT_IIC);
f_nGetACK = 1;
}
我先向0x10中写入0xFC这时0x10对应的数码管显示0 然后我再用iic_read_8led读的时候发现读出来的数据不是0xFC,这是为什么呢?
还有我单步跟踪的时候发现IICSTAT IICCON IICDS这些寄存器有时一个一改变,其他也会自动改变,不明白这是为什么。这里应该是我写进去0xFC读出来却不是0xFC原因,为什么是这样我不明白。
麻烦请大家给个主意~~ 谢谢了~~! 我卡在这里已经3天了,晕啊~~~!!!
跪谢~!