林霖:
能不能帮我改下程序啊。我做的也是遥控调光灯。谢谢,我的邮箱是2019770987@qq.com #include#defineucharunsignedchar#defineuint unsignedint__CONFIG(0x3B31);unsignedchar irtime;bitirpro_ok,irok;unsignedcharIRcord[4];unsignedcharirdata[33];voiddelayms(uint);voidIr_work(void);voidIrcordpro(void);voiddelay_876us(void) //876us{ #asm NEQU70H MEQU71H MOVLW 0X37 MOVWF N NOP NOP NOP NOP NOP DECFSZ N GOTO$-6 RETURN #endasm}voiddelay_1ms(void){ #asm MOVLW 0X3F MOVWF N NOP NOP NOP NOP NOP DECFSZ N GOTO$-6 RETURN #endasm}voiddelay_4730us(void) { #asm MOVLW 0X0B MOVWF M MOVLW 0X4D MOVWFN DECFSZ N GOTO$-1 DECFSZ M GOTO$-5 RETURN #endasm}voidande()//最暗的{ while(1) { TRISB=0xff; TRISD=0xff; TRISC=0xff; TRISE0=0xff; PORTC=0xff; PORTD=0xff; TRISA=0xff; GIE=1;//总中断 PEIE=1;// INTE=1;//外部中断使能 INTF=0;//外部中断标志位 INTEDG=0; INTCON=0xc0; PIE1=1; T1CON=0x21; if(irok) { Ircordpro(); irok=0; break; } }}voidINIT()//中等亮度{ while(1) { PORTD=0x00; delayms(100); PORTD=0xff; delayms(300);//这个值越小越亮 if(irok) { Ircordpro(); irok=0; break; } }} voidkuai()//最高{ while(1) { PORTD=0x00; if(irok) { Ircordpro(); irok=0; break; } }}voidinterruptcom() { irtime++;}voidConfig_Timer0() { staticunsignedchar i; staticbitstartflag; if(startflag) {delay_876us(); if(irtime=33) delay_876us(); i=0; irdata[i]=irtime; irtime=0; i++; if(i==33) {delay_4730us(); irok=1; i=0; } } else {delay_876us(); irtime=0; startflag=1; }}voidTIM0init(void){TRISB=0xff; TRISD=0; TRISC=0; TRISE0=0; PORTC=0; PORTD=0; TRISA=0xff; GIE=1;//总中断 PEIE=1;// INTE=1;//外部中断使能 INTF=0;//外部中断标志位 INTEDG=0;}voidEX0init(void){ INTCON=0xc0; PIE1=0x01; TMR1L=0x00; TMR1H=0x00; T1CON=0x21;}voidIr_work(void){ switch(IRcord[2]) { case0x45:ande();break; case0x46:INIT();break; case0x47:kuai();break; default:break; } irpro_ok=0;}voidIrcordpro(void){ unsignedchari,j,k; unsignedcharcord,value; k=1; for(i=0;i=1; } k++; } IRcord[i]=value; value=0; } irpro_ok=1;}voidmain(void){ EX0init(); TIM0init(); PORTD=0xff;//初始状态调整ff全灭 delayms(1); while(1) {delay_876us(); if(irok) { delay_876us(); Ircordpro(); irok=0; } if(irpro_ok) {delay_876us(); Ir_work(); } }}voiddelayms(uintx) {while(--x);}