main中代码如下:
/***********************************************************
* ³ÌÐòÉè¼Æ¹¦ÄÜ£º1¡¢»ùÓÚDS1302µÄʵʱʱÖÓÏÔʾ£¬²¢¾ß±¸ *
* ¿ÉÒÔµ÷½Úʱ¼ä¡¢ÈÕÆڵŦÄÜ£¨À©Õ¹ÄÖÖӵȣ© *
* 2¡¢¿ÉÒÔÏÔʾζȣ¬Í¨¹ý°´¼ü½øÐÐÏÔʾÇл»£¬Î¶ȱ¨¾¯ *
* 3¡¢À©Õ¹ÏÔʾÆøѹ¡¢¾ß±¸ÓïÒô²¥±¨¹¦ÄÜ£¨´ýÀ©Õ¹£© *
* ×÷ÕߣºZ B T ʱ¼ä£º 2015.03 *
***********************************************************/
#include<reg51.h>
#include"DS1302.h"
#define uint unsigned int
#define uchar unsigned char
/* º¯ÊýÔÐÍÉùÃ÷ */
void timer_init(); /* Öжϳõʼ»¯ */
void key_scan(); /* ¼üÅÌɨÃ躯Êý */
void display_time(); /* ÏÔʾʱ¼ä */
void delayms(uint xms); /* xmsΪ¶àÉÙ ÑÓʱ¶àÉÙºÁÃë */
/* ¶Ë¿Ú¶¨Òå */
sbit led = P2^2; /* LED¶Ë¿Ú */
sbit buzzer = P2^1; /* ·äÃùÆ÷¶Ë¿Ú */
sbit key0 = P1^0; /* ½øÈëʱÖÓÉèÖÃģʽ */
sbit key1 = P1^1; /* Ñ¡ÔñÒªµ÷µÄ²¿·Ö */
sbit key2 = P1^2; /* Ôö¼Ó°´¼ü */
sbit key3 = P1^3; /* ¼õС°´¼ü */
sbit dula = P2^6; /* 74HC573N¿ØÖƵĶÎÑ¡¶Ë */
sbit wela = P2^7; /* 74HC573N¿ØÖƵÄλѡ¶Ë */
//extern unsigned char TIME[7]; //¼ÓÈëÈ«¾Ö±äÁ¿
uchar code w[] = {0xfe, 0xfd,0xfb, 0xf7, 0xef, 0xdf}; /* ÊýÂë¹Üλѡ */
uchar code tab[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; /* 0----FµÄÏÔʾÂë ¹²Òõ */
uchar display_data[8]; /* ÓÃÀ´´æ·ÅÒªÏÔʾµÄ8λÊýµÄÖµ (±¾³ÌÐòÔÝʱÓÃ6¸öÊýÂë¹Ü) */
uchar state,set_place; /* state£º ÊÇ·ñÑ¡Ôñµ÷ʱµÄ±êÖ¾ set_place £ºÑ¡Ôñµ÷½ÚÄIJ¿·Ö */
void main()
{
timer_init(); /* Öжϳõʼ»¯ */
//ds1302_init(); /* ʱÖÓ³õʼ»¯ */
while(1)
{
if(state == 0)
{
ds1302_read_time();
}
else
{
key_scan();
}
display_time();
}
}
void key_scan()
{
if(key1 == 0)
{
delayms(5);
if(key1 == 0)
{
set_place++;
if(set_place == 7)
{
set_place = 0;
}
}
while(!key1);
}
if(set_place != 0)
{
if(key2 == 0)
{
delayms(5);
if(key2 == 0)
{
while(!key1); // °´¼üÊÍ·Å
if(set_place == 1)
{
TIME[1]++; ds1302_read_time();
}
}
}
}
}
/* ÊýÂë¹ÜÏÔʾʱ¼äº¯Êý */
void display_time()
{
uchar i;
uint j;
display_data[0] = tab[TIME[2]/16]; /* ½«Ð¡Ê±µÄBCDÂë·Ö³ÉÁ½Î»Êý */
display_data[1] = tab[TIME[2]&0x0f];
//display_data[2] = 0x40; /* ÏÔʾ-- ±¾Éè¼ÆÔÝʱ²»ÏÔʾ */
display_data[2] = tab[TIME[1]/16]; /* ½«´ú±í·ÖµÄBCDÂë·Ö³ÉÁ½Î»Êý */
display_data[3] = tab[TIME[1]&0x0f];
//display_data[5] = 0x40;
display_data[4] = tab[TIME[0]/16]; /* ½«´ú±íСʱµÄBCDÂë·Ö³ÉÁ½Î»Êý */
display_data[5] = tab[TIME[0]&0x0f];
for(i = 0; i < 6; i++)
{
wela = 1;
P0 = w[i]; /* ËÍÈëλѡ */
wela = 0;
dula = 1;
P0 = display_data[i]; /* ËÍÈë¶ÎÑ¡ */
dula = 0;
P0 = 0x00; /* ÏûÒþ */
if(i == 5) /* ledÉÁ˸ */
{
led = ~led;
}
j=70; /* ɨÃè¼ä¸ôʱ¼äÉ趨 */
while(j--);
}
}
void timer_init()
{
TMOD = 0x01;
TH0 = (65536 - 45872) / 256;
TL0 = (65536 - 45872) % 256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void t0() interrupt 1
{
TH0 = (65536 - 45872) / 256;
TL0 = (65536 - 45872) % 256;
if(key0 == 0)
{
delayms(5);
if(key0 == 0)
{
state = ~state;
set_place++;
ds1302_init(); /* ´ò¿ª¹Ø±Õд±£»¤ */
while(!key0);
}
}
}
/* ÑÓʱº¯Êý */
void delayms(uint xms)
{
uint i, j;
for(i = xms; i > 0; i--)
for(j = 110; j > 0; j--); /* ÑÓʱԼxms */
}
希望能有人解答一下key_scan中的函数是不是哪里写错了,
这个想了好久都没弄好,希望得到大家帮助
|