欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
單片機跑馬燈加音樂
[打印本頁]
作者:
進擊的蝸牛
時間:
2017-12-18 18:28
標題:
單片機跑馬燈加音樂
本帖最后由 進擊的蝸牛 于 2017-12-18 19:49 編輯
下面是我的程序以及錯誤求大師們幫我改一下,最后是跑馬燈加音樂就行,我用的是AT89C52
#include "reg52.h"
sbit key1=P0^0;
sbit key2=P0^1;
sbit key3=P0^2;
sbit key4=P0^3;
sbit key5=P0^4;
sbit key6=P0^5;
sbit key7=P0^6;
sbit key8=P0^7;
#include <INTRINS.H>
sbit Beep = P1^2;
unsigned char n=0; //n為節(jié)拍常數變量
unsigned char code music_tab[] ={
0x18, 0x30, 0x1C , 0x10, //格式為: 頻率常數, 節(jié)拍常數, 頻率常數, 節(jié)拍常數,
0x20, 0x40, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x10,
0x1C, 0x10, 0x18 , 0x40,
0x1C, 0x20, 0x20 , 0x20,
0x1C, 0x20, 0x18 , 0x20,
0x20, 0x80, 0xFF , 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20, 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30, 0x80 , 0xFF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x30,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x40, 0x1C , 0x20,
0x20, 0x20, 0x26 , 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00
};
void int0() interrupt 1
{ TH0=0xd8;
TL0=0xef;
n--;
}
void delay (unsigned char m) //控制頻率延時
{
unsigned i=3*m;
while(--i);
}
void delayms(unsigned char a) //豪秒延時子程序
{
while(--a);
}
void sound()
{ unsigned char p,m; //m為頻率常數變量
unsigned char i=0;
TMOD&=0x0f;
TMOD|=0x01;
TH0=0xd8;TL0=0xef;
IE=0x82;
play:
while(1)
{
a: p=music_tab[i];
if(p==0x00) { i=0, delayms(1000); goto play;} //
else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;}
else {m=music_tab[i++], n=music_tab[i++];} /
TR0=1; //開定時器1
while(n!=0) Beep=~Beep,delay(m); /
TR0=0; //關定時器1
}
}
int num=0;
int flag_hz=10;
void main()
{
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
P2=0xff;
while(1)
{
sound();
if(key1==0)
{
flag_hz=5;
}
if(key2==0)
{
flag_hz=25;
}
if(key3==0)
{
flag_hz=45;
}
if(key4==0)
{
}
if(key5==0)
{
P3=0X03;
P2=0X03;
}
if(key6==0)
{
P3=0X33;
P2=0X33;
}
if(key7==0)
{
P3=0XAA;
P2=0XAA;
}
if(key8==0)
{
P3=0X99;
P2=0X99;
}
}
}
void T0_time() interrupt 1 //50MS
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num>=flag_hz)
{
num=0;
P3=~P3;
P2=~P2;
}
}
復制代碼
警告:Build target 'Target 1'
assembling STARTUP.A51...
compiling shijian 7.c...
linking...
*** WARNING L5: CODE SPACE MEMORY OVERLAP
FROM: 000BH
TO: 000DH
Program Size: data=14.0 xdata=0 code=606
creating hex file from "shijian 7"...
"shijian 7" - 0 Error(s), 1 Warning(s).
作者:
shuisheng60
時間:
2019-2-4 05:17
這個真的不難,從數組取出的節(jié)拍作LED的按制變量
作者:
a0115674
時間:
2019-2-4 17:57
void int0() interrupt 1
void T0_time() interrupt 1
定義了兩個同級中斷函數,得去掉一個
作者:
angmall
時間:
2019-2-4 18:37
重復用同一個中斷,看一下interrupt N 這個N
作者:
a0115674
時間:
2019-2-4 20:00
void int0() interrupt 1 void T0_time() interrupt 1 定義了兩個同級中斷函數,得去掉前面那個中斷函數
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1