OK6410 timer accurately controls buzzer

Publisher:雅致小筑Latest update time:2015-05-21 Source: 51heiKeywords:ok6410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
For various instructions, please refer to the previous article on LED control: http://www.51hei.com/mcu/2503.html. Since the source code provided by Feiling is not a program for the timer to accurately control the buzzer, I wrote one myself. Comrades in the group who need the bare metal program source code can download it from my space by themselves. The program debugging is available. Please pay attention to add Feiling's int.s file, otherwise it cannot be compiled in CodeWarrior. For files with various conditions, please refer to Feiling paf. Here I only provide the program code.

 #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
global start

start    
    bl        main
    
    END

Keywords:ok6410 Reference address:OK6410 timer accurately controls buzzer

Previous article:315/433Mhz wireless learning materials
Next article:A programmer's experience and reality: I just want a warehouse!

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号