#include<reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit DIN=P2^0;
sbit LOAD=P2^1;
sbit CLK=P2^2;
uint Disp_Buffer[6];
uint num;
uint
timer;
void WtiteMAX_7219(uchar addr,uchar dat)
{
uchar i;
LOAD=0;
for(i=0;i<8;i++)
{
CLK=0;
addr<<=1;
DIN=CY;
CLK=1;
_nop_();
_nop_();
CLK=0;
}
for(i=0;i<8;i++)
{
CLK=0;
dat<<=1;
DIN=CY;
CLK=1;
_nop_();
_nop_();
CLK=0;
}
LOAD=1;
}
void Initialise(uchar mode,uchar blink,uchar div)
{
WtiteMAX_7219(0x09,mode);
WtiteMAX_7219(0x0a,blink);
WtiteMAX_7219(0x0b,div);
WtiteMAX_7219(0x0c,0x01);
}
void InitTimer1()
{
num=0;
timer=0;
TMOD=0x10;
TH1=0x4c;
TL1=0x00;
EA=1;
ET1=1;
TR1=1;
}
void Timer1Interrupt() interrupt 0
{
TH1=0x4c;
TL1=0x00;
num++;
if(num==20)
{
num=0;
timer++;
if(timer==999999)
{
timer=0;
}
}
}
void main()
{
uint i;
Initialise(0xff,0x07,0x05);
InitTimer1();
while(1)
{
Disp_Buffer[5]=timer/100000;
Disp_Buffer[4]=timer/100000/10000;
Disp_Buffer[3]=timer/100000/10000/1000;
Disp_Buffer[2]=timer/100000/10000/1000/100;
Disp_Buffer[1]=timer/100000/10000/1000/100/10;
Disp_Buffer[0]=timer/100000/10000/1000/100%10;
for(i=0;i<6;i++)
{
WtiteMAX_7219(i+1,Disp_Buffer[i]);
}
}
}
你的这句void Timer1Interrupt() interrupt 0 就不对了,中断0是外部中断
一周热门 更多>