#include "function.h"
#include "ISD4004_drive.h"
#include "usual.h"
#include "lcd.h"
unsigned char code tab[] = {" ISD4004 TEST "}; //定义第1行显示的字符
unsigned char code line1_data[] = {"Recording Start "}; //定义第1行显示的字符
unsigned char code line2_data[] = {"Recording Over "}; //定义第1行显示的字符
unsigned char code line3_data[] = {" Playing Start "}; //定义第1行显示的字符
unsigned char code line4_data[] = {" Playing Over "}; //定义第1行显示的字符
unsigned char code line5_data[] = {"RecordingSuspend"}; //定义第1行显示的字符
unsigned char code line6_data[] = {"Playing Suspend" }; //定义第1行显示的字符
unsigned char mode = 0;
void init(void)
{unsigned char i = 0;
lcd_init();
spi_init();
lcd_wcmd(0x01);
lcd_wcmd(0x80);
while(tab[i] != '\0')
{
lcd_wdat(tab[i]);
i++;
}
EX0 = 1;
IT0 = 1;
IE0 = 0;
EA = 1;
}
void key(void)
{
static bit rec_suspend_flag = 0;
static bit play_suspend_flag = 0;
static unsigned long address = 0;
unsigned char i = 0;
if(!key_rec){
delay_ms(20);
if(!key_rec){
while(!key_rec) ;
rec_test();
mode = 1;
play_suspend_flag = 0;
rec_suspend_flag = 0;
}
}
if(!key_play){
delay_ms(20);
if(!key_play){
while(!key_play) ;
play_test();
mode = 2;
play_suspend_flag = 0;
rec_suspend_flag = 0;
}
}
if(!key_stop){
delay_ms(20);
if(!key_stop){
while(!key_stop) ;
stop_op();
}
}
if(!key_suspend){
delay_ms(20);
if(!key_suspend){
while(!key_suspend) ;
switch(mode){
case 1:if(!rec_suspend_flag){
rec_suspend_flag = 1;
isd_stop();
delay_ms(500);
address = isd_read_address();
lcd_wcmd(0x80);
i = 0;
while(line5_data[i] != '\0')
{
lcd_wdat(line5_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
}
else{ rec_suspend_flag = 0;
isd_powerup();
delay_ms(500);
isd_powerup();
delay_ms(500);
address = address - 2;
isd_setrec(((unsigned char)(address>>8)),((unsigned char)(address&0xff)));
isd_rec(); //发送rec指令
lcd_wcmd(0x80);
i = 0;
while(line1_data[i] != '\0')
{
lcd_wdat(line1_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
}
break;
case 2:if(!play_suspend_flag){
play_suspend_flag = 1;
isd_stop();
delay_ms(500);
address = isd_read_address();
lcd_wcmd(0x80);
i = 0;
while(line6_data[i] != '\0')
{
lcd_wdat(line6_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
}
else{ play_suspend_flag = 0;
isd_powerup();
delay_ms(500);
address = address - 2;
isd_setplay(((unsigned char)(address>>8)),((unsigned char)(address&0xff)));
isd_play();
lcd_wcmd(0x80);
i = 0;
while(line3_data[i] != '\0')
{
lcd_wdat(line3_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
}
break;
case 0:break;
}
}
}
}
void rec_test(void)
{unsigned char i = 0;
lcd_wcmd(0x80);
while(line1_data[i] != '\0')
{
lcd_wdat(line1_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
isd_powerup();
delay_ms(500);
isd_powerup();
delay_ms(500);
isd_setrec(0x00,0x00);
isd_rec(); //发送rec指令
}
void play_test(void)
{
unsigned char i = 0;
lcd_wcmd(0x80);
while(line3_data[i] != '\0')
{
lcd_wdat(line3_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
isd_powerup();
delay_ms(500);
isd_setplay(0x00,0x00); //发送setplay指令,从0x0000地址开始放音
isd_play(); //发送放音指令
}
void stop_op(void)
{unsigned char i;
switch(mode){
case 1: mode = 0;
isd_stop();
lcd_wcmd(0x80);
i = 0;
while(line2_data[i] != '\0')
{
lcd_wdat(line2_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
break;
case 2: mode = 0;
isd_stop();
lcd_wcmd(0x80);
i = 0;
while(line4_data[i] != '\0')
{
lcd_wdat(line4_data[i]);
i++;
}
lcd_wcmd(0xc0+16);
break;
case 0: break;
}
}
/*unsigned char code num_tab[]={"0123456789abcdef"};
void read_addr_test(void)
{
unsigned long addr = 0;
unsigned long mid_var = 0;
unsigned char a,b,c,d,e,f,g,h;
addr = isd_read_address();
mid_var = addr;
h = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
g = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
f = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
e = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
d = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
c = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
b = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
a = mid_var & 0x0000000f;
lcd_wcmd(0xc7);
lcd_wdat(num_tab[a]);
lcd_wdat(num_tab[b]);
lcd_wdat(num_tab[c]);
lcd_wdat(num_tab[d]);
lcd_wdat(num_tab[e]);
lcd_wdat(num_tab[f]);
lcd_wdat(num_tab[g]);
lcd_wdat(num_tab[h]);
lcd_wcmd(0xc0+16);
} */
/*void display_long(unsigned long mid_var)
{
unsigned char a,b,c,d,e,f,g,h;
h = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
g = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
f = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
e = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
d = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
c = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
b = mid_var & 0x0000000f;
mid_var = mid_var >> 4;
a = mid_var & 0x0000000f;
lcd_wcmd(0xc7);
lcd_wdat(num_tab[a]);
lcd_wdat(num_tab[b]);
lcd_wdat(num_tab[c]);
lcd_wdat(num_tab[d]);
lcd_wdat(num_tab[e]);
lcd_wdat(num_tab[f]);
lcd_wdat(num_tab[g]);
lcd_wdat(num_tab[h]);
lcd