|
#include "STC8G.h"
#include "intrins.h"
#define uint unsigned int
#define uchar unsigned char
#define uint unsigned int
#define uchar unsigned char
#define beep P23
#define dula P26
#define wela P27
uint num , c;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void DelayMs(uint c);
void Display(uint shu);
void main(void)
{
P0M0 = 0xff; P0M1 = 0x00;
P1M0 = 0xff; P1M1 = 0x00;
P2M0 = 0xff; P2M1 = 0x00;
P3M0 = 0x50; P3M1 = 0x50;
P4M0 = 0xff; P4M1 = 0x00;
P5M0 = 0x10; P5M1 = 0x10;
P6M0 = 0xff; P6M1 = 0x00;
P7M0 = 0xff; P7M1 = 0x00;
IE1 = 0;
IE0 = 0;
EX1 = 1; //INT1 Enable
EX0 = 1; //INT0 Enable
ET1 =1;
IT0 = 1;
// IT0 = 0;
// IT1 = 0;
IT1 =1;
EA=1;
P37=0;
P36=0;
P35=0;
num==0;
while(1)
{
Display(num);
}
}
void INt0_int (void) interrupt 0
{
if(P32==0)
{
Display(num);
num++;
P5M0=0x20;
while(!P32);
Display(num);
P5M0=0x00;
}
}
void INt1_int (void) interrupt 2
{
if(P54==0)
{
num--;
P5M0=0x20;
while(!P54);
Display(num);
P5M0=0x00;
}
}
void Display(uint shu)
{
P37=0;
P1=table[shu/100];//ÏÔʾ0
DelayMs(5);
P37=1;
P36=0;
P1=table[shu/10%10];//ÏÔʾ0
DelayMs(5);
P36=1;
P35=0;
P1=table[shu%10];//ÏÔʾ0
DelayMs(5);
P35=1;
}
void DelayMs(uint c)
{
uint a,b;
for(a=c;a>0;a--)
for(b=115;b>0;b--);
}
|
|