⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctest_twotager.c

📁 单片机98c51的一些程序代码
💻 C
字号:

//#include <AT89X51.H>
#include <REG51.H>
#include <stdio.h>

sbit    BEEP=P2^7; 
unsigned char th0_f; //在中断中装载的T0的值高8位
unsigned char tl0_f; //在中断中装载的T0的值低8位

void dems(unsigned int r5);

//----------------------------------
void delay400ms(void)
{
  unsigned char TempCycA = 5;
  unsigned int TempCycB;
  while(TempCycA--)
  {
  TempCycB=1000;//2000;//7269;
  while(TempCycB--);

  }
}

//----------------------

//定时中断0,用于产生唱歌频率
timer0() interrupt 1 
{
    TL0 =tl0_f ;TH0 =th0_f;  //调入预定时值
    BEEP =~BEEP;           //取反音乐输出IO
}

void delay(unsigned char times)
{unsigned char t,i =times;
  for(;i!=0;i--)
	for(t=500;t!=0;t--)
	;
 }

void twotager(void)
{
      unsigned char yuepu[33] ={0x44 ,0x54 ,0x64 ,0x44 ,
                                0x44 ,0x54 ,0x64 ,0x44 ,
                                0x64 ,0x74 ,0x88 ,
                                0x64 ,0x74 ,0x88 ,
                                0x82 ,0x92 ,0x82 ,0x72 ,0x64 ,0x44 ,
                                0x82 ,0x92 ,0x82 ,0x72 ,0x64 ,0x44 ,
                                0x44 ,0x84 ,0x48 ,
                                0x44 ,0x14 ,0x48 ,
                                0x00 };
      unsigned int yingao[15] ={64260, 64400, 64524, 64580,
                                64684, 64777, 64820, 64898,
                                64968, 65030, 65058, 65110,
                                65157, 65178, 65217 };
                                
unsigned int templ =0,temph =0,flag = 0; //定义循环用的变量
unsigned int b,loop,c =0,end = 30000;//loop1,loop2,loop3,
unsigned char p2k =0x00;
TMOD = 0x01;
TR0 = 0;
ET0 = 1;
EA = 1;
do{
  c++;
  dems(4);
  for (b=0; yuepu[b]!=0 ;b++) //b<33; b++) //逐个符号演奏
    {//TR0 =0;
     templ = yuepu[b] & 0x0f ;
     temph = yuepu[b] & 0xf0 ;
     temph = temph>>4;
     temph--;
     
     th0_f = (yingao[temph] ) / 256  ;
     tl0_f = (yingao[temph] ) % 256  ;
     
     TL0 = tl0_f;
     TH0 = th0_f;
     TR0 = 1;
     
     for(loop = 1;loop <= templ -1; loop++)
	   dems(templ );
     
    TR0 =0;
    
	delay(2);
       }
   }while(c < 5);  

}

void main(void)
{ while(1)
   {twotager();
	delay400ms();
   }
}

void dems(unsigned int r5)
{ 
 unsigned char r7,r3,r4,rr;
  for(rr=r5; rr!=0;rr--)
	for(r7=2; r7!=0; r7--)
    	for(r4=125; r4!=0; r4--)
    	   for(r3=248; r3!=0; r3--)	  
                    ;
 }



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -