我刚刚开始学习C8051F410
单片机的编程,自己参照以前51系列的单片机的程序写的一个60秒记时的程序,可是在程序运行的时候,秒的十位和个位感觉相互间有干扰,求大神指教啊!!!
#include "c8051f410.h"
/*sbit LED2=P1^2;
sbit LED3=P1^3;*/
sbit w1=P0^0;
sbit w2=P0^1;
sbit w3=P0^2;
sbit w4=P0^3;
unsigned char shuma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char miaoh,miaol;
void delay(unsigned int x)
{
while(--x);
}
void InitOSC(void)
{
P1MDIN&=~0x03;
P1SKIP|= 0x03;
P1|= 0x03;
OSCXCN=0x66;
delay(1024);
while (!(OSCXCN & 0x80));
RSTSRC = 0x06;
CLKSEL = 0x01;
OSCICN = 0x00;
}
void Init
timer0(void)
{
TH0 = 0xa6;
TL0 = 0x7c;
TMOD = 0x01;
CKCON = 0x02;
ET0=1;
TR0 = 1;
}
void display()
{
w1=1;
P2=shuma[miaol];
delay(100);
w2=1;
P2=shuma[miaoh];
delay(100);
}
void main (void)
{
PCA0MD &= ~0x40;
P0MDOUT=0xff;
P1MDOUT=0xfc;
P2MDOUT=0xff;
XBR0= 0x40;
XBR1= 0x40;
InitOSC();
InitTimer0();
EA=1;
while(1)
{
display();
}
}
void Timer0ISR(void) interrupt 1
{
static unsigned int count=0;
count++;
if(count==8)
{
count=0;
miaol++;
}
if(miaol==10)
{
miaol=0;
miaoh++;
}
if(miaoh==6)miaoh=0;
}
for(i=0;i<16;i++)
{
du(pp[i]);
ys(20);
}
x(0x90);
for(i=0;i<16;i++)
{
du(mp[i]);
ys(20);
}
x(0x88);
for(i=0;i<16;i++)
{
du(op[i]);
ys(20);
}
ys(2000);
x(0x98);
for(i=0;i<16;i++)
{
du(dm[i]);
ys(20);
}
一周热门 更多>