发布时间 : 星期一 文章模拟电子琴发声控制系统 - 图文更新完毕开始阅读8744a929cc175527072208e2
单片机课程设计
附录二:
10
单片机课程设计
附录三:
#include
void sound1(unsigned char y2); void game(void);
void sound (unsigned char y1,y2);
unsigned int n1=0,n2=0,n3=0,n4=0,n5=0,n6=0,n7=0;
unsigned char table[6]={0xd0,0x89,0xcd,0xb7,0xc2,0xa2}; unsigned char c=0,x=0,neng=0,fu=0,n8=0,n9=0,y=0,n10=0;
unsignedcharyinji[3][7]={38,34,30,28,26,23,20,19,17,15,14,13,11,10,9,8,7,6,5,4,3}; unsigned char deng[8]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf};
unsigned char tong1[24]={1,6,7,6,5,4,5,6,5,4,3,5,6,3,5,4,6,7,6,5,4,5,6,5}; unsigned char tong2[24]={4,4,4,8,4,4,8,4,4,4,4,2,2,2,2,8,4,4,8,4,4,8,4,4}; void main() {P0M1=0x00; P0M0=0x20; P3M1=0x00; P3M0=0x10; TMOD= 0x22; //设置定时器模式 TL1 = 0xA4; //设置定时初值
11
单片机课程设计
TH1 = 0xA4; //设置定时重载值 TL0 = 0xA4; //设置定时初值 TH0 = 0xA4; //设置定时重载值 TF0 = 0; //清除TF0标志 EA=1; ET1=1; ET0=1; TF1 = 0; //清除TF1标志 TR1 = 1; //定时器1开始计时 k=0; while(1) {
P2=table[n3]; a7=1; a3=a4=0; if(a7==0)
{Delay20ms(); if(a7==0) {a3=1; if(a7!=0) n2=1; else n2=2; Delay300ms(); } }
switch(n2)
{case 1:n3=(1+n3)%3;n2=0;break; case 2:goto out;break; default:break; } }
out: a6=1; TR1=0; neng=1; if(n3==0) play(); neng=2; if(n3==2) listen(); if(n3==1) game();
12
单片机课程设计
}
void inte1(void) interrupt 1 { n5++; if(n5==x) {n5=0;
c=(++c)%2; k=c; }
TF0=0; }
void inte(void) interrupt 3 {if(neng==0) {n4++;
if(n4==2000) {n4=0;
c=(++c)%2; a6=c; } }
if(neng==1) {n4++;
if(n4==625*tong2[n8]) { n8++; n4=0; TR1=0; } }
if(neng==2) {n4++;
if(n4==625*tong2[n8]) { n8++; n4=0; TR1=0; } }
TF1=0; }
void listen(void) {
x=tong1[0];
13