#include<reg52.h>
#define LCD P0
#define uchar unsigned char
unsigned char a,i,j,k;
int b;
int key=0;
sbit EN=P2^0;
sbit RW=P2^1;
sbit RS=P2^2;
sbit CS1=P2^3;
sbit CS2=P2^4;
sbit BUSY=P0^0;
sbit speaker=P1^7;
unsigned char timer0h,timer0l,time;
void delay(unsigned char t)//延迟函数
{
unsigned char t1;
unsigned long t2;
for(t1=0;t1<t;t1++)
for(t2=0;t2<8000;t2++);
}
void t0int() interrupt 1 //spk中断
{
TR0=0;
speaker=!speaker;
TH0=timer0h;
TL0=timer0l;
TR0=1;
}
void song() //音乐播放
{
TH0=timer0h;
TL0=timer0l;
TR0=1;
delay(time);
}
checkbusy() //LCD
{ EN=1;
RW=1;
RS=0;
LCD=0XFF;
if(BUSY);
}
writecode(unsigned char dat) //写命令
{ checkbusy();
EN=1;
RW=0;
RS=0;
LCD=dat;
EN=1;
EN=0;
}
writedata(unsigned char dat) //写数据
{ checkbusy();
EN=1;
RW=0;
RS=1;
LCD=dat;
EN=1;
EN=0;
}
//满屏显示图片函数
void LCDDisplay(unsigned char page,unsigned char lineaddress, unsigned char table[8][128])
{
for(i=0;i<8;i++)
{
if(lineaddress<0X80)
{
CS1=0;
CS2=0;
}
writecode(page+i);
writecode(lineaddress);
for(j=0;j<64;j++)
{
writedata(table[i][j]);
lineaddress+=1;
}
if(lineaddress>=0X80)
{
CS1=0;
CS2=1;
lineaddress=lineaddress-0X40;
}
writecode(page+i);
writecode(lineaddress);
for(j=64;j<128;j++)
{
writedata(table[i][j]);
lineaddress+=1;
}
if(lineaddress>=0X80)
{
lineaddress=lineaddress-0X40;
}
}
}
void lcdinti()
{
writecode(0X3F);
writecode(0XC0);
writecode(0XB8);
writecode(0X40);
}
void lcddelay(unsigned char c) //LCD液晶延迟函数
{
unsigned char a,b;
for(;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
void int0() interrupt 0 //LCD外部中断1
{
EX0=0;
lcddelay(40);
EX0=1;
key=!key;
}
main() //主函数
{
unsigned char k,i;
TMOD=1; //置CT0定时工作方式1
ET0=1;//IE=0x82 //CPU开中断,CT0开中断
EA=1;
EX0=1;
IT0=1;
while(1)
{
if(key==0)
{
LCDDisplay(0Xb8,0X40,&ch2);
i=0;
while(i<100&&key==0)
{
k=sszymmh[i]+7*sszymmh[i+1]-1;
timer0h=FREQH[k];
timer0l=FREQL[k];
time=sszymmh[i+2];
i=i+3;
song();
}
}
else
{
LCDDisplay(0Xb8,0X40,&ch1);
i=0;
while(i<100&&key==1)
{
k=sszymmh1[i]+7*sszymmh1[i+1]-1;
timer0h=FREQH[k];
timer0l=FREQL[k];
time=sszymmh1[i+2];
i=i+3;
song();
}
}
}
}
全部代码在这 |