|
#include "reg52.h"
#include<intrins.h> //因為要用到左右移函數(shù),所以加入這個頭文件
#define uchar unsigned char
typedef unsigned int u16; //對數(shù)據(jù)類型進(jìn)行聲明定義
typedef unsigned char u8;
u8 duan[8]={0x40};
u8 wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}
u8 dispbitcnt;
u8 i;
void Timer()
{
TMOD=0x01;//采用定時器0,16位
TH0=0x3c; //初始值 10ms
TL0=0xb0;
EA=1; //總中斷打開
ET0=1; //定時器中斷打開
TR0=1; //定時器開關(guān)打開
}
void main()
{
Timer();
while (1);
{
if(i==100)
{
i=0;
P0=0x40;
P2=wei[dispbitcnt];
P2=P2>>1;
dispbitcnt++;
if(P2==0x7f)
dispbitcnt=0;
}
}
}
void Timer0(void) interrupt 1
{
static u16 i;
TH0=0xd8;
TL0=0xf0;
i++;
}
|
|