单片机故障排除篇--如何判定是硬件问题还是软件问题?
【摘要】
一段代码写完了,编译下载都ok。
但是没有看到想要的结果?怎么排错???
借一个别人正常的板子是一种方法,但是镜像提供了全仿真工具,试一下吧。
新建项目:
添加time.c到工程中!
添加复用数码管。
当然程序要做微微调整。
单...
一段代码写完了,编译下载都ok。
但是没有看到想要的结果?怎么排错???
借一个别人正常的板子是一种方法,但是镜像提供了全仿真工具,试一下吧。
新建项目:
添加time.c到工程中!
添加复用数码管。
当然程序要做微微调整。
参考上例程序:
先分配管脚和端口
-
#include<8052.h>
-
-
unsigned char smgduan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0x0f8,0x80,0x90};
-
unsigned char T0RH = 0;
-
unsigned char T0RL = 0;
-
unsigned int cnt;
-
int sec;
-
int sec_all=6666;
-
int count=0;
-
void LedScan(unsigned char pos,unsigned char dispcode);
-
void EXINT0() __interrupt 0;
-
void Timer0() __interrupt 1;
-
void EXINT1() __interrupt 2;
-
void ConfigTimer0(unsigned int);
-
void main()
-
{
-
cnt = 0;
-
sec = sec_all;
-
ConfigTimer0(2);
-
IT0=1;
-
EX0=1;
-
IT1=1;
-
EX1=1;
-
PX1=1;
-
TR0=1;
-
while(1)
-
{
-
LedScan(0,smgduan[sec%10]);
-
LedScan(1,smgduan[sec/10%10]);
-
LedScan(2,smgduan[sec/100%10]);
-
LedScan(3,smgduan[sec/1000]);
-
if(count%2==0)
-
{
-
TR0 = 1;
-
}
-
else
-
{
-
TR0 = 0;
-
}
-
}
-
}
-
-
void EXINT0() __interrupt 0
-
{
-
count++;
-
}
-
void EXINT1() __interrupt 2
-
{
-
sec_all=0;
-
}
-
-
void ConfigTimer0(unsigned int ms)
-
{
-
unsigned long tmp;
-
tmp = 11059200 / 12;
-
tmp = (tmp * ms) / 1000;
-
tmp = 65536 - tmp;
-
tmp = tmp + 18;
-
T0RH = (unsigned char)(tmp>>8);
-
T0RL = (unsigned char)tmp;
-
TMOD &= 0xF0;
-
TMOD |= 0x01;
-
TH0 = T0RH;
-
TL0 = T0RL;
-
ET0 = 1;
-
}
-
-
void Timer0() __interrupt 1
-
{
-
TH0 = T0RH;
-
TL0 = T0RL;
-
cnt++;
-
if (cnt >= 5)
-
{
-
cnt = 0;
-
sec--;
-
if (sec < 0)
-
{
-
sec = sec_all;
-
}
-
}
-
}
-
-
void LedScan(unsigned char pos,unsigned char dispcode)
-
{
-
unsigned char i;
-
for(i=0;i<=pos;i++)
-
{
-
switch(pos) {
-
case(0):
-
P1_0=0;P1_1=1;P1_2=1;P1_3=1; break;
-
case(1):
-
P1_0=1;P1_1=0;P1_2=1;P1_3=1; break;
-
case(2):
-
P1_0=1;P1_1=1;P1_2=0;P1_3=1; break;
-
case(3):
-
P1_0=1;P1_1=1;P1_2=1;P1_3=0; break;
-
}
-
P0=dispcode;
-
}
-
}
-
-
#include<8052.h>
-
-
unsigned char smgduan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0x0f8,0x80,0x90};
-
unsigned char T0RH = 0;
-
unsigned char T0RL = 0;
-
unsigned int cnt;
-
int sec;
-
int sec_all=6666;
-
int count=0;
-
void LedScan(unsigned char pos,unsigned char dispcode);
-
void EXINT0() __interrupt 0;
-
void Timer0() __interrupt 1;
-
void EXINT1() __interrupt 2;
-
void ConfigTimer0(unsigned int);
-
void main()
-
{
-
cnt = 0;
-
sec = sec_all;
-
ConfigTimer0(1);
-
IT0=1;
-
EX0=1;
-
IT1=1;
-
EX1=1;
-
PX1=1;
-
TR0=1;
-
while(1)
-
{
-
LedScan(0,smgduan[sec%10]);
-
LedScan(1,smgduan[sec/10%10]);
-
LedScan(2,smgduan[sec/100%10]);
-
LedScan(3,smgduan[sec/1000]);
-
if(count%2==0)
-
{
-
TR0 = 1;
-
}
-
else
-
{
-
TR0 = 0;
-
}
-
}
-
}
-
-
void EXINT0() __interrupt 0
-
{
-
count++;
-
}
-
void EXINT1() __interrupt 2
-
{
-
sec_all=0;
-
}
-
-
void ConfigTimer0(unsigned int ms)
-
{
-
unsigned long tmp;
-
tmp = 11059200 / 12;
-
tmp = (tmp * ms) / 1000;
-
tmp = 65536 - tmp;
-
tmp = tmp + 18;
-
T0RH = (unsigned char)(tmp>>8);
-
T0RL = (unsigned char)tmp;
-
TMOD &= 0xF0;
-
TMOD |= 0x01;
-
TH0 = T0RH;
-
TL0 = T0RL;
-
ET0 = 1;
-
}
-
-
void Timer0() __interrupt 1
-
{
-
TH0 = T0RH;
-
TL0 = T0RL;
-
cnt++;
-
if (cnt >= 2)
-
{
-
cnt = 0;
-
sec--;
-
if (sec < 0)
-
{
-
sec = sec_all;
-
}
-
}
-
}
-
-
void LedScan(unsigned char pos,unsigned char dispcode)
-
{
-
unsigned char i;
-
for(i=0;i<=pos;i++)
-
{
-
switch(pos) {
-
case(0):
-
P1_0=0;P1_1=1;P1_2=1;P1_3=1; break;
-
case(1):
-
P1_0=1;P1_1=0;P1_2=1;P1_3=1; break;
-
case(2):
-
P1_0=1;P1_1=1;P1_2=0;P1_3=1; break;
-
case(3):
-
P1_0=1;P1_1=1;P1_2=1;P1_3=0; break;
-
}
-
P0=dispcode;
-
}
-
}
文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。
原文链接:zhangrelay.blog.csdn.net/article/details/121115586
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)