TXT

music_keil_c51

By Lester Parker,2014-09-25 12:44
16 views 0
music_keil_c51

     /*****************************************/

    /*ÎÒÕâÓÐÒ??ö?ÌÐò??Äã?Î??Ò?Ï */ /* function:?ªÉúÈÕ?ìÀÖ */

    / */

    /*****************************************/

    #include<absacc.h>

    #include<reg52.h>

    #include<intrins.h>

    #define uint unsigned int

    #define uchar unsigned char #define led RD

    #define key_rec T1

    sbit BUZZER=P3^7;//??ÉùÒô?Ú uchar code

    T0_H[16]={0xFF,0xFB,0xFB,0xFC,0xFC,0xFC,0xFD,0xFD,0xFD,0xFD,0xFE,0

    xFE,0xFE,0xFE,0xFE,0xFE};

    uchar code

    T0_L[16]={0xF1,0x4,0x90,0xC,0x44,0xAC,0x9,0x34,0x82,0xC8,0x06,0x22

    ,0x56,0x85,0x9A,0xC1};

    uchar code

    music[32]={8,0,8,9,8,0xB,0xA,0,8,0,8,9,8,0xC,0xB,0,8,0,8,0xF,0xD,0

    xB,0xA,9,0xE,0,0xE,0xD,0xB,0xC,0xB,0x0}; uchar code

    music_L[32]={2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4,2,1,1

    ,4,4,4,4,4};

    uchar a,b;

    uint second,minute;

    long t0count;

    void delay_music(uint v)

    {

    while(v!=0) v--;

    }

    void delay_music1(uint j)

    {

    while(j!=0){j--;delay_music(200);} }

    void delay_music2(uint j)

    {

    while(j!=0){j--;delay_music1(80);} }

    main()

    {//uint i;

    uchar k,n,m;

    delay_music(100);

TMOD=0x11;

    TH0=0xfc;

    TL0=0x66;

    t0count=0;

    EA=1;

    ET0=0;

    TR0=0;

    ET1=0;

    TR1=0;

    while(1)

    {

    ET1=1;

    TR1=1;

    for(k=0;k<32;k++) {

    n=music[k];

    m=music_L[k]; a=T0_H[n];

    b=T0_L[n];

    delay_music2(m); }

    }

    }

    time0() interrupt 1 using 1

    {

    TH0=0xFC;

    TL0=0x66;

    t0count=t0count+1; if (t0count==1000) {

    second++;

    if (second==60) {

    minute++;

    if (minute==60) minute=0;

    second=0;}

    t0count=0;

    }

    }

    time1 () interrupt 3 using 3

    {

    TH1=a;

    TL1=b;

    BUZZER=!BUZZER;

}

==================================================================

    ======

    ÏµÍ????? xp

    ?ª?????? Keil

    ÓïÑÔ C51

    Ê??ä ?þ?ðÒ??ðÄêÁùÔÂÁùÈÕÊ?ÈýÊ?ËÄÊ??Ö ==================================================================

    ======

    ?ÌÐòÒÑ???ý?âÊÔ

    ==================================================================

    ======

    */

    #include <reg52.h>

sbit KEY1 = P3^3;

    sbit KEY2 = P3^4;

sbit LED1 = P1^0;

    sbit LED2 = P1^1;

    //?Ë??ÉùÃ?LEDÊÇ?àµçÁ?(µÍµçÆ?)µãÁÁ #define DISLED1() LED1=0;LED2=1 #define DISLED2() LED1=1;LED2=0 #define DISBOTH() LED1=0;LED2=0 #define DISOFF() LED1=1;LED2=1

unsigned char Key_Flag;

    unsigned int Time_Count;

    void Delay10ms( unsigned char T ); void Key_Scan( void );

    void LED_Dis( void );

void main( void )

    {

     while(1)

     {

     Key_Scan();

     LED_Dis();

     }

    }

    /*

**

    ** ÑÓÊ?10ºÁÃëµÄ?ÌÐò

    **

    */

    void Delay10ms( unsigned char T ) {

     unsigned char i,j;

     for( ;T;T-- )

     for( i=0;i<65;i++ )

     for( j=0;j<50;j++);

}

    /*

    **

    ** É?Ãè???ü×Ó?ÌÐò??Èç?û??ϵÄÊÇKEY1,ÔòKey_Flag×ÔÔö

    **

    */

    void Key_Scan( void )

    {

     if( KEY1==0 )

     {

     //ÑÓÊ?Ïû??

     Delay10ms(1);

     if( KEY1==0 )

     {

     Key_Flag++;

     //µÈ?ýËÉ?ü

     while( KEY1 }

     }

     if( KEY2==0 )

     {

     Delay10ms(1);

     if( KEY2==0 )

     {

//ÖÃÒ??ö?êÖ?Î???Èç?ûKey_FlagµÄ×î?ßÎ?ÖÃÎ???Ôò˵Ã?KEY2??ÏÂ?ý

     Key_Flag|=(1<<7);

     //µÈ?ýËÉ?ü

     while( KEY2==0 );

     }

     }

    }

    /*

    **

**ÏìÓ????ü?ÌÐò

    **

    */

    void LED_Dis( void )

    {

     //Èç?ûKEY2??ÏÂ?ý

     if( Key_Flag&(1<<7) )

     {

     switch( Key_Flag )

     {

     case (1<<7)|2:{DISLED1();Delay10ms(200);DISOFF();break;}

     case (1<<7)|5:{DISBOTH();Delay10ms(200);DISOFF();break;}

     default :break;

     }

     //Çå?ýËùÓÐ?êÖ?Î?

     Key_Flag = 0;

     }

    }

    //ÓÐÎÊÌâÇëÁôÑÔ

Report this document

For any questions or suggestions please email
cust-service@docsford.com