ok6410定时器精确控制蜂鸣器
#define GPFCON(*(volatile unsigned*)(0x7F0080A0))
#define GPFDAT(*(volatile unsigned*)(0x7F0080A4))
#define GPFPUD(*(volatile unsigned*)(0x7F0080A8))
#define PCLK 66000000
#define HCLK 133000000
#define TCFG0(*(volatile unsigned*)(0x7F006000))
#define TCFG1(*(volatile unsigned*)(0x7F006004))
#define TCON(*(volatile unsigned*)(0x7F006008))
#define TCNTB0(*(volatile unsigned*)(0x7F00600C))
#define TCMPB0(*(volatile unsigned*)(0x7F006010))
#define TCNTO0(*(volatile unsigned*)(0x7F006014))
#define TCNTB1(*(volatile unsigned*)(0x7F006018))
#define TCMTB1(*(volatile unsigned*)(0x7F00601C))
#define TCNTO1(*(volatile unsigned*)(0x7F006020))
#define TCNTB2(*(volatile unsigned*)(0x7F006024))
#define TCNTO2(*(volatile unsigned*)(0x7F00602C))
#define TCNTB3(*(volatile unsigned*)(0x7F006030))
#define TCNTO3(*(volatile unsigned*)(0x7F006038))
#define TCNTB4(*(volatile unsigned*)(0x7F00603C))
#define TCNTO4(*(volatile unsigned*)(0x7F006040))
#define TINT_CSTAT(*(volatile unsigned*)(0x7F006044))
void udelay(unsigned int num)
{
unsigned int val;
val=PCLK/1000000-1;
TCFG0&=~(0xff<8);
TCFG0|=(0x00<8);
TCFG1&=~(0xf<8);
TCFG1|=(0x0<8);
TCNTB2=val;
TCON&=~(0xf<12);
TCON|=(0xb<12);
TCON&=~(2<12);
while(num--)
{
while(TCNTO2>=val>>1);
while(TCNTO2
}
}
void init(void)
{
GPFCON&=~(2<30);
GPFCON|=(1<30);
GPFPUD&=~(0x3<(2*15));
GPFDAT|=(0x8000);
}
void beep_off(void)
{
GPFDAT|=0x8000;
}
void beep_on(void)
{
GPFDAT&=0x7fff;
}
void beep(void)
{
while(1)
{
int i,j;
beep_on();
for(i=0;i<1000;i++)
udelay(1000);
beep_off();
for(j=0;j<5000;j++)
udelay(1000);
}
}
int main()
{
init();
beep();
}
int.s
IMPORT main
AREA |C$$code|, CODE, READONLY
globalstart
start
bl main
END
ok6410定时器精确控制蜂鸣 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)