秒表C语言程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include "reg52.h"

#include "intrins.h"

sbitStart_Stop = P3^2;

sbit Clear = P3^3;

sbit Sel_A1 = P1^0;

sbit Sel_B1 = P1^1;

sbit Sel_C1 = P1^2;

sbit Sel_D1 = P1^3;

#define LED P0

#define DP 0x80

bdata unsigned char flag;

sbitStatus_Flag = flag^0;

sbit

Is_KeyS_Hold=flag^1; unsigned char xiaoshu1 = 0 ,

xiaoshu2 = 0 ,

miao1 = 0 ;

miao2 = 0 ;

code unsigned char table[]=

{0x3f,0x06,0x5b,0x4f,0x66,0x6d,

0x7d,0x07,0x7f,0x6f,};

voidinit();

void display();

void delay();

void key();

void main()

{

init();

while(1)

{

key();

display();

}

}

void key()

{

if(Is_KeyS_Hold)

if(Start_Stop)

{

Is_KeyS_Hold = 0 ;

EX0 = 1 ;

}

}

void delay()

{

unsignedinti ;

for(i = 0; i<300; i++);

}

void display()

{

Sel_A1 = 1;

Sel_B1 = 1;

Sel_C1 = 1;

Sel_D1 = 0;

LED = table[xiaoshu2];delay(); Sel_A1 = 1;

Sel_B1 = 1;

Sel_C1 = 0;

Sel_D1 = 1;

LED = table[xiaoshu1];delay(); Sel_A1 = 1;

Sel_B1 = 0;

Sel_C1 = 1;

Sel_D1 = 1;

LED=table[miao2]|DP;delay();

Sel_A1 = 0;

Sel_B1 = 1;

Sel_C1 = 1;

Sel_D1 = 1;

LED = table[miao1];delay(); voidKey_Start_Stop() interrupt 0 { EX0 = 0;

Status_Flag = ~ Status_Flag ;

Is_KeyS_Hold = 1;

if(Status_Flag )

TR0 = 1;

else

TR0 = 0;

}

void time10ms() interrupt 1

{

TL0 = 0XEF;

TH0 = 0XD8;

TR0 = 1 ;

xiaoshu2+=1;

if(xiaoshu2 == 10)

{ xiaoshu2 = 0 ; xiaoshu1 += 1;}

if(xiaoshu1 == 10)

{ xiaoshu1 = 0 ; miao2 += 1;}

if(miao2 == 10)

{ miao2 = 0 ; miao1 += 1;}

if(miao1 == 10)

miao1 = 0;

}

voidinit()

{

Sel_A1 = Sel_B1 = Sel_C1 = Sel_D1 = 1 ; LED = 0XFF;

Status_Flag = 0;

xiaoshu1 = xiaoshu2 = miao1 = miao2 = 0 ;

ET0 = 1;

EX0 = 1;

EA = 1 ;

TMOD = 0X01;

TL0 = 0XEF;

TH0 = 0XD8;

TR0 = 0 ;}

相关文档
最新文档