📄 imemtest.c
字号:
// RAM test avoids the range from 0x4000 to 0x5100 since it is loaded there
//#include "ezusb.h"
#define ALLOCATE_EXTERN // Allocate explicit register addresses here
//#include "ezregs.h" // You don't need ezregs.h with Fx
#include "Fx2.h" //
#include "Fx2regs.h"
#define START_MEM00 0x0080
#define LENGTH_MEM00 (0x2000-START_MEM00)
#define START_MEM01 0x2000
#define LENGTH_MEM01 0x2000 // avoids the range from 0x4000 to 0x5100
// 0x4000 to 0x5100: this program loaded here
#define START_MEM02 0x5100 // check 0x5100 to 0x8000
#define LENGTH_MEM02 (0x8000-START_MEM02)
#define START_MEM03 0x8000
#define LENGTH_MEM03 0x8000
#define LED_ADDR 0x21
BYTE xdata Digit[] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x98, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e };
BYTE xdata Alpha[] = { 0x88,0x83,0xa7,0xa1,0x86,0x8e,0x90,0x8b,0xef,0xe1,0x87,0xc7,0x80,0xab,0xa3,0x8c,0x40,0xaf,0x92,0x87,0xc1,0xcd,0x80,0x89,0x99,0xa4 };
BYTE xdata blank = 0xff;
extern BOOL test_data(void);
BYTE test_mem( void )
{
BYTE i;
BYTE length;
BYTE idata i_mem[ 220 ];
// Set the ports for alternate function -- rd/wr
// PORTCCFG |= 0xc0;
length = 220;
for(i = 0; i < length; ++i)
i_mem[i] = 0x00;
for(i = 0; i < length; ++i)
if(i_mem[i] != 0x00)
return( 1 );
for(i = 0; i < length; ++i)
i_mem[i] = 0xff;
for(i = 0; i < length; ++i)
if(i_mem[i] != 0xff)
return( 2 );
for(i = 0; i < length; ++i)
i_mem[i] = 0xaa;
for(i = 0; i < length; ++i)
if(i_mem[i] != 0xaa)
return( 3 );
for(i = 0; i < length; ++i)
i_mem[i] = 0x55;
for(i = 0; i < length; ++i)
if(i_mem[i] != 0x55)
return( 4 );
// Check the address bus -- LSB only
for(i = 0; i < length; ++i)
i_mem[i] = LSB(i) + MSB(i) * 3;
for(i = 0; i < length; ++i)
if(i_mem[i] != (BYTE) (LSB(i) + MSB(i) * 3))
return( 5 );
return( 0 );
}
void status(WORD stat)
{
WORD saveStat = stat;
BYTE i;
while(TRUE)
{
stat=saveStat;
for (i = 0; i < 4; i++, stat <<= 4)
{
EZUSB_WriteI2C(LED_ADDR, 0x01, &(Digit[(stat>>12)&0xf]));
EZUSB_WaitForEEPROMWrite(LED_ADDR);
EZUSB_Delay(400);
EZUSB_WriteI2C(LED_ADDR, 0x01, &blank);
EZUSB_WaitForEEPROMWrite(LED_ADDR);
EZUSB_Delay(200);
}
EZUSB_WriteI2C(LED_ADDR, 0x01, &blank);
EZUSB_WaitForEEPROMWrite(LED_ADDR);
EZUSB_Delay(500);
}
}
void statString(char *stat)
{
BYTE i;
while(TRUE)
{
for (i = 0; stat[i]; i++)
{
EZUSB_WriteI2C(LED_ADDR, 0x01, &(Alpha[(stat[i] & 0x5f)-'A']));
EZUSB_WaitForEEPROMWrite(LED_ADDR);
EZUSB_Delay(400);
EZUSB_WriteI2C(LED_ADDR, 0x01, &blank);
EZUSB_WaitForEEPROMWrite(LED_ADDR);
EZUSB_Delay(200);
}
EZUSB_WriteI2C(LED_ADDR, 0x01, &blank);
EZUSB_WaitForEEPROMWrite(LED_ADDR);
EZUSB_Delay(500);
}
}
main()
{
BYTE xdata *xd;
BYTE code *cd;
BYTE err = 0;
BYTE xdata buttons = 0;
EZUSB_InitI2C();
EZUSB_WriteI2C(LED_ADDR, 0x01, &(Digit[0]));
EZUSB_WaitForEEPROMWrite(LED_ADDR);
err = test_mem( );
if (err)
status((WORD )err);
xd = (BYTE xdata *)START_MEM00;
cd = (BYTE code *)START_MEM01;
*xd = *cd + 1;
if(*xd != *cd)
{
statString("good");
}
// status(5);
statString(" ");
EZUSB_ReadI2C(0x20,0x01,&buttons); // Read button states
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -