汇编语言生日快乐音乐程序
51单片机蜂鸣器播放音乐代码(生日快乐 两只蝴蝶 祝你平安)精编版
/*生日快乐歌曲*/#include <reg51.h>#define uint unsigned int#define uchar unsigned charsbit beep = P1^5;uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159, 212,212,106,126,159,169,190,119,119,126,159,142,159,0};uchar code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};//延时void DelayMS(uint x){uchar t;while(x--) for(t=0;t<120;t++);}void PlayMusic(){uint i=0,j,k;while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){ //播放各个音符,SONG_LONG 为拍子长度for(j=0;j<SONG_LONG[i]*20;j++){beep=~beep;//SONG_TONE 延时表决定了每个音符的频率for(k=0;k<SONG_TONE[i]/3;k++);}DelayMS(10);i++;}}void main(){beep=0;while(1){PlayMusic(); //播放生日快乐DelayMS(500); //播放完后暂停一段时间}}两只蝴蝶:#include <reg51.h> // 这是单片机音乐代码生成器生成的代码#define uchar unsigned charsbit beepIO=P1^5; // 输出为P1.5 可以修改成其它IO 口uchar m,n;uchar code T[49][2]={{0,0},{0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0xB9},{0xFB,0x03 },{0xFB,0x4A},{0xFB,0x8F},{0xFB,0xCF},{0xFC,0x0B},{0xFC,0x43},{0xFC,0x78},{0xFC,0xAB},{0xFC,0xDB},{0xFD,0x08},{0xFD,0x33},{0xFD,0x5B},{0xFD,0x8 1},{0xFD,0xA5},{0xFD,0xC7},{0xFD,0xE7},{0xFE,0x05},{0xFE,0x21},{0xFE,0x3C},{0xFE,0x55},{0xFE,0x6D},{0xFE,0x84},{0xFE,0x99},{0xFE,0xAD},{0xFE,0xC0 },{0xFE,0x02},{0xFE,0xE3},{0xFE,0xF3},{0xFF,0x02},{0xFF,0x10},{0xFF,0x1D},{0xFF,0x2A},{0xFF,0x36},{0xFF,0x42},{0xFF,0x4C},{0xFF,0x56},{0xFF,0x60},{ 0xFF,0x69},{0xFF,0x71},{0xFF,0x79},{0xFF,0x81}};uchar code music[][2]={{0,4},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{14,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,24},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{21,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{14,24},{23,4},{26,4},{26,16},{26,4},{28,4},{26,4},{23,24},{21,4},{23,4},{21,8},{21,4},{23,4},{21,4},{19,4},{16 ,4},{16,2},{19,2},{19,24},{0,20},{26,4},{26,4},{28,4},{31,4},{30,4},{30,4},{28,4},{23,4},{21,4},{21,4},{23,16},{0,4},{23,4},{23,4},{26,4} ,{28,8},{28,12},{16,4},{23,4},{21,4},{21,24},{23,4},{26,4},{26,4},{23,4},{26,8},{0,4},{31,8},{30,4},{28,4},{30,4},{23,8},{0,4},{28,4},{28,4},{ 30,4},{28,4},{26,4},{23,4},{21,8},{23,4},{21,4},{23,4},{26,16},{0xFF,0xFF}};void delay(uchar p){uchar i,j;for(;p>0;p--)for(i=181;i>0;i--)for(j=181;j>0;j--);}void pause(){uchar i,j;for(i=150;i>0;i--)for(j=150;j>0;j--);}void T0_int() interrupt 1beepIO=!beepIO;TH0=T[m][0]; TL0=T[m][1];}void main(){uchar i=0;TMOD=0x01; EA=1; ET0=1;while(1){m=music[i][0];n=music[i][1];if(m==0x00){TR0=0;delay(n);i++;}else if(m==0xFF){TR0=0;delay(30);i=0;}else if(m==music[i+1][0]){TR0=1;delay(n);TR0=0;pause();i++;}else{TR0=1;delay(n);i++;}}}祝你平安:#include "reg52.h"unsigned char Count;sbit _Speak =P1^5 ;unsigned char code SONG[] ={ //祝你平安0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20, 0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20, 0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10, 0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20, 0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20, 0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20, 0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10, 0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80, 0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20, 0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20, 0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10, 0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00};void Time0_Init(){TMOD = 0x01;IE = 0x82;TH0 = 0xD8;TL0 = 0xEF; //12MZ晶振,10ms}void Time0_Int() interrupt 1{TH0 = 0xD8;TL0 = 0xEF;Count++; //长度加1}/*-------------------------------------------------功能:1MS延时子程序-------------------------------------------------*/ void Delay_xMs(unsigned int x){unsigned int i,j;for( i =0;i < x;i++ ){for( j =0;j<3;j++ );}}void Play_Song(unsigned char i){unsigned char Temp1,Temp2;unsigned int Addr;Count = 0; //中断计数器清0Addr = i * 217;while(1){Temp1 = SONG[Addr++];if ( Temp1 == 0xFF ) //休止符{TR0 = 0;Delay_xMs(100);}else if ( Temp1 == 0x00 ) //歌曲结束符{return;}else{Temp2 = SONG[Addr++];TR0 = 1;while(1){_Speak = ~_Speak;Delay_xMs(Temp1);if ( Temp2 == Count ){Count = 0;break;}}}}}/*------------------------------------------------- 功能:主程序-------------------------------------------------*/ void main(){Time0_Init(); //定时器0中断初始化while(1){Play_Song(0); //播放}}。
播放生日快乐歌曲
安徽冶金科技职业学院实训报告课题名称播放生日快乐歌系部班级学生姓名指导教师年月日一、播放生日快乐歌的原理:通过80C51乐曲播放电路中,P1.7接发声器SOND,P1.0接启动键<K0>,按一次K0就播放一遍生日快乐歌<fosc=12MHz>;控制输出方波形频率用定时/计数器比延时程序更加准确,根据C音调、半周期和fosc=12MHz条件下选T0定时器方式0计算出来的;播放乐曲,除了控制频率,还有控制时间的问题,用T0方式0控制音频频率,T1方式1控制音符节拍,编制生日快乐歌曲音符序号数组s[26]和生日快乐歌曲音符节拍长度数组L[26],两数组序号具有对应关系。
例如:播放生日快乐歌第一个音符“5”,1/8拍,取4*50ms=200ms;遇休止符0;停止发音频,但仍当做一个音符,按其节拍长短控制定时时间。
当一个音符播放结束,T1停,转入下一个音符,中间间隔延时10ms。
设T1定时时间:50ms计算T1定时初值:T1(初值)=3CB0H因此:TH1=0x3c,TL1=0xb0三、生日快乐歌曲编程:#include <reg51.h> //包含访问sfr库函数reg51.hsbit K0=P1^0; //定义启动键K0为P1.0sbit SOND=P1^7; //定义发声器SOND为P1.7unsigned char i,j; //定义字符型循环变量i(音符序数)、j(50ms整倍数)unsigned char code th[22]={ //定义音符频率定时数组高8位(12MHz,定时方式0)0,196,202,208,211,216,220,224,226,229,232,233,236,238,240,241,242,244,244,246,2 67,248};unsigned char code tl[22]={ //定义音符频率定时数组低8位(12MHz,定时方式0)0,12,27,21,7,4,16,12,4,12,9,20,2,8,6,2,22,5,26,1,4,3};unsigned char s[26]={ //定义生日快乐歌曲音符序数数组12,12,13,12,15,14,12,12,13,12,16,15,12,12,19,17,15,14,13,0,18,18,17,15,16,15}; unsigned char L[26]={ //定义生日快乐歌曲音符节拍长度数组(50ms整倍数)4,4,8,8,8,16,4,4,8,8,8,16,4,4,8,8,8,8,16,8,4,4,8,8,8,16};void main(){ //主函数unsigned int t; //定义循环变量t(用于音符发声后间隙延时)TMOD=0x10; //T0定时器方式0,T1定时器方式1TH1=0x3c;TL1=0xb0; //置T1初值50msIP=0x02;IE=0x8a; //置T0为高优先级中断,T0、T1开中断while(1){ //无限循环while(K0==1); //等待按K0按下while(K0==0); //等待按K0释放for(i=0;i<26;i++){ //歌曲音符节拍循环if(s[i]==0) {SOND=0; //若歌曲音符序数为0,停止发声TR0=0;} //T0停止运行else {TH0=th[s[i]]; //否则,置T0初值高8位(音符方波半周期)TL0=tl[s[i]]; //置T0初值低8位(音符方波半周期)TR0=1;} //T0运行j=L[i];TR1=1; //置50ms计数器初值,T1运行while(TR1==1); //等待T1停止运行TR0=0;SOND=0; //T0停止运行,停止发声for(t=0;t<2000;t++);}}} //音符间隔延时为10msvoid t0() interrupt 1 { //T0中断函数SOND=~SOND; //输出取反(产音频方波)TH0=th[s[i]]; TL0=tl[s[i]];} //重置T0初值void t1() interrupt 3 { //T1中断函数TH1=0x3c;TL1=0xb0; //重置T1初值50msif((j--)==0) TR1=0;} //若50ms计数器减1为0,T1停止四、播放生日快乐歌的步骤和调试:A.创建keil项目:1)双击桌面keil软件2)打开keil的集成开发环境3)点击菜单栏项目project选新建new project4)选择保存路径,建立项目文件夹,给项目命名并保存。
c语言几句代码生日祝福
c语言几句代码生日祝福以下是符合要求的10个C语言代码实现生日祝福的例子:1. 使用printf函数输出生日祝福语句。
```c#include <stdio.h>int main() {printf("祝你生日快乐,天天开心!\n");return 0;}```2. 使用多个printf函数输出生日祝福语句。
```c#include <stdio.h>int main() {printf("祝");printf("你");printf("生");printf("日");printf("快");printf("乐");printf(",");printf("天");printf("天");printf("开");printf("心");printf("!");printf("\n");return 0;}```3. 使用字符数组存储生日祝福语句并使用printf函数输出。
```c#include <stdio.h>int main() {char birthday[] = "祝你生日快乐,天天开心!";printf("%s\n", birthday);return 0;}```4. 使用for循环逐个输出生日祝福语句的字符。
```c#include <stdio.h>int main() {char birthday[] = "祝你生日快乐,天天开心!"; int i;for(i = 0; i < sizeof(birthday)-1; i++) {printf("%c", birthday[i]);}printf("\n");return 0;}```5. 使用while循环逐个输出生日祝福语句的字符。
汇编语言课程设计 音乐点播程序
一.背景分析及意义随着计算机的不断更新发展,计算机在各个领域的应用越来越多,更多的软件开发人员和相关技术人员在程序设计的过程中应用汇编程序或编制汇编语言。
而汇编语言做为计算机专业大学生必修之课,每个做为本专业的学生对汇编的理解和学习就显的尤为重要。
汇编语言是计算机能够提供给用户使用的最快而又最好最有效的语言,也是能够利用计算机所有硬件特性并能直接控制硬件的唯一语言。
因而,对程序的空间和时间要求很高的场合,汇编语言的应用就显的必不可少了,一些直接控制硬件的应用场合,则更是非用汇编语言不可了。
这次课程设计是在学习汇编语言与实践相结合的一次综合应用。
通过具体的问题分析、设计、调试、运行程序。
在实际问题中锻炼提高自己,增加了对本门课程内容的理解,锻炼了动手能力。
就这个程序具体而言:知道了音调与频率和时间的关系,就可以按照乐曲的曲谱将每个音符的频率和持续时间定义成两个数据表;然后编写程序依次取出表中的频率值和时间值,调用GENSOUNDF程序发出各种声音。
这个程序最终通过菜单所提示的信息选取所要欣赏的音乐,是执行此程序后,会很有速且有效的使扬声器接通并发出音频为896 Hz的声音。
二.总体设计思想ROM BIOS 中的BEEP子程序能根据BL中给出的时间计数植控制8254定时器,产生持续时间计数值控制8254定时器,产生持续时间为1个或几个0.5 秒,频率为896Hz的声音。
通过对BEEP的修改,可产生任一频率的声音。
用汇编语言写的GENSOUNG,能使Pc 机发出指定频率和指定延时的声音。
它是一个很好的通用发声程序。
组成乐曲的每个音符的频率值和持续时间定义成两个数据表,然后编程依次取出表中的频率值和时间值,调用GENSOUND程序发出各种声音。
本程序就是通过GENSOUNG程序演奏乐曲的例子。
该乐曲点播程序由一个乐曲点播主程序和五个子程序组成。
(1)歌曲设置程序;(2)打开另一个显示窗口程序;(3)接收键盘输入程序;(4)返回程序;(5)发声程序。
16X16点阵显示生日快乐C51程序
void main()
{
csh(); write(0x0c,0x01);//正常工作状态,关断模式 write(0x09,0x00);//译码选择,非 BCD 码 write(0x0a,0x0a);//亮度调节 write(0x0b,0x07);//显示位数 Initial_DS1302(); while(1)
0x00,0x80,0x01,0x02,0x06,0x02,0x78,0x82, 0x08,0x82,0x08,0x82,0x08,0x82,0x08,0x82, 0xFF,0xFE,0x48,0x82,0x08,0x82,0x08,0x82, 0x19,0x82,0x08,0x86,0x00,0x02,0x00,0x00,/*"生",2*/
}; unsigned char code tab2[]={ 0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,
0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00}; uchar code tab3[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x03,0x06,
// Delayms(200); num++;
if(num==137) num=0; for(r=0;r<105;r++)
for(j=q;j<32+q;j++) { P1=tab2[t]; KAI=1; P2=0X00; P2=tab1[j]; KAI=0; j++; KAI2=1; P2=0X00; P2=tab1[j]; KAI2=0; P0=tab3[num]; delay(40); t++; if(t==16) t=0; }
基于单片机的生日歌
/*-----------------------------
祝你生日快乐歌乐谱
乐谱存储格式为
uchar code music_srkl[]=
{音调,音长,.....,0,0};
末尾:0,0 表示结束
定时器0控制音长 定时器1控制音调
--------------------------------*/
TL1=0xb0;
TF1=0;
}
pmusic++;
}
}
/*---------------
函数名:main()
功能:主程序
-----------------*/
void main()
{
timer_init();
while(1)
{
music_play(happy_birthday);
fre=65536-1000000/midtab[*pmusic&0x0f];
else if((*pmusic&0xf0)==0x20)
fre=65536-1000000/hightab[*pmusic&0x0f];
TH0=fre/256;
TL0=fre%256;
//设置低音,中音,高音个音调的频率
uint code lowtab[7]={262,294,330,349,392,440,494};
uint code midtab[7]={523,578,659,698,784,880,988};
uint code hightab[7]={1046,1175,1318,1397,1568,1760,1976}interrupt 1 //控制音调
单片机蜂鸣器播放音乐代码生日快乐两只蝴蝶祝你平安
单片机蜂鸣器播放音乐代码生日快乐两只蝴蝶祝你平安/*生日快乐歌曲*/#include<reg51.h>#defineuintunsignedint#defineucharunsignedcharsbitbeep=P1^5;ucharcodeSONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,159,169,190,119,119,126,159,142,159,0};ucharcodeSONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};//延时voidDelayMS(uintx){uchart;while(x--)for(t=0;t<120;t++);}voidPlayMusic(){uinti=0,j,k;while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){//播放各个音符,SONG_LONG为拍子长度for(j=0;j<SONG_LONG[i]*20;j++){beep=~beep;//SONG_TONE延时表决定了每个音符的频率for(k=0;k<SONG_TONE[i]/3;k++);}DelayMS(10);i++;}}voidmain(){beep=0;while(1){PlayMusic();//播放生日快乐DelayMS(500);//播放完后暂停一段时间}}两只蝴蝶:#include<reg51.h>//这是单片机音乐代码生成器生成的代码#defineucharunsignedcharsbitbeepIO=P1^5;//输出为P1.5可以修改成其它IO口ucharcodeT[49][2]={{0,0},{0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0xB9},{ 0xFB,0x03},{0xFB,0x4A},{0xFB,0x8F},{0xFB,0xCF},{0xFC,0x0B},{0xFC,0x43},{0xFC,0x78},{0xFC,0xAB},{0xFC,0xDB},{0xFD,0x08},{0xFD,0x33},{0xFD,0x5B},{ 0xFD,0x81},{0xFD,0xA5},{0xFD,0xC7},{0xFD,0xE7},{0xFE,0x05},{0xFE,0x21},{0xFE,0x3C},{0xFE,0x55},{0xFE,0x6D},{0xFE,0x84},{0xFE,0x99},{0xFE,0xAD},{ 0xFE,0xC0},{0xFE,0x02},{0xFE,0xE3},{0xFE,0xF3},{0xFF,0x02},{0xFF,0x10},{0xFF,0x1D},{0xFF,0x2A},{0xFF,0x36},{0xFF,0x42},{0xFF,0x4C},{0xFF,0x56},{ 0xFF,0x60},{0xFF,0x69},{0xFF,0x71},{0xFF,0x79},{0xFF,0x81}};ucharcodemusic[][2]={{0,4},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4} ,{23,4},{21,4},{19,4},{16,4},{19,4},{14,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,24},{16,4},{19,4},{21,8},{21,4} ,{23,4},{21,4},{19,4},{16,4},{19,4},{21,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4} ,{23,4},{21,4},{19,4},{16,4},{19,4},{14,24},{23,4},{26,4},{26,16},{26,4},{28,4},{26,4},{23,24},{21,4},{23,4},{21,8},{21,4},{23,4} ,{21,4},{19,4},{16,4},{16,2},{19,2},{19,24},{0,20},{26,4},{26,4},{28,4},{31,4},{30,4},{30,4},{28,4},{23,4},{21,4},{21,4},{23,16},{0,4},{ 23,4},{23,4},{26,4},{28,8},{28,12},{16,4},{23,4},{21,4},{21,24},{23,4},{26,4},{26,4},{23,4},{26,8},{0,4},{31,8},{30,4},{28,4},{30,4},{23,8},{ 0,4},{28,4},{28,4},{30,4},{28,4},{26,4},{23,4},{21,8},{23,4},{21,4},{23,4},{26,16}, {0xFF,0xFF}};voiddelay(ucharp){uchari,j;for(;p>0;p--)for(i=181;i>0;i--)for(j=181;j>0;j--);}voidpause(){uchari,j;for(i=150;i>0;i--)for(j=150;j>0;j--);}voidT0_int()interrupt1{beepIO=!beepIO;TH0=T[m][0];TL0=T[m][1];}voidmain(){uchari=0;while(1){m=music[i][0];n=music[i][1];if(m==0x00){TR0=0;delay(n);i++;}elseif(m==0xFF){TR0=0;delay(30);i=0;}elseif(m==music[i+1][0]){TR0=1;delay(n);TR0=0;pause();i++;}else{TR0=1;delay(n);i++;}}}祝你平安:#include"reg52.h"unsignedcharCount;sbit_Speak=P1^5;unsignedcharcodeSONG[]={//祝你平安0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20, 0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20, 0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10, 0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20, 0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20, 0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20, 0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10, 0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80, 0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20, 0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20, 0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10, 0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00};voidTime0_Init(){TMOD=0x01;IE=0x82;TH0=0xD8;TL0=0xEF;//12MZ晶振,10ms}voidTime0_Int()interrupt1{TH0=0xD8;TL0=0xEF;Count++;//长度加1}功能:1MS延时子程序-------------------------------------------------*/ voidDelay_xMs(unsignedintx){unsignedinti,j;for(i=0;i<x;i++){for(j=0;j<3;j++);}}voidPlay_Song(unsignedchari){unsignedcharTemp1,Temp2;unsignedintAddr;Count=0;//中断计数器清0Addr=i*217;while(1){Temp1=SONG[Addr++];if(Temp1==0xFF)//休止符{TR0=0;Delay_xMs(100);}elseif(Temp1==0x00)//歌曲结束符{return;}else{Temp2=SONG[Addr++];TR0=1;while(1){_Speak=~_Speak;Delay_xMs(Temp1);if(Temp2==Count){Count=0;break;}}}}}功能:主程序-------------------------------------------------*/ voidmain(){Time0_Init();//定时器0中断初始化while(1){Play_Song(0);//播放}}。
《MCS-51单片机原理及应用》实验指导书涛
《MCS-51单片机原理与应用》实验指导书新疆水利水电学校水电机电系2010年9月前言:任务与要求一.单片机原理与应用实验的任务单片机原理与应用实验是单片机原理与应用课程的一部分,它的任务是:1.通过实验进一步了解和掌握单片机原理的基本概念、单片机应用系统的硬件设计及调试方法。
2.学习和掌握单片机应用系统程序设计基础。
3.提高应用计算机的能力及水平,提高逻辑思维及动手能力。
二.实验设备单片机实验所使用的设备由计算机、DP-51PRO单片机综合仿真试验仪,其中计算机是软件开发平台,主要完成程序编辑、编译、下载程序等任务;单片机综合仿真试验仪是硬件开发平台,是基于80C51单片机的扩展实验系统。
计算机和单片机实验开发系统之间是通过RS232串行接口进行通信的。
图1 单片机原理实验设备在计算机软件的控制下可完成单片机基本实验及综合设计性实验项目。
所有的MCS-51单片机原理与应用课程实验都在这套综合仿真试验仪上完成。
三.实验要求和成绩考核1.遵守实验室纪律,在实验室内不得随意走动、大声喧哗。
2.实验前,按实验要求事先复习与实验有关的理论知识,明确实验目的,了解实验内容和方法。
在实验过程中务必带上教材和实验文档,认真听讲,以调试为主要目的,注意观察思考,记录有关数据和程序,每次实验成绩根据完成情况给予评分。
3.按实验指导书要求进行接线和操作,经检查和指导老师同意后再通电。
小心使用机器,以免出现意外故障,若机器出现硬件故障,可报告并请求老师协调维护,勿喧哗和起哄。
4.禁止在实验室中做与实验无关的事情,特别是玩游戏者,一经发现本课程实训总成绩将减10分,发现两次实训总成绩按0分处理。
5.按规定时间完成并上交实验报告。
实验报告字迹要清楚,结论要明确,并写出程序流程图、程序、并分析实验结果、完成思考题等。
6.实验后应断电并返回WINDOWS下关闭计算机,整理实验台,恢复到实验前的情况。
第一部分 Keil C51 软件使用说明Keil C51 软件是众多单片机应用开发的优秀软件之一,它集编辑,编译,仿真于一体,支持汇编、PLM语言和C 语言的程序设计,界面友好,易学易用。
汇编音乐程序
; 画横线DRAWLINE0 MACRO START_X,START_Y,END_X,COLOR LOCAL PAINTPUSH AXPUSH BXPUSH CXPUSH DXMOV AH,0CHMOV AL,COLORMOV BX,0MOV CX,START_XMOV DX,START_YPAINT:INT 10HINC CXCMP CX,END_XJC PAINTPOP DXPOP CXPOP BXPOP AXENDM ; 画竖线DRAWLINE1 MACRO START_X,START_Y,END_Y,COLOR LOCAL PAINTPUSH AXPUSH BXPUSH CXPUSH DXMOV AH,0CHMOV AL,COLORMOV BX,0MOV CX,START_XMOV DX,START_YPAINT:INT 10HINC DXCMP DX,END_YJC PAINTPOP DXPOP CXPOP BXPOP AXENDM ; 画斜线向右倾斜DRAWOBILQUE MACRO START_X,START_Y,END_X,COLOR LOCAL PAINT2 PUSH AXPUSH BXPUSH CXPUSH DXMOV AH,0CHMOV AL,COLORMOV BX,0MOV DX,START_YMOV CX,START_XPAINT2:INT 10HDEC CXINC DXCMP CX,END_XJA PAINT2POP DXPOP CXPOP BXPOP AXENDM ; 画填充矩形DRAW MACRO START_X,START_Y,END_X,END_Y,COLORLOCAL DRAW_NEXTPUSH AXPUSH BXPUSH CXPUSH DXMOV AH,0CHMOV AL,COLORMOV BH,0号0MOV CX,START_XMOV DX,START_YDRAW_NEXT:INT 10HINC CX线CMP CX,END_X 画完JNE DRAW_NEXTMOV CX, START_XINC DXCMP DX,END_Y 画完JNE DRAW_NEXTPOP DXPOP CXPOP BXPOP AXENDMDATAS SEGMENTWHITE DB 0FFHBLACK DB 0YELLOW DB 0EEHGRAY DB 8CHOSE DB 'Chose the tone:C,F',0AH,0DH,'$'ANSWER DB 0AH,0DH,'You have chosed the tone,Now enjoy the game!$' ;TABFA DW 441,495,556,589,661,742,833;TABFB DW 495,556,624,661,742,833,935TABFC DW 192,294,330,350,393,441,495;TABFD DW 294,330,371,393,441,495,556;TABFE DW 330,371,416,441,495,556,624TABFF DW 350,393,441,467,525,589,661;TABFG DW 393,441,495,525,589,661,742;ZERO DW -1BUFFER DW 0DTIME DW 10TONEF DW 0TABOLINE DW 240,290,340,390,440,490BLACKL DW 225,275,375,425,475BLACKR DW 255,305,405,455,505写像素点设置颜色选用页列起始点行起始点画点画横比较行是否画另一行另一行的起始点比较列是否未完继续画BBL DW 180,230,330,380,430BBR DW 211,261,361,411,461WL DW 101,151,201,251,301,351,401WR DW 150,200,250,300,350,400,451DATAS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATASSTART:MOV AX,DATASMOV DS,AXCALL INITCALL OPEN ; 主界面; 画白键盘, 平行四边形MOV SI,190 ;SI=START_XMOV DI,140 ;DI=START_YMOV BP,540 ;BP=END_XDRAWW:DRAWLINE0 SI,DI,BP,WHITEDEC SIDEC BPINC DICMP DI,230JC DRAWW ;DRAW 190,120,540,140,YELLOW ; 画阴影DRAW 100,230,450,250,GRAY ; 侧面阴影MOV SI,140PAINTSIDE:DRAWOBILQUE 540,SI,450,GRAYINC SICMP SI,160JC PAINTSIDE; 黑键阴影MOV SI,140PAINTSIDE0:DRAWOBILQUE 255,SI,210,WHITEINC SICMP SI,150JC PAINTSIDE0MOV SI,140PAINTSIDE1:DRAWOBILQUE 305,SI,260,WHITE INC SICMP SI,150JC PAINTSIDE1MOV SI,140PAINTSIDE2:DRAWOBILQUE 405,SI,360,WHITE INC SICMP SI,150JC PAINTSIDE2MOV SI,140PAINTSIDE3:DRAWOBILQUE 455,SI,410,WHITE INC SICMP SI,150JC PAINTSIDE3MOV SI,140PAINTSIDE4:DRAWOBILQUE 505,SI,460,WHITE INC SICMP SI,150JC PAINTSIDE4; 画分割线MOV SI,240REDRAW0:MOV DI,SISUB DI,90DRAWOBILQUE SI,140,DI,BLACK ADD SI,50CMP SI,540JC REDRAW0MOV SI,150REDRAW1:DRAWLINE1 SI,230,250,BLACK ADD SI,50CMP SI,440JC REDRAW1 ; 画黑键盘PAINTB:MOV SI,OFFSET BLACKLMOV DI,OFFSET BLACKRMOV SI,[SI+BX]MOV BP,[DI+BX];DRAW SI,185,BP,195,BLACK MOV DI,140 ;DI=START_Y DRAWB:DRAWLINE0 SI,DI,BP,BLACK DEC SIDEC BPINC DICMP DI,185JC DRAWBADD BX,2CMP BX,9JC PAINTB ; 黑键底下阴影MOV BX,0PAINTBB:MOV SI,OFFSET BBLMOV DI,OFFSET BBRMOV SI,[SI+BX]MOV BP,[DI+BX]DRAW SI,185,BP,195,BLACK ADD BX,2;MOV DI,140 ;DI=START_Y; DRAWLINE0 SI,DI,BP,BLACK; DEC SI; DEC BP; INC DI; CMP DI,185; JC DRAWB; ADD BX,2CMP BX,9JC PAINTBB; 提示选择信息MOV AH,09HMOV DX,OFFSET CHOSEINT 21HINPUT:MOV AH,01H INT 21H CMP AL,'C' JZ CTONE CMP AL,'c' JZ CTONE CMP AL,'F' JZ FTONE CMP AL,'f' JZ FTONE JMP INPUT;C调,F调CTONE:MOV DI,OFFSET TABFCJMP ANSFTONE:MOV DI,OFFSET TABFFANS:MOV TONEF,DI ;把选择的音调标号存储在TONEF中MOV DX,OFFSET ANSWE R 示提示信息MOV AH,09HINT 21H; 获取弹奏的音符SCAN:MOV AH,00HINT 16HCMP AL,37H ;ASCII>37H, 退出JA ERRORCMP AL,31H ;ASCII<31H, 退出JC ERRORAND AX,000FH ; 将ASCII 码转换成数字MOV BUFFER,AX ;将数字存储在内存空间BUFFER中JMP PLAYERROR:CMP AL,1BHJZ EXITJMP SCANPLAY:MOV DI,TONEFDEC AXADD AX,AX ;TABFx为双字表,需要将获得的ASCII符*2 ADD DI,AXMOV BX,[DI] ; 根据按键获取的ASCII 码得到相应的频率值MOV DX,12HMOV AX,34DEH ;1.193182MHZ/BXDIV BXOUT 42H,ALMOV AL,AHOUT 42H,AL ; 画阴影抖动模拟动态效果PAINTKEY:MOV AX,BUFFERMOV SI,OFFSET WLMOV DI,OFFSET WRDEC AXADD AX,AXADD SI,AXADD DI,AXMOV SI,WORD PTR[SI]MOV DI,WORD PTR[DI]DRAW SI,230,DI,250,WHITEDRAW SI,230,DI,250,WHITECALL DELAY ; 扬声器延时MOV AX,12H ; 往扬声器送高频,模拟关闭OUT 42H,ALMOV AL,AHOUT 42H,ALJMP SCANEXIT:CALL CLOSEMOV AH,1INT 21HMOV AH,4CHINT 21HDELAY PROCMOV AH,2DHMOV CX,0MOV DX,0 INT 21H ; 设置系统时间READ:MOV AH,2CH INT 21HMOV AL,100MUL DHMOV DH,0ADD AX,DXCMP AX,DTIME JC READRET DELAY ENDPOPEN PROCPUSH AXIN AL,61HOR AL,03HOUT 61H,ALPOP AXRETOPEN ENDPCLOSE PROCPUSH AXIN AL,61HAND AL,0FCHOUT 61H,ALPOP AXRETCLOSE ENDPINIT PROCMOV AH,00HMOV AL,12H ;640*480 彩色图形INT 10HMOV AL,80H ;对8255进行初始化工作,A 口、B 口均为输出状态工作与方式0 OUT 63H,ALMOV AL,0B7H ;对计数器8254进行初始化工作,选2号计数器,且先读写低8 位后高8 位,工作与模式3OUT 43H,ALRETINIT ENDPCODES ENDSEND START。
各种版本的《生日快乐》歌
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
//<<12*12点阵+音乐产生>>
// MCU:89C51晶振:12M
//编写日期:2010。12。25
//编写人:李春起
#include <REG51.H>
#define uchar unsigned char
#define uint unsigned int
uint a=0,a1=0,a2=0;
};
//----------------音符----------------------
uint code miusdata[]={
//祝你生日快乐
64260,64260,64399,64260,64579,64524,64260,64260,
64399,64260,64684,64580,64260,64260,64898,64777,
0x0E,0x0D,0x0B,0xE7,0x2F,0x2F,0x2F,0x2F,0xEF,0x0F,0x0F,0x0F, //日
//0x0E,0x4D,0xDB,0x67,0xCF,0x4F,0x0F,0x8F,0x4F,0x4F,0x2F,0x0F, //新
//0x0E,0x0D,0x8B,0x47,0x7F,0x4F,0xCF,0x4F,0x4F,0x4F,0x4F,0x0F, //年
c语言祝福生日快乐
c语言祝福生日快乐1. 求生日祝福代码C++语言具体些什么呢?我写一个“生日快乐”吧!代码若有错,请告知。
望采纳#includeusing namespace std;int main() { cout< 2. 谁可以帮我用C语言编一个元旦快乐的程序,要输入密码才能收到祝福#includevoid main(){void best_wish_2();void best_wish_3();long int a,b,f;long intQnum[11]={583006791,296976834,624764923,649819275,3 92469764,196833458,664097911,278605171,386853508,460646 836,107986001},QNo[11]={665,849,631,485,760,266,166,869,015,959,989},e, c,d;printf("请输入你的Q号按回车:");scanf("%d",&c);for(a=0;aif(b==0){printf("你不能收到第二份礼物!\n请输入你的Q号后3位按回车:");scanf("%d",&d);for(a=0;aif(b==0) printf("五好意思你收五到这份礼物!\n");}}scanf("%d",&f);}void best_wish_2(){int a,b;for(a=1;a{if(aif(a>=4&&aif(a>=7&&aif(a>=22&&aif(a==24) printf("*");if(a==25) printf("元旦快乐(*_*)*\n");if(a>=26&&aif(a>=29&&aif(a>=43) printf("\n");}printf("你收到的是第二份礼物!");scanf("%d",&b);}void best_wish_3(){int a;printf("\n\n\n");printf("元旦快乐");printf("\n\n\n你收到的是第三份礼物!");scanf("%d",&a);}3. 请问一下用c语言写时间问候语怎么写#include#includeint main(void){int i=123456789;clock_t start, end;start = clock();while(i--);end = clock();printf("The time was: %d\n", (end - start));//单位是毫秒,注意是%d,不再是%fprintf("The time was: %f\n", (double)(end - start) / CLK_TCK);//单位是秒return 0;}。
汇编 音乐乐曲演奏程序
目录1、问题定义 (2)1.1设计目的 (2)1.2设计内容 (2)2、需求分析 (3)2.1流程图 (3)2.2通用发声程序设计原理 (4)3、详细设计 (6)3.1主要的宏和过程的实现 (6)3.1.1DISPLAY显示宏 (6)3.1.2ADDRESS音乐地址宏 (6)3.1.3MUSIC宏 (7)3.1.4通用发生程序GENSOUND (8)3.1.5WAITF延时程序 (9)3.1.6CLEAR清屏程序 (10)3.1.7RETU退出 (11)3.2主程序实现 (11)3.2.1数据段定义 (11)3.2.2堆栈段定义 (12)3.2.3初始化 (13)3.2.4程序执行过程 (13)4、系统调试 (14)5、收获体会 (17)6、附录 (18)7、参考文献 (25)1、问题定义1.1设计目的1.使学生能够较全面地巩固和应用课堂中所学的基本理论和程序设计方法,能够较熟练地完成汇编语言程序的设计和调试。
2.培养学生综合运用所学知识独立完成汇编程序课题的能力。
3.培养学生勇于探索、严谨推理、实事求是、有错必改,用实践来检验理论,全方位考虑问题等科学技术人员应具有的素质。
4.提高学生对工作认真负责、一丝不苟,对同学团结友爱,协作攻关的基本素质。
5.培养学生从资料文献、科学实验中获得知识的能力,提高学生从别人经验中找到解决问题的新途径的悟性,初步培养工程意识和创新能力。
6.对学生掌握知识的深度、运用理论去处理问题的能力、实验能力、课程设计能力、书面及口头表达能力进行考核。
1.2设计内容要求完成一个音乐程序,即通过按下键盘上某个按键就可以按预先设定的程序播放音乐或者终止程序。
(比如:按大写字母“A”,唱乐曲“玛丽有只小羔羊”;按大写字母“B”,唱乐曲“太湖船”按大写字母“C”,唱乐曲“两只老虎”;按"Q"鍵,退出。
)此程序涉及到过程和宏的调用,要求学生掌握关于过程和宏的定义和使用。
单片机汇编语言举例
动态显示字符"8051AF";============================== ;定义显示缓冲区DISP1 EQU 40HDISP2 EQU 41HDISP3 EQU 42HDISP4 EQU 43HDISP5 EQU 44HDISP6 EQU 45H;============================== ORG 0000HLJMP START;============================== ORG 0050HSTART:MOV SP,#060H ;初始化堆栈指针;初始化显示缓冲区MOV DISP1,#0FhMOV DISP2,#0AhMOV DISP3,#01hMOV DISP4,#05hMOV DISP5,#00h;MOV A,#80H ;8255方式控制字MOV DPTR,#0FF23H ;8255控制口地址MOVX @DPTR,A ;初始化8255 MAIN:ACALL DISPLAYSJMP MAIN;============================== DISPLAY:MOV R0,#DISP1MOV R2,#0FEH ;字控制MOV R3,#06HDLOOP:MOV A,@R0MOV DPTR,#LEDMAP ;取七段码表首地址MOVC A,@A+DPTRCPL AMOV DPTR,#0FF21H ;8255 PB口地址MOVX @DPTR,AMOV A,R2MOV DPTR,#0FF20H ;8255 PA口地址RL A ;显示位左移MOV R2,AINC R0ACALL DLYDJNZ R3,DLOOPRET;==============================DLY: ;延时子程序MOV R7,#02HDLY1: MOV R6,#0F0HDJNZ R6,$DJNZ R7,DLY1RET;==============================LEDMAP: ; 数码管七段显示码表(共阴)db 3fh, 06h, 5bh, 4fh, 66h, 6dh, 7dh, 07h db 7fh, 6fh, 77h, 7ch, 39h, 5eh, 79h, 71h db 00H;==============================END1到100数码管显示ORG 0000HABIT EQU 20H ;个位数存放处BBIT EQU 21H ;十位数存放处TEMP EQU 22H ;计数器寄存器START:MOV P2,#0FFHMOV TEMP,#0 ;初始化计数器STLOP:ACALL DISPLAYINC TEMPMOV A,TEMPCJNE A,#100,NEXT ;=100重来MOV TEMP,#0NEXT:LJMP STLOP;显示子程序DISPLAY: mov p0,0ffhMOV A,TEMP ;将temp中的十六进制数转换成10进制 MOV B,#10 ;10进制/10=10进制DIV ABMOV BBIT,A ;十位在aMOV ABIT,B ;个位在b;p0口接段码a,b,c,d,e,f,g, p2口接位码,选哪个数码管显示 MOV DPTR,#TAB ;指定查表启始地址MOV R0,#4DPL1:MOV R1,#250 ;显示1000次DPLOP:MOV A,ABIT ;取个位数MOVC A,@A+DPTR ;查个位数的7段代码MOV P1,A ;送出个位的7段代码CLR P2.0 ;开个位显示ACALL D1MS ;显示1msSETB P2.0MOV A,BBIT ;取十位数MOVC A,@A+DPTR ;查十位数的7段代码MOV P1,A ;送出十位的7段代码CLR P2.1 ;开十位显示ACALL D1MS ;显示1msSETB P2.1DJNZ R1,DPLOP ;100次没完循环DJNZ R0,DPL1 ;4个100次没完循环RET;1MS延时(按12MHZ算);====================================================D1MS:MOV R7,#80DJNZ R7,$RET;7段数码管各划的数字排列表TAB:DB 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0F8h,80h,90h ;不带小数点0 1 2 3 4 5 6 7 8 9END步进电机驱动,按键改变转动方向;==============================; 1 2 3 4 5 6 7 8;P1.0: H H H L L L L L;P1.1: L L H H H L L L;P1.2: L L L L H H H L;P1.3: H L L L L L H H; 9 1 3 2 6 4 C 8KEYIN BIT P3.4 ;定义按键输入FLAG BIT 00H;==============================ORG 0000HLJMP START;==============================ORG 0050HSTART:MOV SP,#060H ;初始化堆栈指针MOV P1,#08HMOV R2,#00HCLR FLAGMOV DPTR,#MOV_TABLEMAIN:ACALL KEYPROCJB FLAG,MAIN1INC R2ACALL MOVESJMP MAINMAIN1:DEC R2ACALL MOVESJMP MAIN;============================== MOVE: ;运转控制MOV A,R2ANL A,#07HMOVC A,@A+DPTRMOV P1,AACALL DLYRET;===========MOV_TABLE:DB 09H,01H,03H,02H,06H,04H,0CH,08H ;============================== KEYPROC:JB KEYIN,KEY_DONEACALL DLYACALL DLYJB KEYIN,KEY_DONECPL FLAGJNB KEYIN,$KEY_DONE:RET;============================== DLY: ;延时子程序MOV R7,#0AHDLY1: MOV R6,#0F0HDJNZ R6,$DJNZ R7,DLY1RET;==============================END左右循环点亮ORG 0000HLJMP STARTORG 0030HSTART: MOV R1,#00HDJNZ R1,$MOV SP,#60HLOOP: MOV A,#0FEHLOOP_1: MOV P1,ACALL DELAYRL ACJNE A,#7FH,LOOP_1 ;0111 1111 LOOP_2: MOV P1,ACALL DELAYRR ACJNE A,#0FEH,LOOP_2 ; 1111 1110 SJMP LOOPDELAY: MOV R0,#00HL1: MOV R1,#00H L2: DJNZ R1,L2 DJNZ R0,L1 RETEND所有灯循环点亮ORG 0000HLJMP MAINORG 0100HMAIN:MOV P1,#0FFHLCALL DELAYMOV P1,#00HLCALL DELAYLJMP MAINDELAY:MOV R7,#0D1:MOV R6,#0D2:DJNZ R6,D2DJNZ R7,D1RETEND产生方波/*用定时器T0产生50HZ的方波。