CY8CKIT-049に1MBitSRAMをつける
Ver.1.001 2020.10.12
更新履歴
2020. 8.24 Ver.1.000 新規作成
2020.10.12 Ver.1.001 ソフト修正
#include "project.h"
#include <stddef.h> // sprinf用
#include <stdlib.h>
//
sprinf用
#include <stdio.h>
// sprinf用
void write_counter_low_byte(uint8 address_low)
{
C_EN_Write(0); // Count_EN L
DATA_BUS_Write(address_low);
LD0_Write(0); // LD0 L
CLKOUT_Write(1); // CLK H
CLKOUT_Write(0); // CLK L
LD0_Write(1); // LD0 H
DATA_BUS_Write(0xff);
}
void write_counter_high_byte(uint8 address_high)
{
C_EN_Write(0); // Count_EN L
DATA_BUS_Write(address_high);
LD1_Write(0); // LD1 L
CLKOUT_Write(1); // CLK H
CLKOUT_Write(0); // CLK L
LD1_Write(1); // LD1 H
DATA_BUS_Write(0xff);
}
void count_up(void)
{
CLKOUT_Write(0); // CLK L
C_EN_Write(1); // Count_EN H
CLKOUT_Write(0); // CLK L
CLKOUT_Write(1); // CLK H
CLKOUT_Write(0); // CLK L
C_EN_Write(0); // Count_EN L
}
uint8 mem_read(uint16 address)
{
uint8 low;
uint8 high;
uint8 data;
C_EN_Write(0); // Count_EN L
low=address & 0x0ff;
high=address>>8;
write_counter_low_byte(low);
write_counter_high_byte(high);
WE_Write(1); // WE H
DATA_BUS_Write(0x0ff);
OE_Write(0); // OE L
data=DATA_BUS_Read();
data=DATA_BUS_Read();
OE_Write(1); // OE H
return(data);
}
uint8 mem_read_start(uint16 address)
{
uint8 low;
uint8 high;
int data;
low=address & 0x0ff;
high=address>>8;
write_counter_low_byte(low);
write_counter_high_byte(high);
WE_Write(1); // WE H
DATA_BUS_Write(0x0ff);
OE_Write(0); // OE L
data=DATA_BUS_Read();
data=DATA_BUS_Read();
OE_Write(1); // OE H
count_up();
return((uint8)data);
}
uint8 mem_read_next(void)
{
int data;
WE_Write(1); // WE H
DATA_BUS_Write(0x0ff);
OE_Write(0); // OE L
data=DATA_BUS_Read();
data=DATA_BUS_Read();
OE_Write(1); // OE H
count_up();
DATA_BUS_Write(0x0ff);
return((uint8) data);
}
uint8 mem_read_hold(void)
{
int data;
WE_Write(1); // WE H
DATA_BUS_Write(0x0ff);
OE_Write(0); // OE L
data=DATA_BUS_Read();
data=DATA_BUS_Read();
OE_Write(1); // OE H
return((uint8)data);
}
void mem_write(uint16 address,uint8 data)
{
uint8 low;
uint8 high;
low=address & 0x0ff;
high=address>>8;
write_counter_low_byte(low);
write_counter_high_byte(high);
WE_Write(1); // WE H
DATA_BUS_Write(data);
WE_Write(0); // WE L
WE_Write(1); // WE H
DATA_BUS_Write(0x0ff);
}
void mem_write_start(uint16 address,uint8 data)
{
uint8 low;
uint8 high;
low=address & 0xff;
high=address>>8;
write_counter_low_byte(low);
write_counter_high_byte(high);
CLKOUT_Write(0);
DATA_BUS_Write(data);
WE_Write(0); // WE L
WE_Write(1); // WE H
DATA_BUS_Write(0xff);
count_up();
}
void mem_write_next(uint8 data)
{
DATA_BUS_Write(data);
WE_Write(0); // WE L
WE_Write(1); // WE H
DATA_BUS_Write(0xff);
count_up();
}
void mem_write_hold(uint8 data)
{
DATA_BUS_Write(data);
WE_Write(0); // WE L
WE_Write(1); // WE H
DATA_BUS_Write(0xff);
}
int main(void)
{
uint16 address;
uint8 data;
uint8 test_data;
uint8 a16=0;
uint8 pass=0;
char buffer[40];
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g.
MyInst_Start()) */
LCD_Char_1_Start() ;
UART_1_Start();
CyDelay(1000);
LCD_Char_1_Position(0, 0) ;
LCD_Char_1_PrintString("MEMORY
TEST ") ;
sprintf(buffer,"\n Memory test \n");
UART_1_UartPutString(buffer) ;
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintString("LCD
TEST ") ;
sprintf(buffer,"LCD test \n");
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
// init terminal
LD0_Write(1); // LD0 H
LD1_Write(1); // LD1 H
CLKOUT_Write(0); // CLK L
C_EN_Write(0); // C_EN L
OE_Write(1); // OE H
WE_Write(1); // WE H
A16_Write(a16); // A16
address=0;
DATA_BUS_Write(0xff);
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintString("
") ;
for(;;){
// test 55
test_data=0x00;
write_counter_low_byte(0);
write_counter_high_byte(0);
for(address=0;address!=0xffff;address++){
mem_write_next(test_data);
test_data--;
}
test_data=0;
write_counter_low_byte(0);
write_counter_high_byte(0);
for(address=0;address!=0xffff;address++){
data=mem_read_next();
if(data != test_data){
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintInt16(address) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(test_data) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(data) ;
LCD_Char_1_PrintString(" ") ;
sprintf(buffer,"ERORR %04x %02x
%02x \n",address,test_data,data);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
for(;;){};
};
test_data--;
};
pass++;
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintString("PASS= ") ;
LCD_Char_1_PrintInt8(pass) ;
LCD_Char_1_PrintString(" SEQRDS") ;
sprintf(buffer,"PASS=%d SEQRDS\n" ,pass);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
for(address=0;address!=0xffff;address++){
mem_write(address,0x55);
};
//2020.10.12 追加
write_counter_low_byte(0);
write_counter_high_byte(0);
//2020.10.12ここまで
for(address=0;address!=0xffff;address++){
data=mem_read_next();
if(data != 0x55){
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintInt16(address) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(0x55) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(data) ;
LCD_Char_1_PrintString(" ") ;
sprintf(buffer,"EROOR %04x %02x %02x
\n",address,0x55,data);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
for(;;){};
};
};
pass++;
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintString("PASS= ") ;
LCD_Char_1_PrintInt8(pass) ;
LCD_Char_1_PrintString(" SEQRD ") ;
sprintf(buffer,"PASS=%d SEQRD\n"
,pass);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
for(address=0;address!=0xffff;address++){
mem_write(address,0xaa);
};
write_counter_low_byte(0);
write_counter_high_byte(0);
for(address=0;address!=0xffff;address++){
data=mem_read_next();
if(data != 0xaa){
LCD_Char_1_Position(0, 0) ;
LCD_Char_1_PrintInt16(address) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(0xaa) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(data) ;
LCD_Char_1_PrintString(" ") ;
sprintf(buffer,"ERORR %04x %02x %02x
\n",address,0xaa,data);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
for(;;){};
};
};
pass++;
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintString("PASS= ") ;
LCD_Char_1_PrintInt8(pass) ;
LCD_Char_1_PrintString(" SEQRD") ;
sprintf(buffer,"PASS=%d
SEQRD\n" ,pass);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
write_counter_low_byte(0);
write_counter_high_byte(0);
for(address=0;address!=0xffff;address++){
mem_write_next (0x55);
};
for(address=0;address!=0xffff;address++){
data=mem_read(address);
if(data != 0x55){
LCD_Char_1_Position(0, 0) ;
LCD_Char_1_PrintInt16(address) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(0x55) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(data) ;
LCD_Char_1_PrintString(" ") ;
sprintf(buffer,"ERORR %04x %02x
%02x \n",address,0x55,data);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
for(;;){};
};
}
pass++;
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintString("PASS= ") ;
LCD_Char_1_PrintInt8(pass) ;
LCD_Char_1_PrintString(" DIR RD") ;
sprintf(buffer,"PASS=%d DIR
RD\n" ,pass);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
write_counter_low_byte(0);
write_counter_high_byte(0);
for(address=0;address!=0xffff;address++){
mem_write_next(0xaa);
};
for(address=0;address!=0xffff;address++){
data=mem_read(address);
if(data != 0xaa){
LCD_Char_1_PrintInt16(address) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(0xaa) ;
LCD_Char_1_PrintString(" ") ;
LCD_Char_1_PrintInt8(data) ;
LCD_Char_1_PrintString(" ") ;
sprintf(buffer,"ERORR %04x %02x
%02x \n",address,0xaa,data);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
for(;;){};
};
}
pass++;
LCD_Char_1_Position(1, 0) ;
LCD_Char_1_PrintString("PASS= ") ;
LCD_Char_1_PrintInt8(pass) ;
LCD_Char_1_PrintString(" DIRRD") ;
sprintf(buffer,"PASS=%d
DIRRD\n" ,pass);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
if (a16==0){
a16=1;
}else{
a16=0;
};
A16_Write(a16); // A16
LCD_Char_1_Position(0, 0) ;
LCD_Char_1_PrintString("A16= ") ;
LCD_Char_1_PrintInt8(a16) ;
LCD_Char_1_PrintString(" ") ;
sprintf(buffer,"A16=%d \n"
,a16);
UART_1_UartPutString(buffer) ;
UART_1_UartPutCRLF(1) ;
}
/* END OF FILE */
}