请帮忙写一个单片机c语言程序 急急急!!!

2024-12-21 10:55:43
推荐回答(4个)
回答1:

#include
#define uchar unsigned char
#define uint unsigned int
//sbit duan=P3^6;
sbit key1=P3^2;//按key1可暂停歌曲
sbit key2=P3^3;//按key2可切换歌曲
sbit fm=P3^7;//蜂鸣器连续的IO口
sbit KK=P2^0; //点亮一个数码管
uchar count2=0;//歌曲标志
uchar timeh,timel,i;
/***********************************************************/
uchar code DSY_table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80, //0~8
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x8f}; //9,A~F
uint code tone_delay_table[]={ 64021,64103,64260,64400,64524,64580,64684,
64777,64820,64898,64968,65030,65058,65110,65157,65178}; //个音符对应的延时
uchar keyno;//定义按键得到的初值
void delay_ms(uchar x) //延时子函数
{ uchar i;
while(x--)
for(i=0;i<120;i++);
}
void keys_scan() //键盘扫描子函数
{ uchar tmp,k;
P1=0x0f;//高四位置0,放入四行
delay_ms(2);
…………………………………………

回答2:

#include
#include
typedef unsigned char byte;
#define PA8255 0x7CFF
#define PB8255 0x7DFF
#define PC8255 0x7EFF
#define CTRL8255 0x7FFF
byte code distab[ ]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
void INIT_8255(void)
{
XBYTE[CTRL8255]=0x82;
XBYTE[PA8255]=0x00;
}
void delay(void)
{
int i,j;
for(i=300;i>0;i--)
for(j=200;j>0;j--);
}
void main(void)
{
int k,l;
INIT_8255( );
while(1)
{ l=XBYTE[PB8255];
if((XBYTE[PB8255]&0x80)==0x80){
for(k=0;k<8;k++)
{ XBYTE[PA8255]=distab[k];
delay( );
} }
// if((XBYTE[PB8255]&0x80)==0) XBYTE[PA8255]=0xfe;
else- {
if((XBYTE[PB8255]&0x07)==0)XBYTE[PA8255]=0xfe;
if((XBYTE[PB8255]&0x07)==1)XBYTE[PA8255]=0xfd;
if((XBYTE[PB8255]&0x07)==2)XBYTE[PA8255]=0xfb;
if((XBYTE[PB8255]&0x07)==3)XBYTE[PA8255]=0xf7;
if((XBYTE[PB8255]&0x07)==4)XBYTE[PA8255]=0xef;
if((XBYTE[PB8255]&0x07)==5)XBYTE[PA8255]=0xdf;
if((XBYTE[PB8255]&0x07)==6)XBYTE[PA8255]=0xbf;
if((XBYTE[PB8255]&0x07)==7)XBYTE[PA8255]=0x7f;

}
}
}
给我邮箱,私聊。

回答3:

回答4:

qq wohui