51單片機問題,自己弄的壹個電子鐘,出現數字變化很快(秒變的很快),什麽原因,求解釋
void timer0() interrupt 1
{
TH0 = (65536 - 250) / 256;
TL0 = (65536 - 250) % 256;
tcnt++;
mstcnt++;
if(tcnt == 8) { //2毫秒定時,2毫秒刷新壹次數碼管.
tcnt = 0;
P0 = duanxuan[weitable[jishu]];
P2 = xunhuan[jishu];
jishu++;
if(jishu == 6) jishu = 0;
}
if(mstcnt == 40000) { //1s時.
mstcnt = 0;
second++; //秒加1
if(second == 60) {
second = 0; //秒清零.
minite++; //分加1
if(minite == 60) {
minite = 0;
hour++;
if(hour == 24) hour = 0;
}
}
weitable[0] = second % 10;
weitable[1] = second / 10;
weitable[2] = minite % 10;
weitable[3] = minite / 10;
weitable[4] = hour % 10;
weitable[5] = hour / 10;
}
}
//===============
妳關鍵性的錯誤在於下壹條:
if(mstcnt==40000);//1s時
註意到了嗎?末尾,多了壹個分號。