📄 复件 old1700.c
字号:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit P20 =P2^0;
sbit P21 =P2^1;
uchar bdata SR0_L,SR0_H,SR1,APC_L,APC_H;
uchar ID,APCL=0,APCH=0,ISDEvent=0;
sbit INT_1700=SR0_L^4;
sbit EOM=SR0_L^3;
sbit PU_1700=SR0_L^2;
sbit FULL=SR0_L^1;
sbit CMD_ERR=SR0_L^0;
sbit REC_1700=SR1^3;
sbit PLAY_1700=SR1^2;
sbit ERASE_1700=SR1^1;
sbit RDY=SR1^0;
sbit SS = P1^2;
sbit SCLK = P1^3;
sbit MOSI = P1^4;
sbit MISO = P1^5;
uchar data databuf[3];
uchar databufpc=0,hasdata=0;
void delay_50us(uint t)
{
uchar j=0;
while(t--)
for(j=0;j<6;j++);
}
void delay(uint msec)
{
for (msec; msec > 0; msec--)
{
delay_50us(20);
}
}
uchar spio(uchar BUF_ISD) //shaoliang
{
uchar i,dat=BUF_ISD;
SCLK=1;
SS=0;
for(i=0;i<8;i++)
{
SCLK=0;
_nop_(); _nop_();_nop_(); _nop_(); _nop_();
if(dat&0X01) MOSI=1;
else MOSI=0;
dat>>=1;
if(MISO)
dat=(dat|0X80);
SCLK=1;
_nop_(); _nop_(); _nop_(); _nop_();_nop_();
}
MOSI=0;
return(dat);
}
void rdstatus()
{
spio(0x05);
spio(0x00);
spio(0x00);
SS=1;
//delay(100); //延迟100ms
SR0_L=spio(0x05);
SR0_H=spio(0x00);
SR1=spio(0x00);
}
void clrint()
{
spio(0x04); spio(0x00); SS=1;
}
pu() //power up
{
spio(0x01); spio(0x00); SS=1;
delay(120);
}
void pd() //power down
{
spio(0x07); spio(0x00); SS=1;
delay(100);
}
void reset()
{
spio(0x03); spio(0x00); SS=1;
delay(100);
}
void chk_mem()
{
spio(0x49); spio(0x00); SS=1; delay(150);
}
void stop()
{
spio(0x02);spio(0x00); SS=1;
}
void wr_apc1() //线路输入, aux 输出
{
spio(0x45); spio(0xc0); spio(0x04); // d7:d0 d11:d8
SS=1; delay(1) ;
}
void wr_nvcfg()
{
spio(0x46);spio(0x00); SS=1;
}
void setplay(uchar segment)
{
stop();
clrint();
chk_mem();
switch (segment)
{
case 0: //播放4元
spio(0x80);spio(0x00); spio(0x10);spio(0x00);spio(0x1a);spio(0x00);SS=1;
break;
case 1: //卡片无效 //播放4元
spio(0x80);spio(0x00); spio(0x1b);spio(0x00);spio(0x27);spio(0x00);SS=1;
break;
case 2: //学生卡 //卡片无效
spio(0x80);spio(0x00); spio(0x28);spio(0x00);spio(0x32);spio(0x00);SS=1;
break;
case 3: //新高职 //学生卡
spio(0x80);spio(0x00); spio(0x33);spio(0x00);spio(0x3d/*0x3D*/);spio(0x00);SS=1;
break;
case 4: //记名卡 //新高职
spio(0x80);spio(0x00); spio(0x3e);spio(0x00);spio(0x49);spio(0x00);SS=1;
break;
case 5: //家属卡 //记名卡
spio(0x80);spio(0x00); spio(0x49);spio(0x00);spio(0x53);spio(0x00);SS=1;
break;
case 6: //教工卡 //家属卡
spio(0x80);spio(0x00); spio(0x54);spio(0x00);spio(0x5D);spio(0x00);SS=1;
break;
case 7: //临时卡 //教工卡
spio(0x80);spio(0x00); spio(0x5E);spio(0x00);spio(0x67);spio(0x00);SS=1;
break;
case 8: //无效卡 //临时卡
spio(0x80);spio(0x00); spio(0x68);spio(0x00);spio(0x71);spio(0x00);SS=1;
case 9: //1 //无效卡
spio(0x80);spio(0x00); spio(0x72);spio(0x00);spio(0x76);spio(0x00);SS=1;
break;
//case 10:
// spio(0x80);spio(0x00); spio(0xBD);spio(0x00);spio(0xCB);spio(0x00);SS=1;
// break;
default:
//spio(0x80);spio(0x00); spio(0x10);spio(0x00);spio(0x2a);spio(0x00);SS=1;
break;
}
}
initisd1700()
{
dd: pu(); //上电
rdstatus();
if((PU_1700==0||CMD_ERR==1) &&ISDEvent<10)
{
ISDEvent++;
reset();
pd();
goto dd;
}
if( ISDEvent==10)
{
return;
ISDEvent=0;
}
chk_mem();
wr_apc1();
wr_nvcfg();
}
uchar yuyin_play(uchar i)
{
stop();
aa: clrint();
chk_mem();
setplay(i);
rdstatus();
if(CMD_ERR==1)
{
clrint();
goto aa;
}
_nop_();
_nop_();
_nop_();
return 1;
}
void Timer0_ISR(void)interrupt 1
{
databufpc = 0;
ET0 = 0;
TR0 = 0;
}
/*
void serial()interrupt 4 using 0
{
//命令1B+参数1B+校验1B
if(TI) return;
if (databufpc == 0)
{
ET0 = 1;
TH0 = (65536-20000)/256; //20ms
TL0 = (65536-20000)%256;
TR0 = 1;
}
databuf[databufpc]=SBUF;
databufpc++;
RI=0;
if(databufpc>2)
{
hasdata=1;
return;
}
}
*/
main()
{
uchar tmp;
TMOD=0x21;
TL1=0xfd;TH1=0xfd; //波特率9600 8数据 1停止
SCON=0xd8;
PCON &= 0x7f;
IE=0X96;
TR1=1;
EA=1;
ES = 0;
REN = 1;
RI = 0;
MOSI=0;
hasdata=0;
SBUF=0x55;while(TI==0); TI=0;
initisd1700();
SBUF=0xAA;while(TI==0); TI=0;
delay(50);
yuyin_play(2);
while(1)
{ /*
if(hasdata==1)
{
SBUF=databuf[0];while(TI==0); TI=0;
SBUF=databuf[1];while(TI==0); TI=0;
SBUF=databuf[2];while(TI==0); TI=0;
hasdata=0;
if(databuf[0]==0x55)
{
yuyin_play(databuf[1]);
databufpc=0;
SBUF=0x88;while(TI==0); TI=0;
}
}
*/
if(RI==1)
{
RI=0;
tmp=SBUF;
if(tmp>=0x80||tmp<=0x86)
{
yuyin_play(tmp-0x80);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -