本帖最后由 wulin 于 2017-6-30 21:10 编辑 两个方法可以解决你的问题 方法1. #include < reg51.h> #include <intrins.h> unsigned char count=0,i=0; unsigned char s=0xfe; //主函数 main ( ) { P1=0xfe; TMOD=0x00; TH0=0x63; TL0=0x18; ET0=1; EA=1; TR0=1; while(1); } //服务函数 void Timer0_int( ) interrupt 1 { count++; if (count>=100) { count=0; P1=_crol_(P1,1);//P1循环左移一位 // P1=_cror_(P1,1);//P1循环右移一位 /* i++; if(i<8) { s=s<<1; s=s^0x01; P1=s; } else i=0;*/ } TH0=0x63; TL0=0x18; } 方法2;#include < reg51.h> #include <intrins.h> unsigned char count=0,i=0; unsigned char s=0xfe; //主函数 main ( ) { P1=0xfe; TMOD=0x00; TH0=0x63; TL0=0x18; ET0=1; EA=1; TR0=1; while(1); } //服务函数 void Timer0_int( ) interrupt 1 { count++; if (count>=100) { count=0; i++; s=s<<1; s=s^0x01; P1=s; if(i>=8) { i=0; P1=s=0xfe; } } TH0=0x63; TL0=0x18; } |
中断内部有问题,自己推力一遍试试 |
在中斷的else敘述中多增加一個S=0xfe; |