|
剛學 ATXMEGA 配合簡易開發板內附的程式 及 小修改 CVAVR 自動生成SystemClock代碼,
以配合使用 WinARV 編譯的測試小程式。
文件還沒看足~ 不知這CCP=CCP_IOREG_gc;是做什麼用的?
/*
+------------------------------------------------------------------------------
| Project : LED 0.5秒閃爍 使用 PLL 8倍頻 64Mhz for miniATX_DEMO ATMEGA32A4
+------------------------------------------------------------------------------
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED_ON() PORTC.OUT&=~0x80
#define LED_OFF() PORTC.OUT|=0x80
#define LED_T() PORTC.OUT^=0x80
/*
+------------------------------------------------------------------------------
| Function : Initial_Timer
+------------------------------------------------------------------------------
*/
void Initial_Timer(void)
{
TCC1.PER = 31250; // PER = 500ms*64M/1024
TCC1.INTCTRLA=TC_OVFINTLVL_LO_gc; // Enable Timer Overflow interrupt
TCC1.CTRLA=TC_CLKSEL_DIV1024_gc; // Select clock source. 1024Div 2M/1024= 1.95K
PMIC.CTRL |= PMIC_LOLVLEN_bm; // enable low_level interrupts
}
/*
+------------------------------------------------------------------------------
| Function : Initial_SystemsClk & PLL
+------------------------------------------------------------------------------
|PLL 倍頻電路使能步驟~
|1.使能參考時鐘源 2.設置倍頻及選PLL的參考時鐘 3.等待時鐘穩定 4.使能PLL電路
|
+-------------------------------------------------------------------------------
*/
void Int_32M_RC_SystemsClk(void)
{
unsigned char n;
// Internal 32 kHz RC oscillator initialization
OSC.CTRL|=OSC_RC32KEN_bm; // Enable the internal 32 kHz RC oscillator
while ((OSC.STATUS & OSC_RC32KRDY_bm)==0);// Wait for the internal 32 kHz RC oscillator to stabilize
// Internal 32 MHz RC oscillator initialization
OSC.CTRL|=OSC_RC32MEN_bm; // Enable the internal 32 MHz RC oscillator
OSC.DFLLCTRL&= ~(OSC_RC32MCREF_bm | OSC_RC2MCREF_bm); // Internal 32 MHz RC osc. calibration reference
// clock source: 32.768 kHz Internal Osc.
DFLLRC32M.CTRL|=DFLL_ENABLE_bm;// Enable the autocalibration of the internal 32 MHz RC oscillator
while ((OSC.STATUS & OSC_RC32MRDY_bm)==0);// Wait for the internal 32 MHz RC oscillator to stabilize
// PLL initialization // Set the PLL clock source and multiplication factor
n=(OSC.PLLCTRL & (~(OSC_PLLSRC_gm | OSC_PLLFAC_gm))) | OSC_PLLSRC_RC32M_gc | 8;
CCP=CCP_IOREG_gc; // PLL clock cource: 32 MHz Internal Osc./4 // PLL multiplication factor: 8
OSC.PLLCTRL=n;
OSC.CTRL|=OSC_PLLEN_bm; // Enable the PLL
n=(CLK.PSCTRL & (~(CLK_PSADIV_gm | CLK_PSBCDIV1_bm | CLK_PSBCDIV0_bm))) |
CLK_PSADIV_1_gc | CLK_PSBCDIV_1_1_gc;
CCP=CCP_IOREG_gc; // System Clock prescaler A division factor:1 , B&C division factors: B:1,C:1
CLK.PSCTRL=n; // ClkPer4: 64 MHz // ClkPer2: 64 MHz // ClkPer: 64 MHz // ClkCPU: 64 MHz
while ((OSC.STATUS & OSC_PLLRDY_bm)==0); // Wait for the PLL to stabilize
n=(CLK.CTRL & (~CLK_SCLKSEL_gm)) | CLK_SCLKSEL_PLL_gc; // Select the system clock source: Phase Locked Loop
CCP=CCP_IOREG_gc;
CLK.CTRL=n;
OSC.CTRL&= ~(OSC_RC2MEN_bm | OSC_XOSCEN_bm); // Disable the unused oscillators: 2 MHz,
//external clock/crystal oscillator
n=CLK.LOCK | CLK_LOCK_bm; // Lock the CLK.CTRL and CLK.PSCTRL registers
CCP=CCP_IOREG_gc;
CLK.LOCK=n;
// Peripheral Clock output: Disabled
PORTCFG.CLKEVOUT=(PORTCFG.CLKEVOUT & (~PORTCFG_CLKOUT_gm)) | PORTCFG_CLKOUT_OFF_gc;
}
/*
+------------------------------------------------------------------------------
| Function : main
+------------------------------------------------------------------------------
| Description : trun on the LED
+------------------------------------------------------------------------------
*/
int main(void)
{
PORTC.DIR|=0x80; //Set Led Pin as Output
Int_32M_RC_SystemsClk(); //32M
Initial_Timer();
sei();
while(1); //Stop wait for interrput
return 0;
}
/*
+------------------------------------------------------------------------------
| Function : interrput
+------------------------------------------------------------------------------
| Description : interrput for TCC1 overflow,tig the LED1
+------------------------------------------------------------------------------
*/
ISR(TCC1_OVF_vect) //500ms
{
LED_T();
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|