Last active
August 27, 2018 14:47
-
-
Save Ryanhu1015/6d9b7377aa5328fd3784608a6b01817a to your computer and use it in GitHub Desktop.
embedded rookie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum{off, on, pwm} | |
sbit pwmOut = P0^1; | |
const int pwmValue=96;//120*0.8, which means 80% dutycycle | |
void PWM_Init(void); | |
void PWM(uint8_t status); | |
void PWM_Init(){ | |
T3YH=0x78;// 0-120 pieces | |
T3YL=0x00; | |
T3M=0xF0; // enable PWM function, also the rate of timer is fosc/1 | |
IEN2=0x02; // Enable T3 interrupt & clear T3F | |
//..some setting below | |
} | |
void PWM(uint8_t status){ | |
switch(status){ | |
case off: | |
T3M=0x00;//disable pwm | |
pwmOut=0;//gpio status low | |
break; | |
case on: | |
T3M=0x00; | |
pwmOut=1; | |
break; | |
case pwm: | |
T3M = 0xF0; | |
PWCH = 0x02; | |
PW1DH = pwmValue; | |
PW1DL = 0x00; | |
break; | |
default: | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment