Skip to content

Instantly share code, notes, and snippets.

@Ryanhu1015
Last active August 27, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ryanhu1015/6d9b7377aa5328fd3784608a6b01817a to your computer and use it in GitHub Desktop.
Save Ryanhu1015/6d9b7377aa5328fd3784608a6b01817a to your computer and use it in GitHub Desktop.
embedded rookie
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