新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > ok6410定時器精確控制蜂鳴器

ok6410定時器精確控制蜂鳴器

作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
各種說明請參見上一篇led控制:http://www.51hei.com/mcu/2503.html 由于飛凌提供的源碼并不是定時器精確控制蜂鳴器的程序,所以自己寫了一個,群里需要裸機(jī)程序源碼的同志們可以自行在我空間下載,程序調(diào)試可用,注意添加飛凌的int.s文件,否則在codewarrior無法編譯,各種條件的文件請參詳飛凌paf,這里我只提供個程序代碼。

#define GPFCON(*(volatile unsigned*)(0x7F0080A0))
#define GPFDAT(*(volatile unsigned*)(0x7F0080A4))
#define GPFPUD(*(volatile unsigned*)(0x7F0080A8))

本文引用地址:http://m.butianyuan.cn/article/201612/324181.htm

#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



評論


技術(shù)專區(qū)

關(guān)閉