Code:
#include <REGX51.H> sbit PWM = P2^3; sbit TANG = P1^2; sbit GIAM = P1^5; unsigned char dem=0,tocdo=25; bit TANG1=1,TANG0=1,GIAM0=1,GIAM1=1; void timer0(void) interrupt 1 { TR0 = 0; TF0 = 0; dem++; if(dem > 100) dem = 0; if(dem<tocdo) PWM = 1; else PWM = 0; TR0 = 1; } void phimnhan() { ////////////////////////// TANG0=TANG1;TANG1=TANG; if((TANG0==1)&&(TANG1==0)) tocdo=tocdo+5; if(tocdo==55)tocdo=50; ///////////////////////////////// GIAM0=GIAM1;GIAM1=GIAM; if((GIAM0==1)&&(GIAM1==0)) tocdo=tocdo-5; if(tocdo==-5)tocdo=0; } void main(void) { TMOD = 0X02; IE = 0X82; TH0=TL0=-50; // tao tan so 0.05 ms TR0 = 1; PWM=0; while(1) { phimnhan(); } }
Comment