C語言把主函式改成子函式,請指教(我是初學者)
想把這個程式改成子函式,加到另一個函式中,但一直有問題,我不知道main部分要怎麼改#include #include "derivative.h" void PLL_Init(void) { REFDV=1; SYNR=2; while(!(CRGFLG&0x08)); CLKSEL=0xc0;} void PWM_Init(void) { PWME_PWME1=0x00; PWMPRCLK=0x33; PWMSCLA=150; PWMSCLB=150; PWMCLK_PCLK1=1; PWMPOL_PPOL1=1; PWMCAE_CAE1=0; PWMCTL_CON01=0x00; PWMPER01=200; PWMDTY01=20; PWME_PWME1=1; }void main(void) {PLL_Init();PWM_Init();}
答案如下:
因為main函數里面的兩個子程式都沒有返回值,我覺得可以直接把兩個子程式的內容替換成main函式中兩個子程式,即:
#include
#include "derivative.h"
void main(void)
{
REFDV=1;
SYNR=2;
while(!(CRGFLG&0x08));
CLKSEL=0xc0;
PWME_PWME1=0x00;
PWMPRCLK=0x33;
PWMSCLA=150;
PWMSCLB=150;
PWMCLK_PCLK1=1;
PWMPOL_PPOL1=1;
PWMCAE_CAE1=0;
PWMCTL_CON01=0x00;
PWMPER01=200;
PWMDTY01=20;
PWME_PWME1=1;
}
C語言把主函式改成子函式,請指教(我是初學者)
想把這個程式改成子函式,加到另一個函式中,但一直有問題,我不知道main部分要怎麼改#include #include "derivative.h" void PLL_Init(void) { REFDV=1; SYNR=2; while(!(CRGFLG&0x08)); CLKSEL=0xc0;} void PWM_Init(void) { PWME_PWME1=0x00; PWMPRCLK=0x33; PWMSCLA=150; PWMSCLB=150; PWMCLK_PCLK1=1; PWMPOL_PPOL1=1; PWMCAE_CAE1=0; PWMCTL_CON01=0x00; PWMPER01=200; PWMDTY01=20; PWME_PWME1=1; }void main(void) {PLL_Init();PWM_Init();}
答案如下:
因為main函數里面的兩個子程式都沒有返回值,我覺得可以直接把兩個子程式的內容替換成main函式中兩個子程式,即:
#include
#include "derivative.h"
void main(void)
{
REFDV=1;
SYNR=2;
while(!(CRGFLG&0x08));
CLKSEL=0xc0;
PWME_PWME1=0x00;
PWMPRCLK=0x33;
PWMSCLA=150;
PWMSCLB=150;
PWMCLK_PCLK1=1;
PWMPOL_PPOL1=1;
PWMCAE_CAE1=0;
PWMCTL_CON01=0x00;
PWMPER01=200;
PWMDTY01=20;
PWME_PWME1=1;
}