新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > S3C2440-蜂鳴器

        S3C2440-蜂鳴器

        作者: 時間:2016-12-02 來源:網絡 收藏


        #define rGPBCON (*(volatile unsigned *)0x56000010)
        #define rGPBDAT (*(volatile unsigned *)0x56000014)
        #define rGPBUP (*(volatile unsigned *)0x56000018)
        #define rTCFG0 (*(volatile unsigned *)0x51000000)
        #define rTCFG1 (*(volatile unsigned *)0x51000004)
        #define rTCNTB0 (*(volatile unsigned *)0x5100000C)
        #define rTCMPB0 (*(volatile unsigned *)0x51000010)
        #define rTCON (*(volatile unsigned *)0x51000008)

        int Main(){
        rGPBCON &= 0xfffffc;
        rGPBCON |= 0x2;
        rTCFG0 &= "0xff;
        rTCFG0 |= 0x64;
        rTCFG1 &= "0xf;
        rTCFG1 |= 0x3;
        rTCNTB0 = 0x7530;
        rTCMPB0 = rTCNTB0>>1;
        rTCON &= "0x1f;
        rTCON |= (0x1)|(0x1<<1)|(0x1<<3);
        rTCON &= "2;
        while(1);
        return 0;
        }

        使用定時器產生中斷使IO電平翻轉,控制蜂鳴器:

        定時器注意設置rINTMSK開中斷,并在中斷處理程序中清除中斷請求位。rSRCPND |= 0x1<<10;rINTPND |= 0x1<<10;清除rINTPND通過設置相應為1進行清除。rSTCPND是向相應位寫數據清除。如果不清除,會一直響應這個中斷。在Main函數中清一下是為了防止以前這個位申請中斷,所以清一下,以防萬一。定時器接在APB總線上,所以用PCLK時鐘。在這里我設預分頻為0x64,除法器為16,rTCNTB0為0x7a12,所以 50M/0x64/16/0x7a12為1HZ,所以中斷周期為1s,所以每一秒蜂鳴器響一下,然后隔一秒,然后再響。

        #define rGPBCON (*(volatile unsigned *)0x56000010)
        #define rGPBDAT (*(volatile unsigned *)0x56000014)
        #define rGPBUP (*(volatile unsigned *)0x56000018)
        #define rSRCPND (*(volatile unsigned *)0x4A000000)
        #define rINTPND (*(volatile unsigned *)0x4A000010)
        #define rTCFG0 (*(volatile unsigned *)0x51000000)
        #define rTCFG1 (*(volatile unsigned *)0x51000004)
        #define rTCNTB0 (*(volatile unsigned *)0x5100000C)
        #define rTCON (*(volatile unsigned *)0x51000008)
        #define rINTMSK (*(volatile unsigned *)0x4A000008)
        #define U32 unsigned int
        #define _ISR_STARTADDRESS 0x33ffff00
        #define pISR_TIMER0 (*(unsigned *)(_ISR_STARTADDRESS+0x48))
        int count;
        void __irq Timer0_ISR(void){
        rSRCPND |= 0x1<<10;
        rINTPND |= 0x1<<10;
        count++;
        if(count %2 == 1)
        rGPBDAT |= 0x01;
        else
        rGPBDAT &= 0xfe;
        if(count == 1000)
        count = 0;
        }

        int Main(){
        count = 0;
        rGPBCON &= 0xfffffc;
        rGPBCON |= 0x1;
        rGPBDAT &= 0xffe;
        rGPBUP &= 0xfe;
        pISR_TIMER0 = (U32)Timer0_ISR;
        rSRCPND |= 0x1<<10;
        rINTPND |= 0x1<<10;
        rINTMSK &= "(0x1<<10);
        rTCFG0 &= "0xff;
        rTCFG0 |= 0x64;
        rTCFG1 &= "0xf;
        rTCFG1 |= 0x3;
        rTCNTB0 = 0x7a12;
        rTCON &= "0x1f;
        rTCON |= 0xb;
        rTCON &= "0x2;
        while(1);
        return 0;
        }

        上一頁 1 2 下一頁

        關鍵詞: S3C2440蜂鳴器PW

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 阳山县| 栾城县| 龙岩市| 长寿区| 咸宁市| 宁海县| 武汉市| 东乡族自治县| 盐池县| 合阳县| 静宁县| 南汇区| 徐汇区| 苍南县| 白城市| 乐清市| 涟水县| 浙江省| 河曲县| 博客| 永靖县| 湘阴县| 高青县| 廊坊市| 道孚县| 津市市| 兖州市| 商河县| 伊宁县| 宾阳县| 陵水| 建宁县| 澄江县| 邯郸市| 东方市| 汉阴县| 清河县| 黑龙江省| 永州市| 崇阳县| 米易县|