📄 main.c
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#define WRDATA (1)
#define POLLACK (2)
#define RDDATA (3)
#define SETRDADDR (4)
#define IICBUFSIZE 0x20
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Rd24C040(U32 slvAddr,U32 addr,U8 *data);
void Wr24C040(U32 slvAddr,U32 addr,U8 data);
#define ZLG7290 0x70
unsigned char ZLG7290_SendCmd(unsigned char Data1,unsigned char Data2);
unsigned char ZLG7290_SendStr(unsigned char sla, unsigned char suba, unsigned char *s, unsigned char no);
void ZLG7290_SendBuf(unsigned char * disp_buf,unsigned char num);
void DelayNS(U32 dly);
U8 _iicData[IICBUFSIZE];
volatile int _iicDataCount;
volatile int _iicStatus;
volatile int _iicMode;
volatile int _iicsuba;
volatile int _iicsuba_en;
int _iicPt;
void __irq IicInt(void);
void Main(void)
{
unsigned int i;
static U8 disp_buf[9];
char aa;
rSYSCFG=SYSCFG_8KB;
Isr_Init();
Port_Init();
Uart_Init(0,115200);
Uart_Select(0);
Delay(1);
Uart_Printf("\n* 北京三恒星科技 *");
Uart_Printf("\n* -S3C44B0X功能部件:数码管实验测试- *");
Uart_Printf("\n* UART Config--COM:115.2kbps,8Bit,NP,UART0 *");
Uart_Printf("\n* www.sanhengxing.com *");
Uart_Printf("\n*------------------Begin to Start 数码管实验测试,OK? (Y/N)-----------------*");
Uart_Printf("\n");
aa= Uart_Getch();
if((aa=='Y')||(aa=='y'))
Uart_Printf("[IIC Test using ZLG7290]\n");
pISR_IIC=(unsigned)IicInt;//中断入口函数说明
rINTMSK=~(BIT_GLOBAL|BIT_IIC);//去屏蔽中断
rIICCON=(1<<7)|(0<<6)|(1<<5)|(0xf);
//Enable interrupt, IICCLK=MCLK/16, Enable ACK
//40Mhz/16/(15+1) = 257Khz
rIICADD=0x10; // S3C44B0X slave address ?
rIICSTAT=0x10;//?
Uart_Printf("TESTING IS STARTING\n");
for(i=0; i<=8; i++)
disp_buf[i] = 0xC8;
ZLG7290_SendBuf(disp_buf,9);
DelayNS(150);
/* 显示"8 7 6 5 4 3 2 1" */
for(i=0; i<=8; i++)
disp_buf[i] = i+1;
ZLG7290_SendBuf(disp_buf,9);
DelayNS(150);
}
//传送数码管字符编码
void ZLG7290_SendBuf(unsigned char * disp_buf,unsigned char num)
{
unsigned char i;
for(i=0;i<num;i++)
{
ZLG7290_SendCmd(0x60+i,*disp_buf);
disp_buf++;
}
}
unsigned char ZLG7290_SendCmd(unsigned char Data1,unsigned char Data2)
{
unsigned char Data[2];
Data[0]=Data1;
Data[1]=Data2;
ZLG7290_SendStr(ZLG7290,0x07,Data,2);
DelayNS(500);
return 1;
}
void DelayNS(U32 dly)
{ U32 i;
for(; dly>0; dly--)
for(i=0; i<5000; i++);
}
unsigned char ZLG7290_SendStr(unsigned char sla, unsigned char suba, unsigned char *s, unsigned char no)
{
_iicMode=WRDATA;
_iicPt=0;
_iicData[0]=(U8)s[0];
_iicData[1]=s[1];
_iicsuba=suba;
_iicsuba_en=2;
_iicDataCount=3;
rIICDS=sla;//slvAddr;//0xa0
rIICSTAT=0xf0;
//Clearing the pending bit isn't needed because the pending bit has been cleared.
while(_iicDataCount!=-1);
}
/*****************************************************************/
void __irq IicInt(void)
{
U32 iicSt,i;
rI_ISPC=BIT_IIC;
iicSt=rIICSTAT;
if(iicSt&0x8){} // when bus arbitration is failed.
if(iicSt&0x4){} // when a slave address is matched with IICADD
if(iicSt&0x2){} // when a slave address is 0000000b
if(iicSt&0x1){ while(1) {iicSt=rIICSTAT;
if(iicSt&0x1==0) break;
}
} // when ACK isn't received
switch(_iicMode)
{
case POLLACK:
_iicStatus=iicSt;
break;
case RDDATA:
if((_iicDataCount--)==0)
{
_iicData[_iicPt++]=rIICDS;
rIICSTAT=0x90; //stop MasRx condition
rIICCON=0xaf; //resumes IIC operation.
Delay(1); //wait until stop condtion is in effect.
//too long time...
//The pending bit will not be set after issuing stop condition.
break;
}
_iicData[_iicPt++]=rIICDS;
//The last data has to be read with no ack.
if((_iicDataCount)==0)
rIICCON=0x2f; //resumes IIC operation with NOACK.
else
rIICCON=0xaf; //resumes IIC operation with ACK
break;
case WRDATA:
if((_iicDataCount--)==0)
{
rIICSTAT=0xd0; //stop MasTx condition
rIICCON=0xaf; //resumes IIC operation.
Delay(1); //wait until stop condtion is in effect.
//The pending bit will not be set after issuing stop condition.
break;
}
else {if (_iicsuba_en==2)
{rIICDS=_iicsuba;
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON=0xaf; //resumes IIC operation.
_iicsuba_en=0;
break;
}
else {rIICDS=_iicData[_iicPt++];
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON=0xaf; //resumes IIC operation.
}
}
break;
case SETRDADDR:
//Uart_Printf("[S%d]",_iicDataCount);
if((_iicDataCount--)==0)
{
break; //IIC operation is stopped because of IICCON[4]
}
rIICDS=_iicData[_iicPt++];
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON=0xaf; //resumes IIC operation.
break;
default:
break;
}
}
/******************************************************************/
void Isr_Init(void)
{
U32 i;
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
{
*((volatile unsigned *)i)=0xEA000000+0x1FFE;
}
rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; // All=IRQ mode
rINTMSK|=BIT_GLOBAL|BIT_EINT3; // All interrupt is masked.
}
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -