1、实验环境:win732位系统,keil2,proteus7.5sp3。
2、实验目的:学习通过编程时钟0工作方式1中断法控制数码管0-59变化。
3、实验连接图。
4、实验代码。
#include<reg52.h>
unsigned char seg7code[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x00};
unsigned char second;
unsigned char tcount;
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
tcount=0;
second=0;
P1=seg7code[second/10];
P2=seg7code[second%10];
while(1);
}
void timer0(void)interrupt 1
{
tcount++;
if(tcount==20)
{
tcount=0;
second++;
if(second==60)
{
second=0;
}
P1=seg7code[second/10];//显示秒的十位
P2=seg7code[second%10];//显示秒的个位
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
5、实验结果:
6、实验体会:
今天,进行了时钟0工作方式1中断法控制数码管0-59变化的实验,了解了51单片机的时钟作用,还学会了连接单片机的最小系统,对单片机的理解进一步加深,有所收获,感觉棒棒哒,继续加油。