- This topic has 0 replies, 1 voice, and was last updated 12 years, 1 month ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › pls help PWM fan
i want to use two button to control the fan speed (fast and slow)
this is the code
#include <reg52.h>
unsigned char timer1;
int time;
sbit PWM=P1^2;
void system_Ini()
{
TMOD = 0x10;
TH1 = 0xfe;
TL1 = 0x33;
TR1 = 1;
IE = 0x8A;
}
/**************************************************
Function: delay_us();
/**************************************************/
void delay_us(unsigned int x)
{
unsigned int i=0;
for(i=0;i<x;i++)
{;}
}
main()
{ time=50;
system_Ini();
while(1)
{
P2|=0xff;
if(P2==0xfe&&time<100)
{delay_us(1200);
if(P2==0xfe)
time+=1;}
if(P2==0xfd&&time>0)
{delay_us(1200);
if(P2==0xfd)
time-=1;}
if(timer1>100)
timer1=0;
if(timer1<time)
PWM=0;
else
PWM=1;
}
}
/*************************************
*************************************/
void T1zd(void) interrupt 3
{
TH1 = 0xfe; //11.0592
TL1 = 0x33;
timer1++;
}
i use the software to test
it shows the code is work?
but will test in hardware
all the thing is not work!!
I don’t know where is the problem can anyone help pls