unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; int time=99; int t1=0; int t2=0; int i=0; void Timer0Init(void) //1毫秒 { EA=1; ET0=1; TR0 = 1; //定时器0开始计时 TMOD = 0x01; //设置定时器模式 TL0 = 0xCD; //设置定时初值 TH0 = 0xD4; //设置定时初值 } int main() { led5=0; Timer0Init(); while(1) { t1=time/10; t2=time%10; W2=0; W3=1; P0=table[t2]; delay(100); W2=1; W3=0; P0=table[t1]; delay(100); } return 0; } void time_user()interrupt 1 { TL0 = 0xCD; //设置定时初值 TH0 = 0xD4; //设置定时初值 i++; if(i==100) { led5=~led5; i=0; time--; if(time<0) { time=99; } } }
软件延时来实现呼吸灯,一路定时器控制FM
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; int time=99; int t1=0; int t2=0; int i=0; void Timer0Init(void) //1毫秒 { EA=1; ET0=1; TR0 = 1; //定时器0开始计时 TMOD = 0x01; //设置定时器模式 TL0 = 0xCD; //设置定时初值 TH0 = 0xD4; //设置定时初值 } int main() { led5=0; Timer0Init(); while(1) { t1=time/10; t2=time%10; W2=0; W3=1; P0=table[t2]; delay(100); W2=1; W3=0; P0=table[t1]; delay(100); } return 0; } void time_user()interrupt 1 { TL0 = 0xCD; //设置定时初值 TH0 = 0xD4; //设置定时初值 i++; if(i==100) { led5=~led5; i=0; time--; if(time<0) { time=99; } } }
其实这个东西挺坑的,定时器有优先级,所以选择了折中的办法
C语言题目
int main() { int N = 0; for (int x = 1; x <= 3; x++) { for (int y = 0; y <= 3; y++) { for (int z = 0; z <= 3; z++) { if (x == y || x == z || z == y) { continue; } printf("%d%d%d ", x, y, z); N++; } } } printf("共计%d个 ", N); system("pause"); return 0; }
第一个不写了,数码管平时也用不到