求助汇编转变成C语言!!!!!!!!
一,happy birthday 生日快乐歌用21个音阶设计的程序Void happy birthday()要用C51格式写程序!
{
setb tr0(tr0=1;) ;启动定时器0
start0:
setb p3.3;
30h=0x00;
next:
mov a,30h
mov dptr,#table
inc dptr
movc a,@a+dptr
mov r5,a ;将节拍码存入r5
cjne a,#0ffh,next1
jmp ennd
next1:
clr c
mov a,dpl
subb a,#1
mov dpl,a
mov a,dph
subb a,#0
mov dph,a
mov a,30h
movc a,@a+dptr
jnz sing
clr tr0 ;休止符?是,则不发音
jmp d1 ;跳到d1
sing:
dec a ;取到的音符码减1
mov 22h,a ;存入(22h)
rl a ; 乘2
mov dptr,#table1 ;至table1取相对应的高字节
movc a,@a+dptr
mov th0,a ;取到的高字节存入TH0
mov 21h,a ;取到的高字节存入(21h)
mov a,22h ;乘2
rl a ;加1
inc a ;至table1取相对应的低位
movc a,@a+dptr
mov tl0,a ;取到低字节存入tl0
mov 20h,a ;取到低字节存入(20h)
setb tr0 ;启动timer0
d1:
call delay ;声音延时 基本单位时间 1/4拍187毫秒
inc 30h ;取简码简指针加1
inc 30h ;取简码简指针加1
jmp next ;取下一个码
ennd:
clr tr0 ;停止timer0
ret
table:
db 12,2,0,1,12,2,13,4,12,4,15,4,14,4,0,4
db 12,2,0,1,12,1,13,4,12,4,16,4,15,4,0,4
db 12,2,0,1,12,1,19,4,17,4,15,4,14,4,13,4
db 18,2,0,1,18,1,17,4,15,4,16,4,15,4,0,4
db 12,2,0,1,12,1,13,4,12,4,15,4,14,4,0,4
db 12,2,0,1,12,1,13,4,12,4,16,4,15,4,0,4
db 12,2,0,1,12,1,19,4,17,4,15,4,14,4,13,4
db 18,2,0,1,15,1,17,4,15,4,16,4,15,4,0,4,0ffh,0ffh
}
二、中断服务程序
void interrupt intt0: ;定时器中断服务程序
{
push psw :将psw的值存于堆栈区
push acc
mov tl0,20h ;将psw的值暂存于堆栈区 重设计数值
mov th0,21h
cpl p3.3 ;将输出口p3.3取反
pop acc ;至堆栈区取回psw的值
pop psw ;至堆栈区
}
三、延迟程序
void delay()用C51格式写!
{
mov r7,#02
delay0:
mov r4,#187
delay1:
mov r3,#248
djnz r3,$
djnz r4,delay1
djnz r7,delay0 ;延时因子
djnz r5,delay ;决定节拍
}
end
四、液晶显示程序
void DealyS(unsigned int dly)
{
unsigned int i;
for(;dly>0;dly--)
{
for(i=0;i<1000;i++);
}
}
五、键盘扫描处理程序(二个键)
void keyCheck(void)
{
if((Key1Flag==0)&&(KEY1==1))Key1Flag=1
else if((Key1flag==1)&&(KEY1==0))
{
DelayS(10);
if(KEY1==0)
{
Key1Flag=0;
counter++;
menu++;
}
}
if((Key2Flag==0)&&(KEY2==1))Key2Flag=1
else if((Key2flag==1)&&(KEY2==0))
{
DelayS(10);
if(KEY2==0)
{
Key1Flag=0;
counter--;
else counter=9;
}
}
if((Key3Flag==0)&&(KEY3==1))Key3Flag=1
{……}
……
}
六、键盘处理程序
void keyProcess(void)
{
switch(menu)
case0:
{
LCM_DisStr(1,1,"LCM_DisStr(1,1,"Select the following songs");
LCM_DisStr(1,1,"LCM_DisStr(1,2,"HAPPY BIRTHDAY");
LCM_DisStr(1,1,"LCM_DisStr(1,3,"My heart will go on");
LCM_DisStr(1,1,"LCM_DisStr(1,4," TAKE ME TO YOUR HEART ");
}
Case2:
{
LCM_DisStr(1,1,"LCM_DisStr(1,1," HAPPY BIRTHDAY ");
LCM_DisStr(1,1,"LCM_DisStr(1,2, "My heart will go on ");
LCM_DisStr(1,1,"LCM_DisStr(1,3, "TAKE ME TO YOUR HEART ");
LCM_DisStr(1,1,"LCM_DisStr(1,4,"NEVER ON SUNDAY ");
}
Case3:
{
LCM_DisStr(1,1,"LCM_DisStr(1,1," My heart will go on ");
LCM_DisStr(1,1,"LCM_DisStr(1,2, " TAKE ME TO YOUR HEART ");
LCM_DisStr(1,1,"LCM_DisStr(1,3, " NEVER ON SUNDAY ");
LCM_DisStr(1,1,"LCM_DisStr(1,4," SAY YOU SAY ME ");
}
Case4:
{
LCM_DisStr(1,1,"LCM_DisStr(1,1," TAKE ME TO YOUR HEART ");
LCM_DisStr(1,1,"LCM_DisStr(1,2, " NEVER ON SUNDAY ");
LCM_DisStr(1,1,"LCM_DisStr(1,3, " SAY YOU SAY ME ");
LCM_DisStr(1,1,"LCM_DisStr(1,4," THE TIME OF MY LIFE ");
}
Case5:播放乐曲
{
Happy birthday();
}
Case6:
{
……
}
}
主程序
#include "CONFIg.h"
#include "CONFIg.h"
sbit KEY1=P1^1;
sbit KEY2=P1^2;
bit Key1Flag;
bit key2Flag;
unsigned char counter,temp;
void mian(void)
{
LCM_DispIni();
LCM_DispStr(2,1,"KEy1:"
counter=0;
while(1)
{
keyCheck();
keyProcess();
}
table1:
dw 63628,63835,64021,64103,64260,64400,64524
dw 64580,64680,64777,64820,64898,64968,65030
dw 65058,65110,65157,65178,65217,65252,65283
}