C51单片机注解处的书写合理不?,单片机源程序如下:
#include<reg52.h>
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
sbit ADDR2 = P1^2;
sbit ADDR1 = P1^1;
sbit ADDR0 = P1^0;
bit flag500ms = 0;
unsigned char T0RH = 0;
unsigned char T0RL = 0;
void ConfigTimer0(unsigned int ms);
void main()
{
unsigned char i = 0;
unsigned char LedBuf[8] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
EA = 1;
ConfigTimer0(10);
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while(1)
{
if(flag500ms == 1)
{
flag500ms = 0;
P0 = LedBuf[i++]; //这里合理不?
}
}
}
void ConfigTimer0(unsigned int ms)
{
unsigned long tmp;
tmp = 11059200/12;
tmp = (tmp * ms)/1000;
tmp = 65536 – tmp;
tmp = tmp + 12;
T0RH = (unsigned char)(tmp >> 4);
T0RL = (unsigned char)tmp;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = T0RL;
TL0 = T0RL;
ET0 = 1;
TR0 = 1;
}
void interruptTimer0() interrupt 1
{
static unsigned char tmr500ms = 0;
TH0 = T0RH;
TL0 = T0RL;
tmr500ms++;
if(tmr500ms >= 50)
{
tmr500ms = 0;
flag500ms = 1;
}
},注解处问题不大吧,但LedBuf[]数组只有8个,i累加超过7以后就…….,
wysh_2004 发表于 2021-1-17 20:23
注解处问题不大吧,但LedBuf[]数组只有8个,i累加超过7以后就…….
代码是我参考师傅的代码编的,在开发板上跑正常。让我自己怀疑这个i值,要不要加归零的语句。