微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ok6410定时器精确控制蜂鸣器

ok6410定时器精确控制蜂鸣器

时间:12-01 来源:互联网 点击:
各种说明请参见上一篇led控制:http://www.51hei.com/mcu/2503.html 由于飞凌提供的源码并不是定时器精确控制蜂鸣器的程序,所以自己写了一个,群里需要裸机程序源码的同志们可以自行在我空间下载,程序调试可用,注意添加飞凌的int.s文件,否则在codewarrior无法编译,各种条件的文件请参详飞凌paf,这里我只提供个程序代码。

#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>1);
}
}
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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top