|
借用別人一段程序,自已想修改成亮度,色溫可以分別用兩個(gè)開(kāi)關(guān)可以調(diào)節(jié)。但是死活不行,請(qǐng)哪位大師幫忙看下,是什么問(wèn)題,謝謝!- #include <REGX52.H>
- #include "Key.h"
- #include "Timer0.h"
- sbit Motor=P1^0;
- sbit Motor1=P1^1;
- unsigned char Counter,Compare,Cou,Com; //計(jì)數(shù)值和比較值,用于輸出PWM
- unsigned char KeyNum,Speed,k,S;
- void main()
- {
- Timer0_Init();
- while(1)
- {
- KeyNum=Key();
- if(KeyNum==1)
- {
- Speed++;
- Speed%=4;
- if(Speed==0){Compare=20;} //設(shè)置比較值,改變PWM占空比
- if(Speed==1){Compare=50;}
- if(Speed==2){Compare=75;}
- if(Speed==3){Compare=100;}
- }
- if(KeyNum==2)
- {
- S++;
- S%=4;
- if(S==0){Com=20;} //設(shè)置比較值,改變PWM占空比
- if(S==1){Com=50;}
- if(S==2){Com=75;}
- if(S==3){Com=100;}
- }
- }
- }
- void Timer0_Routine() interrupt 1
- {
- TL0 = 0x9C; //設(shè)置定時(shí)初值
- TH0 = 0xFF; //設(shè)置定時(shí)初值
- Counter++;
- Counter%=100; //計(jì)數(shù)值變化范圍限制在0~99
- Cou++;
- Cou%=100;
- if(Counter<Compare) //計(jì)數(shù)值小于比較值
- {
- Motor=0; //輸出1
-
- Motor1=0;
-
- //計(jì)數(shù)值大于比較值
-
- Motor=1; //輸出0
-
- Motor1=1;
-
- }
-
- //計(jì)數(shù)值變化范圍限制在0~99
- else //計(jì)數(shù)值小于比較值
- {
- Motor=0; //輸出1
-
- Motor1=1;
-
-
- //計(jì)數(shù)值大于比較值
-
- Motor=1; //輸出0
-
- Motor1=0;
-
- }
- }
復(fù)制代碼
|
|