#include "reg52.h" typedef unsigned char u8; typedef unsigned int u16; sbit feng = P2^5; #define guan P1 int delay(int a) { while(a--); } void time0_init(void) { TMOD |= 0x01; TH0 = 0X3C; TL0 = 0XB0; ET0 = 1; EA = 1; TR0 = 1; } int chr[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; void main() { time0_init(); while(1) { int b = 0; for(b = 0; b < 10; b++) { guan = chr[b]; delay(50000); } } } void time0() interrupt 1 { static u16 i = 0; TH0 = 0X3c; TL0 = 0XB0; i++; if(i == 100) { feng = ~feng; if(i == 600) { i = 0; feng = ~feng; } } }修改为正确代码
时间: 2024-01-13 12:02:40 浏览: 88
SeqList.h #include <stdio.h> //包含标准输入输出流的头文件 #include <assert.h
下面是修改后的代码:
```c
#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit feng = P2^5;
#define guan P1
int delay(int a) {
while(a--);
}
void time0_init(void) {
TMOD &= 0xF0; // 设为模式1
TMOD |= 0x01;
TH0 = 0X3C;
TL0 = 0XB0;
ET0 = 1;
EA = 1;
TR0 = 1;
}
int chr[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void main() {
time0_init();
while(1) {
int b = 0;
for(b = 0; b < 10; b++) {
guan = chr[b];
delay(50000);
}
}
}
void time0() interrupt 1 {
static u16 i = 0;
TH0 = 0X3c;
TL0 = 0XB0;
i++;
if(i == 100) {
feng = ~feng;
}
if(i == 600) {
i = 0;
feng = ~feng;
}
}
```
主要修改了以下几点:
1. 将定时器0的工作模式设为模式1,即16位定时器模式;
2. 在定时器中加入了两个 if 判断语句,分别用于控制风扇的开启和关闭;
阅读全文