??? 08/13/05 22:47 Read: times |
#99357 - PWM with 8051 Responding to: ???'s previous message |
Hi Adam,
I'm trying to use an 8051 to generate a PWM and it doesn't seem to be working. Attached below is the code I used, could you help check it and point out where I made a mistake? This is for my project and I'm presently frustrated. Kindly help. Note: the values I have used are just for simulation purposes and are not mearnt to be used on the servo. #include<reg932.h> sbit pulse=P0^0; unsigned long count_high=50000; unsigned long count_low=50000; void main(void) { TMOD &= 0xF0; TMOD=0x02; EA=1; pulse=1; TH0=0xB8; TL0=0xB8; ET0=1; TR0=1; while(1); } void x(void) interrupt 1 { if (pulse==1) { if (count_high==0) { pulse=0; count_high=50000; } else { count_high--; } } if (pulse==0) { if (count_low==0) { pulse=1; count_low= 50000; } else { count_low--; } } } |