基于郭天祥開發板
#include <STC89C5xRC.H>
#include <intrins.h>
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
//sbit ir=P3^2;
sbit ledw=P2^6;
sbit ledd=P2^7;
#define ledduan P0
u8 code ledma []={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,
0x7c,0x58,0x5e,0x79,0x71,0x80,0xff,0x00};//共陰 0-f . 全顯全滅
u8 code ledwma []={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//共陰
u8 i,j;
u32 a;
void delay(u16 z)
{
u16 x;
u8 y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
void timerInit ()
{
TMOD|=0x01;
TH0=(65536-3000)/256; //50MS
TL0=(65536-3000)%256;
//TH1=(65536-46080)/256; //3MS
//TL1=(65536-46080)%256;
ET0=1;
//ET1=1;
EA=1;
TR0=1;
// TR1=1;
}
/*
void timer0init ()
{
TMOD|=0x01;
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
ET0=1;
EA=1;
TR0=1;
}
void display(u32 a)
{
u8 aa,bb,cc,dd,ee,ff;
aa=a/100000;
bb=a%100000/10000;
cc=a%10000/1000;
dd=a%1000/100;
ee=a%100/10;
ff=a%10;
ledd=1;
ledduan=ledwma [0];
ledd=0;
ledw=1;
ledduan=ledma[aa];
ledw=0;
delay(5);
ledd=1;
ledduan=ledwma [1];
ledd=0;
ledw=1;
ledduan=ledma[bb];
ledw=0;
delay(5);
ledd=1;
ledduan=ledwma [2];
ledd=0;
ledw=1;
ledduan=ledma[cc];
ledw=0;
delay(5);
ledd=1;
ledduan=ledwma [3];
ledd=0;
ledw=1;
ledduan=ledma[dd];
ledw=0;
delay(5);
ledd=1;
ledduan=ledwma [4];
ledd=0;
ledw=1;
ledduan=ledma[ee];
ledw=0;
delay(5);
ledd=1;
ledduan=ledwma [5];
ledd=0;
ledw=1;
ledduan=ledma[ff];
ledw=0;
delay(5);
}
*/
void main()
{
u8 aa,bb,cc,dd,ee,ff;
a=333333;
aa=a/100000;
bb=a%100000/10000;
cc=a%10000/1000;
dd=a%1000/100;
ee=a%100/10;
ff=a%10;
timerInit ();
while(1)
{
ledduan=0x00;
switch(j)
{
case 0:
// ledduan=0x00;
ledd=1;
ledduan=ledwma [j];
ledd=0;
//ledduan=0x00;
ledw=1;
ledduan=ledma[aa];
ledw=0;
//ledduan=0x00;
break;
case 1:
//ledduan=0x00;
ledd=1;
ledduan=ledwma [j];
ledd=0;
//ledduan=0x00;
ledw=1;
ledduan=ledma[bb];
ledw=0;
//ledduan=0x00;
break;
case 2:
// ledduan=0x00;
ledd=1;
ledduan=ledwma [j];
ledd=0;
//ledduan=0x00;
ledw=1;
ledduan=ledma[cc];
ledw=0;
//ledduan=0x00;
break;
case 3:
// ledduan=0x00;
ledd=1;
ledduan=ledwma [3];
ledd=0;
//ledduan=0x00;
ledw=1;
ledduan=ledma[dd];
ledw=0;
//ledduan=0x00;
break;
case 4:
// ledduan=0x00;
ledd=1;
ledduan=ledwma [4];
ledd=0;
//ledduan=0x00;
ledw=1;
ledduan=ledma[ee];
ledw=0;
//ledduan=0x00;
break;
case 5:
//ledduan=0x00;
ledd=1;
ledduan=ledwma [5];
ledd=0;
//ledduan=0x00;
ledw=1;
ledduan=ledma[ff];
ledw=0;
//ledduan=0x00;
break;
/*if(i>=20)
{
i=0;
cnt++;
}*/
//display(123456);
//delay(3000);*
}
}
}
void timer0isr() interrupt 1
{
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
j++;
if(j>=6)
{
j=0;
}
}
/*
void timer1isr() interrupt 3
{
TH1=(65536-46080)/256;
TL1=(65536-46080)%256;
i++;
}*/
|