板子到了,插上电源,仿真器就显示出来。
今天搞了一下KEIL下点灯程序。工程配置:
代码:
#include "samd21.h"
void SystemInit()
{
//do nothing
}
void LED_Init(void)
{
PORT->Group[1].DIRSET.reg = PORT_PB10;
PORT->Group[1].OUTSET.reg = PORT_PB10;
}
void LED_ON(void)
{
PORT->Group[1].OUTCLR.reg = PORT_PB10;
}
void LED_OFF(void)
{
PORT->Group[1].OUTSET.reg = PORT_PB10;
}
void SysTick_Handler(void)
{
if(PORT->Group[1].OUTSET.reg == PORT_PB10)
{
LED_ON();
}
else
{
LED_OFF();
}
}
void configure_osc8m(SYSCTRL_OSC8M_Type osc8m)
{
osc8m.bit.ENABLE = 1;
SYSCTRL->OSC8M = osc8m;
}
void configure_osc8m_8m(void)
{
SYSCTRL_OSC8M_Type osc8m;
osc8m = SYSCTRL->OSC8M;
osc8m.bit.PRESC = SYSCTRL_OSC8M_PRESC_0_Val;
osc8m.bit.RUNSTDBY = 0;
osc8m.bit.ONDEMAND = 1;
configure_osc8m(osc8m);
}
void configure_dfll(SYSCTRL_DFLLCTRL_Type dfllctrl, SYSCTRL_DFLLMUL_Type dfllmul, SYSCTRL_DFLLVAL_Type dfllval)
{
SYSCTRL->DFLLCTRL.reg = dfllctrl.reg & ~SYSCTRL_DFLLCTRL_ONDEMAND;
while (!(SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_DFLLRDY)) {
/* Wait for DFLL sync */
}
SYSCTRL->DFLLMUL.reg = dfllmul.reg;
SYSCTRL->DFLLVAL.reg = dfllval.reg;
dfllctrl.bit.ENABLE = 1;
/* Write full configuration to DFLL control register */
SYSCTRL->DFLLCTRL.reg = dfllctrl.reg;
}
void configure_dfll_open_loop(void)
{
SYSCTRL_DFLLCTRL_Type dfllctrl;
SYSCTRL_DFLLMUL_Type dfllmul;
SYSCTRL_DFLLVAL_Type dfllval;
dfllctrl.bit.LLAW = 0;
dfllctrl.bit.STABLE = 0;
dfllctrl.bit.QLDIS = 0;
dfllctrl.bit.CCDIS = 0;
dfllctrl.bit.ONDEMAND = 1;
dfllctrl.bit.MODE = 0;
dfllval.bit.COARSE = (*((uint8_t*)(0x806020+7)))>>2;//0x1f / 4; /* Midpoint */
dfllval.bit.FINE = (*((uint32_t*)(0x806020+8))) & 0x3FF;//0xff / 4; /* Midpoint */
dfllmul.bit.CSTEP = 1;
dfllmul.bit.FSTEP = 1;
dfllmul.bit.MUL = 6; /* Multiply 8MHz by 6 to get 48MHz */
configure_dfll(dfllctrl, dfllmul, dfllval);
NVMCTRL->CTRLB.bit.RWS = 2;
}
void configure_gclk(GCLK_GENCTRL_Type genctrl, GCLK_GENDIV_Type gendiv)
{
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY) {
/* Wait for synchronization */
};
/* Select the correct generator */
GCLK->GENDIV.bit.ID = gendiv.bit.ID;
/* Write the new generator configuration */
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY) {
/* Wait for synchronization */
};
GCLK->GENDIV = gendiv;
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY) {
/* Wait for synchronization */
};
genctrl.bit.GENEN = GCLK->GENCTRL.bit.GENEN;
GCLK->GENCTRL = genctrl;
}
void configure_gclk_gen_dfll(void)
{
/* Change system clock to DFLL */
GCLK_GENCTRL_Type genctrl;
GCLK_GENDIV_Type gendiv;
genctrl.reg = 0;
gendiv.reg = 0;
genctrl.bit.ID = GCLK_CLKCTRL_GEN_GCLK0_Val;
gendiv.bit.ID = GCLK_CLKCTRL_GEN_GCLK0_Val;
genctrl.bit.SRC = GCLK_SOURCE_DFLL48M;
genctrl.bit.DIVSEL = 0;
genctrl.bit.IDC = 0;
genctrl.bit.OOV = 0;
genctrl.bit.RUNSTDBY = 0;
genctrl.bit.OE = 0;
gendiv.bit.DIV = 0;
configure_gclk(genctrl, gendiv);
}
int main(void)
{
long int i;
configure_osc8m_8m();
configure_dfll_open_loop();
configure_gclk_gen_dfll();
LED_Init();
while(1)
{
LED_ON();
for(i=5000000;i>0;i--);
LED_OFF();
for(i=5000000;i>0;i--);
}
}
效果图:
工程:
KEIL_LED.rar
(42.8 KB)
|
@ningling_21 :没有,看英文的吧
有没这个芯片的中文手册
@ningling_21 :是啊,搞不懂
这个板子,插针孔怎么不在一条直线上,好像有点歪歪扭扭不好焊