这个是音乐程序
#include<absacc.h>
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define led RD
#define key_rec T1
sbit BUZZER= P2^7;
uchar code T0_H[16]={0xFF,0xFB,0xFB,0xFC,0xFC,0xFC,0xFD,0xFD,0xFD,0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE};
uchar code T0_L[16]={0xF1,0x4,0x90,0xC,0x44,0xAC,0x9,0x34,0x82,0xC8,0x06,0x22,0x56,0x85,0x9A,0xC1};
uchar code music[32]={8,0,8,9,8,0xB,0xA,0,8,0,8,9,8,0xC,0xB,0,8,0,8,0xF,0xD,0xB,0xA,9,0xE,0,0xE,0xD,0xB,0xC,0xB,0x0};
uchar code music_L[32]={2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4};
uchar a,b;
uint second,minute;
long t0count;
void delay(uint v)
{
while(v!=0) v--;
}
void delay1(uint j)
{
while(j!=0){j--;delay(200);}
}
void delay2(uint j)
{
while(j!=0){j--;delay1(80);}
}
main()
{
// uint i;
uchar k,n,m;
delay(100);
TMOD=0x11;
TH0=0xfc;
TL0=0x66;
t0count=0;
EA=1;
ET0=0;
TR0=0;
ET1=0;
TR1=0;
while(1)
{
ET1=1;
TR1=1;
for(k=0;k<32;k++)
{
n=music[k];
m=music_L[k];
a=T0_H[n];
b=T0_L[n];
delay2(m);
}
}
}
time0 () interrupt 1 using 1
{
TH0=0xFC;
TL0=0x66;
t0count=t0count+1;
if (t0count==1000)
{
second++;
if (second==60)
{
minute++;
if (minute==60) minute=0;
second=0;}
t0count=0;
}
}
time1 () interrupt 3 using 3
{
TH1=a;
TL1=b;
BUZZER=!BUZZER;
}
这个是广告灯程序
#include <reg51.H>
unsigned char code table[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f,
0x7f,0xbf,0xdf,0xef,
0xf7,0xfb,0xfd,0xfe,
0x7f,0xbf,0xdf,0xef,
0xf7,0xfb,0xfd,0xfe,
0x00,0xff,0x00,0xff,
0x01};
unsigned char i;
void delay(void)
{
unsigned char m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}
void main(void)
{
while(1)
{
if(table[i]!=0x01)
{
P1=table[i];
i++;
delay();
}
else
{
i=0;
}
}
}