51单片机时钟

更新时间:2023-11-08 15:05:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

/**********************SY-1实验开发板例程************************ * 平台:SY-1+STC89C52 * 名称:钟表

* 公司:思源电子科技有限公司 * 编写:思源

* 日期:2012-12-25 * QQ : 936559219 * 晶振:11.0592MHZ

******************************************************************/ #include

#define uchar unsigned char

sbit dula=P2^6; sbit wela=P2^7; sbit beep=P2^3;

unsigned char j,k,a1,a0,b1,b0,c1,c0,s,f,m,key=10,temp,qq; uchar shi20,shi10,fen20,fen10,miao20,miao10,new,ok=1,wei; unsigned int pp;

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,

0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void delay(unsigned char i) {

for(j=i;j>0;j--)

for(k=125;k>0;k--); }

void display(uchar shi2,uchar shi1,uchar fen2,uchar fen1,uchar miao2,uchar miao1) {

dula=0;

P0=table[shi2]; dula=1; dula=0;

wela=0; P0=0xfe; wela=1; wela=0; delay(5);

P0=table[shi1]|0x80; dula=1; dula=0;

P0=0xfd; wela=1; wela=0; delay(5);

P0=table[fen2]; dula=1; dula=0;

P0=0xfb; wela=1; wela=0; delay(5);

P0=table[fen1]|0x80; dula=1; dula=0;

P0=0xf7; wela=1; wela=0; delay(5);

P0=table[miao2]; dula=1; dula=0;

P0=0xef; wela=1; wela=0; delay(5);

P0=table[miao1]; dula=1; dula=0;

P0=0xdf; wela=1; wela=0; delay(5); }

void keyscan0() {

P3=0xfb; temp=P3;

temp=temp&0xf0; if(temp!=0xf0) {

delay(10); if(temp!=0xf0) {

temp=P3; switch(temp) {

case 0xbb: ok=0; break;

case 0x7b: ok=1; break; } } } }

void keyscan() { {

P3=0xfe; temp=P3;

temp=temp&0xf0; if(temp!=0xf0) {

delay(10); if(temp!=0xf0) {

temp=P3; switch(temp) {

case 0xee: key=0; wei++; break;

case 0xde:

key=1; wei++; break;

case 0xbe: key=2; wei++; break;

case 0x7e: key=3; wei++; break; }

while(temp!=0xf0) {

temp=P3;

temp=temp&0xf0; beep=0; }

beep=1; } }

P3=0xfd; temp=P3;

temp=temp&0xf0; if(temp!=0xf0) {

delay(10); if(temp!=0xf0) {

temp=P3; switch(temp) {

case 0xed: key=4; wei++; break;

case 0xdd: key=5; wei++; break;

case 0xbd: key=6; wei++; break;

case 0x7d: key=7; wei++; break; }

while(temp!=0xf0) {

temp=P3;

temp=temp&0xf0; beep=0; }

beep=1; } }

P3=0xfb; temp=P3;

temp=temp&0xf0; if(temp!=0xf0) {

delay(10); if(temp!=0xf0) {

temp=P3; switch(temp) {

case 0xeb: key=8; wei++; break;

case 0xdb: key=9; wei++; break; }

while(temp!=0xf0) {

temp=P3;

temp=temp&0xf0;

本文来源:https://www.bwwdw.com/article/oiu2.html

Top