现在学到定时器了,变了一个程序:三种数据顺序循环显示,定时器控制。问题是程序可以编译,但是显示有问题,好像是各类数据叠加,显示程序调试都没有问题,不知问题出在哪了,求帮助,给看看哪里不对。万分感谢。
FUNN.h:
sfr P0M0=0x93;
sfr P0M1=0x94;
sfr P1M0=0x91;
sfr P1M1=0x92;
sfr P2M0=0x95;
sfr P2M1=0x96;
sfr P3M0=0xb1;
sfr P3M1=0xb2;
#define fosc 11059200L
#define T0_50ms (65536-50000*(fosc/12000000L))
sbit en1=P2^0;
sbit en2=P2^1;
sbit en3=P2^2;
sbit en4=P2^3;
unsigned char count_in_T0;
unsigned char display_num;
const unsigned char seg7[10]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
const unsigned char seg7a[10]={0xb0,0x9b,0xcf,0xe6,0xed,
0xf9,0x87,0xff,0xef,0xbf};
const unsigned char bat[3]={0x7c,0xdc,0x78};
void ms_delay(unsigned int t)
{
unsigned int i;
for(t;t>0;t--)
for(i=110;i>0;i--)
;
}
void display_Ligh()
{
P0=seg7[9];
en1=0;
ms_delay(1);
en1=1;
P0=seg7[8];
en2=0;
ms_delay(1);
en2=1;
P0=seg7[7];
en3=0;
ms_delay(1);
en3=1;
P0=seg7[6];
en4=0;
ms_delay(1);
en4=1;
}
void display_k()
{
P0=seg7a[7];
en1=0;
ms_delay(1);
en1=1;
P0=seg7[8];
en2=0;
ms_delay(1);
en2=1;
}
void display_bat()
{
P0=bat[0];
en1=0;
ms_delay(1);
en1=1;
P0=bat[1];
en2=0;
ms_delay(1);
en2=1;
P0=bat[2];
en3=0;
en4=0;
ms_delay(1);
en3=1;
en4=1;
}
void init_
timer()
{
TMOD=0x09;
TH0=T0_50ms>>8;
TL0=T0_50ms;
ET0=1;
}
main:
#include<reg51.h>
#include<FUNN.h>
void Timer0_interrupt() interrupt 1
{
TH0=T0_50ms>>8;
TL0=T0_50ms;
if((++count_in_T0)==20)
{
count_in_T0=0;
display_num++;
if(display_num=9)
{
display_num=0;
}
}
}
main()
{
P0M0=0xff;
P0M1=0xff;
P1M1=0x0f;
P1M0=0x00;
count_in_T0=0;
display_num=0;
en1=1;
en2=1;
en3=1;
en4=1;
EA=1;
init_timer();
while(1)
{
if(0<display_num<3)
{
display_ligh();
}
else if(3<display_num<=6)
{
display_k();
}
else
{
display_bat();
}
}
}
一周热门 更多>