?? epwm.c
字號(hào):
#include <pic18.h>#include <stdio.h>void get_dutycycle(void);void get_period(void);void update_pwm(void);extern void putch(unsigned char);unsigned int DUTYCYCLE=0x0080;unsigned char PERIOD=0xFF;void get_dutycycle(void){ ADFM=1; /* need 10 bit result, right justify */ ADCON0=0xC9; /* select the channel of the duty cycle input pot */ GODONE=1; while(!ADIF)continue; ADIF=0; DUTYCYCLE=ADRES; /*right justified 10 bit result */}void get_period(void){ ADFM=0; /* period is an 8 bit value, left justify to get result from ADRESH */ ADCON0=0xC1; /* select the channel of the period input pot */ GODONE=1; /* start A2D */ while(!ADIF)continue; ADIF=0; PERIOD=ADRESH; /* Return 8 most signifigant bits of result */ } void update_pwm(void){unsigned int percentage;static unsigned int old_percentage; get_period(); get_dutycycle(); /* update the PWM period SFR */ PR2=PERIOD;/* update the PWM duty cycle SFRs */ EDC1B0=(bit)DUTYCYCLE; EDC1B1=(bit)(DUTYCYCLE>>1); ECCPR1L=(DUTYCYCLE>>2);/* update results */ if (PERIOD==0) percentage=0xFFFF; else percentage=(DUTYCYCLE*100/PERIOD); if (percentage!=old_percentage) printf("\rPeriod: %X, Duty: %X \r",PERIOD,DUTYCYCLE); old_percentage=percentage; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -