新闻中心

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

评论


技术专区

关闭