📄 voice.c
字号:
OVF=0;
EOM=0;
ISD_PowerUp();
ISD_SET_MC();
ISD_MC();
while(!OVF)
{
while(!EOM)
{
if(OVF) break;
}
segment++;
if(OVF) break;
ISD_MC();
}
DispIntToLED(segment);
return(segment);
}
unsigned Search_Segment(unsigned int seg)
{
unsigned int count=0;
ISD_PowerUp();
ISD_SET_MC();
ISD_MC();
while(!OVF)
{
if(seg==0)
{
RAC_Read=0;
break;
}
ISD_MC();
while(!EOM)
{
if(OVF) break;
}
count++;
if(!OVF)
{
if(count==seg)
{
CurrentSeg=seg;
break;
}
}
else
{
break;
}
}
RAC_Read=ISD_WriteByte(0x00,0x30);
return(RAC_Read);
}
bit CompareBuffer(uchar code * pc_str,uchar idata *ip_str)
{
uchar data i;
bit same;
while(*pc_str)
{
i=*ip_str;
if(*ip_str!=*pc_str)
{
same=0;
break;
}
else
{
same=1;
ip_str++;
pc_str++;
}
}
return(same);
}
unsigned int GetRecNum() //得到接收缓冲区内的数值
{
unsigned int num;
num=(rdata[1]-0x30)*10000+(rdata[2]-0x30)*1000+(rdata[3]-0x30)*100+(rdata[4]-0x30)*10+rdata[5]-0x30;
return (num);
}
void InitMCU(void)
{
SCON=0X50; // SM0/SM1/SM2/REN/TB8/RB8/TI/RI
TMOD=0X51;
TH1=0;
TL1=0;
TR1=1;
TH0=0XB7 ;
TL0=0X59 ;
TR0=1;
T2CON=0X30;
RCAP2H=0XFF;
RCAP2L=0Xb8;
TR2=1; //定时器2做为波特率发生器, (RCAP2H,RCAP2L)= 65535-fosc/32*波特率
EA=1;
ES=1;
ET0=1;
EX0=1;
IT0=0;
EX1=1;
IT1=1;
// PS=1;
}
void UART_Send(uchar dat)
{
SBUF=dat;
while(!TI);
TI=0;
}
void TimeRun()
{
REG_B=0X1A;
}
void Init_RTC()
{
uchar i;
REG_B=0X9A;
REG_A=0X26;
REG_C=0X70;
i=REG_C;
TimeRun();
}
void RestTime()
{
SECOND=0X50;
MINUTE=0X00;
HOUR=0X12;
WEEK=0X04;
DATE=0X01;
MONTH=0X10;
YEAR=0X02;
CENTURY=0X20;
}
main()
{
uchar j;
unsigned long int temp;
uint playseg;
prekey=0xff;
InitMCU();
Init_RTC();
I2C_ADDR=0;
ISD_PowerUp();
Segment=Total_Segment();
RAC_Read=ISD_WriteByte(0x00,0x30);
CurrentSeg=0;
start=GetStartDelay(CurrentSeg);
while(1)
{
if(BufferFlag)
{
BufferFlag=0;
if(CompareBuffer("R",rdata))
{
CurrentSeg=GetRecNum();
Search_Segment(CurrentSeg);
if(CurrentSeg==0)
{
ISD_PowerUp();
ISD_PowerUp();
ISD_SET_REC(0);
}
else
{
ISD_SET_REC(RAC_Read);
ISD_REC();
}
}
else
if(CompareBuffer("P",rdata))
{
CurrentSeg=GetRecNum();
Search_Segment(CurrentSeg);
if(CurrentSeg==0)
{
ISD_PowerUp();
ISD_SetPlay();
}
ISD_Play();
}
else
if(CompareBuffer("Break!",rdata))
{
RAC_Read=ISD_WriteByte(0x00,0x30);
ResetCounter();
VoiceRun=0;
}
else
if(CompareBuffer("U",rdata))
{
temp=GetRecNum();
SaveStartDelay(CurrentSeg,temp);
}
else
if(CompareBuffer("?",rdata))
{
CurrentSeg=GetRecNum();
temp=GetStartDelay(CurrentSeg);
EA=0;
j='P';
UART_Send(j);
j=temp/10000+0x30;
UART_Send(j);
j=(temp%10000)/1000+0x30;
UART_Send(j);
j=(temp%1000)/100+0x30;
UART_Send(j);
j=(temp%100)/10+0x30;
UART_Send(j);
j=temp%10+0x30;
UART_Send(j);
j='?';
SBUF=j;
while(!TI);
TI=0;
j=Segment/1000+0x30;
SBUF=j;
while(!TI);
TI=0;
j=(Segment%1000)/100+0x30;
SBUF=j;
while(!TI);
TI=0;
j=(Segment%100)/10+0x30;
SBUF=j;
while(!TI);
TI=0;
j=Segment%10+0x30;
SBUF=j;
while(!TI);
TI=0;
EA=1;
}
}
if(keyflag)
{
keyflag=0;
if(key==K8)
{
RAC_Read=ISD_WriteByte(0x00,0x30);
VoiceRun=0;
}
else
if(key==K1)
{
CurrentSeg=0;
ISD_PowerUp();
ISD_SetPlay();
ISD_Play();
ResetCounter();
RAC_Read=0;
}
else
if(key==K2)
{
ISD_Play();
}
else
if(key==K3)
{
CurrentSeg=0;
ISD_PowerUp();
ISD_PowerUp();
ISD_SET_REC(0);
ISD_REC();
}
else
if(key==K4)
{
ISD_REC();
}
else
if(key==K5)
{
CurrentSeg=0;
ResetCounter();
// ISD_PowerUp();
ISD_SET_MC();
ISD_MC();
}
else
if(key==K6)
{
if(CurrentSeg>1)
CurrentSeg--;
Search_Segment(CurrentSeg);
}
else
if(key==K7)
{
ISD_MC();
}
}
if(sec_flag)
{
sec_flag=0;
if(!VoiceRun)
{
if(sec_count==start)
{
Search_Segment(CurrentSeg);
ISD_Play();
CurrentSeg++;
start=GetStartDelay(CurrentSeg);
}
}
}
if(VoiceRun)
{
RAC_Count=ByteToInt(TL1,TH1);
DispIntToLED(RAC_Read+RAC_Count);
}
else
{
DispIntToLED(sec_count);
}
}
}
void intex1() interrupt 2
{
RAC_Read=ISD_WriteByte(0x00,0x30);
if(OVF)
{
_nop_();
ResetCounter();
CurrentSeg=Segment;
VoiceRun=0;
}
if(EOM)
{
ResetCounter();
// CurrentSeg++;
VoiceRun=0;
}
_nop_();
}
void intex0() interrupt 0
{
uchar i;
_nop_();
i=REG_C;
sec_count++;
sec_flag=1;
if(sec_count>86400)
{
sec_count=0;
CurrentSeg=0;
start=GetStartDelay(CurrentSeg);
}
}
void intet0() interrupt 1
{
uchar i ;
TH0=0Xf6 ;
TL0=0XFF ; //1.25ms
if(row<8)
{
i=led_buffer[row];
if(row==1)
SEG7_DATA=seg7_b[i];
else
SEG7_DATA=seg7_a[i];
SEG7_SCAN=scan_tab[row];
row++;
}
else
{
row=0;
SEG7_DATA=0XFF;
SEG7_SCAN=0X00;
i=READ_KEY;
if(prekey!=i)
{
prekey=i;
if(prekey==0xff)
keyflag=1;
else
key=prekey;
}
}
_nop_();
}
bit sync;
void serial() interrupt 4
{
uchar i;
if(TI)
TI=0;
else
{
EA=0;
while(1)
{
while(!RI);
RI=0;
i=SBUF;
if((i=='R')||(i=='S')||(i=='?')||(i=='P')||(i=='B')||(i=='U'))
{
sbufcount=0;
sync=1;
}
else
if(!sync)
{
break;
}
rdata[sbufcount++]=i;
if((i==0x0d)||(sbufcount>5))
{
sbufcount=0;
BufferFlag=1;
rflag=1;
sync=0;
break;
}
}
_nop_();
EA=1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -