📄 feedis_spi._c
字号:
#include <include.h>
volatile uchar countwait;
volatile uchar ISDstatus;
/*
MSB LSB
0b 7 6 5 4 3 2 1 0
setbit bit5-7 bit3-4 moeny wati_i voice on
cleanbit the bigest moeny s_car ready voice off
00 x
the 3 01 x*10
bits are used 10 x*100
store the 11 x*1000
sequence of moeny voice and when it becomes 111 ,play "thank you".
*/
uchar ISDmoney[5];
/*
ISDmoney[0] 个位
ISDmoney[1] 十位
ISDmoney[2] 百位
ISDmoney[3] 千位
ISDmoney[4] 车型
*/
extern uchar SPEAK;
//#pragma data:code
unsigned int voiceadd[]={
0b000000000000,0b000000000111,0b000000001110,0b000000010101,
0b000000011100,0b000000100100,0b000000101011,0b000000110011,
0b000000111011,0b000001000011,0b000001001011,0b000001010100,
0b000001011100,0b000001100100,0b000001101100,0b000001110100,
0b000001111100,0b000010000100,0b000010001100,0b000010010100,
0b000010011001,0b000010011101,0b000010100010,0b000010100111,
0b000010101100,0b000010110001,0b000010110110,0b000010111011,
0b000011000000,0b000011000101,0b000011001010,0b000011001111,
0b000011010100,0b000011011001,0b000011011110,0b000011100011,
0b000011101011,0b000011110011,0b000011111011,0b000100000011,
0b000100001011,0b000100010011,0b000100011100,0b000100100101,
0b000100101101,0b000100110000,0b000100110100,0b000100111000,
0b000100111100,0b000101000000,0b000101000100,0b000101001000,
0b000101001100,0b000101010000,0b000101010100,0b000101010110,
0b000101011000,0b000101011010,0b000101011101,0b000101100000,
0b000101100011,0b000101100101,0b000101101000,0b000101101010,
0b000101101101,0b000101110000,0b000101110100,0b000101111000,
0b000101111100,0b000110000000,0b000110000100,0b000110001000,
0b000110001100,0b000110010000,0b000110010100,0b000110011000,
0b000110011100,0b000110100000,0b000110100100,0b000110101000,
0b000110101100,0b000110110000,0b000110110100,0b000110111000,
0b000110111100,0b000111000000,0b000111000100,0b000111001000,
0b000111001100,0b000111010000,0b000111010100,0b000111011000,
0b000111011100,0b000111100000,0b000111100100,0b000111101001,
0b000111101110,0b000111110011,0b000111111000,0b000111111100,
0b001000000001,0b001000000110
};
//#pragma data:data
/***********************************************************************
Init the hardware for SPI communication
***********************************************************************/
void spi_init(void)
{
SET_MOSI();
CLEAR_SCLK();
SET_SS();
//SET_SDI_TO_OUTPUT();
//SET_SCLK_TO_OUTPUT();
//SET_SDO_TO_INPUT();
waitms(500);
}
/***********************************************************************
Write one data byte to the SPI bus
***********************************************************************/
void spi_sendbyte(unsigned char data)
{
uchar idx = 0;
uchar temp = 0;
CLEAR_SCLK();
CLEAR_MOSI();
while(idx < 8)
{
CLEAR_SCLK();
//waitus(100);
//for(temp = 0;temp < 130;temp++)
NOP();
// NOP();
// NOP();
// NOP();
if (data & 0x1) SET_MOSI(); else CLEAR_MOSI();
data >>= 1;
//for(temp = 0;temp < 20;temp++)
NOP();
NOP();
NOP();
NOP();
SET_SCLK();
//for(temp = 0;temp <130;temp++)
NOP();
//waitus(200);
idx++;
}
}
void spi_sendint(uint data)
{
uchar datatemp;
datatemp = (uchar) data;
spi_sendbyte(datatemp);
datatemp = (uchar)(data >> 8);
spi_sendbyte(datatemp);
}
unsigned char ISDplay(unsigned char num)
{
uint ADD;
CLEAR_SS(); //PULL DOWN THE SS PIN
spi_sendbyte(POWERUP);
SET_SS(); //pull up the ss pin
//waitms(10);
ADD = PLAYADD + voiceadd[num];
CLEAR_SS(); //PULL DOWN THE SS PIN
spi_sendint(ADD);
SET_SS(); //pull up the ss pin
//CLEAR_SS(); //PULL DOWN THE SS PIN
//spi_sendbyte(PLAYCURRENT);
//SET_SS(); //pull up the ss pin
return 0;
}
void ISDpowerdown(void)
{
CLEAR_SS();
spi_sendbyte(POWERDOWN);
SET_SS();
}
uchar ISDmonitor(void)
{
static uchar temp ;
//static uchar round ;
//if(ISDstatus & 1)
//{
if(ISDstatus & 0x02) //如果上一句还未讲完,不能说话
{
//countwait++;
//if(countwait < 150)
return 0;
//countwait = 0;
//ISDstatus &= ~0x02;
//SPEAK = 1;
}
ISDstatus |= 0x02;
if((ISDstatus & 0xe0) == 0xe0)
{
ISDplay(34 + ISDmoney[4] ); //播放"你好,几型车"
//ISDplay(39); //播放"你好,几型车"
ISDstatus &= 0x1f;
ISDstatus |= 0xc0;
return 0;
}
if((ISDstatus & 0xe0) == 0xc0)
{
//ISDstatus |= 0x02;
ISDplay(20); //播放"请交"
ISDstatus &= 0x1f;
ISDstatus |= 0xa0;
return 0;
}
if((ISDstatus & 0xe0) == 0xa0)
{
uchar temp1;
if(temp != 4)
temp = (ISDstatus&0x18)>> 3;
switch(temp)
{
case 3:
ISDplay(ISDmoney[temp]+82);
temp1 = 0;
while(temp1 < 3)
{
if(!ISDmoney[temp-1])
{
temp--;
}
else
{
ISDstatus &= 0b11100111;
ISDstatus += (--temp) << 3;
if((temp1 > 0) )
temp = 4;
break;
}
temp1++;
if(temp1 == 3)
{
ISDstatus &= 0x1f;
ISDstatus |= 0x80;
SPEAK = 0;
}
}
break;
case 2:
ISDplay(ISDmoney[temp]+73);
temp1 = 0;
while(temp1 < 2)
{
if(!ISDmoney[temp-1])
{
temp--;
}
else
{
ISDstatus &= 0b11100111;
ISDstatus += (--temp) << 3;
if((temp1 > 0) )
temp = 4;
break;
}
temp1++;
if(temp1 == 2)
{
ISDstatus &= 0x1f;
ISDstatus |= 0x80;
SPEAK = 0;
}
}
break;
case 1:
ISDplay(ISDmoney[temp]+64);
temp1 = 0;
while(temp1 < 1)
{
if(!ISDmoney[temp-1])
{
temp--;
}
else
{
ISDstatus &= 0b11100111;
ISDstatus += (--temp) << 3;
if((temp1 > 0) )
temp = 4;
break;
}
temp1++;
if(temp1 == 1)
{
ISDstatus &= 0x1f;
ISDstatus |= 0x80;
SPEAK = 0;
}
}
break;
case 0:
if(ISDmoney[temp])
ISDplay(ISDmoney[temp]+54);
else
ISDstatus &= 0xfd;
ISDstatus &= 0x1f;
ISDstatus |= 0x80;
SPEAK = 0;
break;
case 4:
ISDplay(54);
temp = 5;
break;
default:
break;
}
//ISDstatus |= 0x02;
//ISDstatus |= 0x02;
return 0;
}
if((ISDstatus & 0xe0) == 0x80 && SPEAK)
{
ISDplay(44); //
ISDstatus &= 0xfc;
}
//if(ISDstatus & 0x04) //paly the money voice
{
/*if((ISDstatus & 0xe0) == 0xe0) //play "thank you"
{
ISDplay(THANKYOU);
ISDstatus &= 0b11111110; //clear the bit 0,then wait for the end of this voice
return 0;
}
temp = (ISDstatus>>3) & 0x03;
ISDstatus &= 0b00000011; //clear the bit 2-bit 7
ISDstatus += temp << 2 + 3;
ISDstatus |= 0b00000010; //set the busy bit
*/
}
/*else //play the special car voice
{
ISDplay(94 + (ISDstatus>>5) & 0X07);
ISDstatus &= 0b11111110; //clear the bit 0,then voice off
return 0;
}*/
//}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -