我想要改变这个程序的PWM输出频率。 可是我怎么改定时器的值,输出的频率都是在2kHZ不变。请高手指教。应用的芯片是P89LPC901. Uchar code sintab[160]= { 0xFF,0xEB,0xFF,0xFA,0xFF,0xE6,0xFF,0xF0,0xFF,0xE1,0xFF,0xE6,0xFF,0xDC,0xFF,0xDC,0xFF,0xD7,0xFF,0xD2, 0xFF,0xD2,0xFF,0xC8,0xFF,0xCD,0xFF,0xBE,0xFF,0xC8,0xFF,0xB4,0xFF,0xC3,0xFF,0xAA,0xFF,0xBE,0xFF,0xA0, 0xFF,0xB4,0xFF,0xAA,0xFF,0xBE,0xFF,0xB4,0xFF,0xC3,0xFF,0xBE,0xFF,0xC8,0xFF,0xC8,0xFF,0xCD,0xFF,0xD2, 0xFF,0xD2,0xFF,0xDC,0xFF,0xD7,0xFF,0xE6,0xFF,0xDC,0xFF,0xF0,0xFF,0xE1,0xFF,0xFA,0xFF,0xE6,0xFF,0xEB, 0xFF,0xEB,0xFF,0xE6,0xFF,0xFA,0xFF,0xE1,0xFF,0xF0,0xFF,0xDC,0xFF,0xE6,0xFF,0xD7,0xFF,0xDC,0xFF,0xD2, 0xFF,0xD2,0xFF,0xCD,0xFF,0xC8,0xFF,0xC8,0xFF,0xBE,0xFF,0xC3,0xFF,0xB4,0xFF,0xBE,0xFF,0xAA,0xFF,0xB4, 0xFF,0xA0,0xFF,0xBE,0xFF,0xAA,0xFF,0xC3,0xFF,0xB4,0xFF,0xC8,0xFF,0xBE,0xFF,0xCD,0xFF,0xC8,0xFF,0xD2, 0xFF,0xD2,0xFF,0xD7,0xFF,0xDC,0xFF,0xDC,0xFF,0xE6,0xFF,0xE1,0xFF,0xF0,0xFF,0xE6,0xFF,0xFA,0xFF,0xEB, } ;
sbit OUT=P0^4;
main() { P0M1&=0xef; P0M2|=0x10; TMOD=0x11; EA=1; ET1=1; ET0=1; TR0=1; TR1=0; while(1); }
Timer0() interrupt 1 { TR0=0; OUT=1; TR1=1; }
Timer1() interrupt 3 { Uchar aa,bb; OUT=0; aa=bb*4; TR1=0; TH0=sintab[aa]; TL0=sintab[aa+1]; TH1=sintab[aa+2]; TL1=sintab[aa+3]; bb++; if(bb>39) { bb=0; } TR0=1; } |