具有按键功能的秒表

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

#include

#include

#define uchar unsigned char

#define uint unsigned int

unsigned char num;

unsigned char miao;

unsigned char fen;

unsigned char const SEGtableD[]={0x3F,0x06,0x5B,0x4F,0x66, 0x6D,0x7D,0x07,0x7f,0x6f,0};

unsigned char const SEGtableW[]={0XFE,0xFD,0xFB,0xF7,0xEF, 0xDF,0xBF,0x7F};

unsigned char hour;

unsigned char minute;

unsigned char second;

unsigned char count;

unsigned char k=0;

void port_init(void)

{

PORTE = 0xFF;

DDRE = 0xFF;

PORTD = 0xFF;

DDRD = 0xFF;

}

unsigned char key_press() {

unsigned char j;

//DDRG|=0x0F;

//PORTG|=0x0F;

DDRG&=0XF0;

j=PING;

j=j&0X0F;

if(j==0X0F)

{

return 0;

}

else

{

return 1;

}

}

unsigned char key_scanf() {

unsigned char key;

//delay(0);

if(key_press())

{

key=PING;

key&=0X0F;

switch(key)

{

case 0X0E:

key=1;

break;

case 0X0D:

key=2;

break;

case 0x0B:

key=3;

break;

default: key=10;

//while(key_press());

}

else

{

key=10;

}

return key;

}

void timer0_init(void) {

TCCR0 = 0x00;

ASSR = 0x00;

TCNT0=0x06;

OCR0=0x7C;

TCCR0 = 0x3b;

}

void init_devices(void) {

CLI();

port_init();

timer0_init();

XDIV=0x00;

XMCRA=0x00;

MCUCR=0x00;

EICRA=0x00;

EICRB=0x00;

EIMSK=0X00;

TIMSK=0x02;

ETIMSK=0x00;

SEI();

}

unsigned char timer0_tick;

#pragma interrupt_handler TIMER0_comp_ISR:16

void TIMER0_comp_ISR(void)

{

TCNT0=0x06;

OCR0=0x7C;

timer0_tick++;

if(timer0_tick==10) {

timer0_tick=0;

num++;

if(num==1000)

{

num=0;

miao++;

if(miao==60)

{

miao=0;

fen++;

if(fen==60)

{

fen=0;

}

}

}

}

}

void display(void)

{unsigned char l;

for(l=0;l<500;l++)

{

PORTD=SEGtableD[num%10];

PORTE=0x7F;

delay(4);

PORTE=0xFF;

PORTD=SEGtableD[num/10];

PORTE=0xBF;

delay(4);

PORTE=0xFF;

PORTD=0x40;

delay(4);

PORTE=0xFF;

PORTD=SEGtableD[miao%10]; PORTE=0xEF;

delay(4);

PORTE=0xFF;

PORTD=SEGtableD[miao/10]; PORTE=0xF7;

delay(4);

PORTE=0xFF;

PORTD=0x40;

PORTE=0xFB;

delay(4);

PORTE=0xFF;

PORTD=SEGtableD[fen%10]; PORTE=0xFD;

delay(4);

相关文档
最新文档