|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2013-3-27 14:33:29
|
显示全部楼层
z421868436 发表于 2013-3-27 11:36 ![](static/image/common/back.gif)
用过Atxmega32A4 其实应该也没那么复杂
atmle官网上面有应用文档,也有例子的
可以下载下来看一下
#include "avr_compiler.h"
#include <util/delay.h>
#include "clksys_driver.h"
#include "TC_driver.h"
#define uchar unsigned char
#define uint unsigned int
void sysclk_initial(void)
{
/* Enable internal 32 MHz ring oscillator and wait until it's
* stable. Divide clock by two with the prescaler C and set the 16M
* 32 MHz ring oscillator as the main clock source.
*/
CLKSYS_PLL_Config( OSC_PLLSRC_RC2M_gc, 16 );
CLKSYS_Enable( OSC_PLLEN_bm );
CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );
do {} while ( CLKSYS_IsReady( OSC_PLLRDY_bm ) == 0 );
CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc );
}
uint16_t period_ticks = 31250; // 31250*1024/32M = 1 second period.
void T0_init()//定时器0 定时1秒
{
TCD0.PER = 31250;//设定对比值
TCD0.CTRLA = TC_CLKSEL_DIV1024_gc;;//配置时钟分频
TCD0.INTCTRLA = TC_OVFINTLVL_MED_gc;
TCD0.INTCTRLA=(TCD0.INTCTRLA&~TC0_OVFINTLVL_gm)|TC_OVFINTLVL_MED_gc;//中断级别
PMIC_CTRL |= PMIC_MEDLVLEN_bm|PMIC_HILVLEN_bm|PMIC_LOLVLEN_bm;//PIMC级别选择与上面中断相对应
}
int main( void )
{
PORTC.DIR=0x07;//方向输出
PORTB.DIR=0xFF;
sysclk_initial();
T0_init();
sei();
while (1);
}
ISR(TCD0_OVF_vect)
{
PORTC_OUTTGL = 0x01;
}
我现在实现了 定时 灯可以1秒闪烁 但是 不知道怎么设置 计数功能,谁能指点一二 |
|