- This topic has 1 reply, 2 voices, and was last updated 12 years, 4 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 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
Hi Chan,
Kindly add appropriate comments to your code and post again keeping the proper intendation. You will surely get help, and you must help others to read and understand your logic which is done in your code.