|
改成這樣 PWM -->> PWM_Val
- #include "reg51.h"
- #include "intrins.h"
- #define uchar unsigned char
- #define uint unsigned int
- sbit INC=P3^4;
- sbit DEC=P3^5;
- sbit DIR=P3^6;
- sbit PWM=P3^7;
- void delay(uint);
- uint PWM_Val= 900; //改成這樣 PWM -->> PWM_Val
- void main(void)
- {
- DIR=1;
- while(1)
- {
- if(!INC)
- PWM_Val=PWM_Val>0 ? PWM_Val-1 : 0;
- if(!DEC)
- PWM_Val=PWM_Val<1000 ? PWM_Val+1: 1000;
- PWM=1;
- delay(PWM_Val);
- PWM=0;
- delay(1000-PWM_Val);
- }
- }
- void delay(uint j)
- {
- for(;j>0;j--)
- {
- _nop_ ();
- }
- }
復(fù)制代碼 |
|