请大家详解void int_0(void) interrupt 0,这段程序,为什么定时闹钟打开,时钟显示是十秒一跳,怎么修改成一秒一秒显示,谢谢。。
#include "AT89X51.H"
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int idata
#define DIN P2_0
#define LOAD P2_1
#define CLK P2_2
sbit ADD=P1^1;
sbit SUB=P1^0;
sbit ACC0 = ACC^0;
sbit ACC7 = ACC^7;
sbit T_CLK = P2^3;
sbit T_IO = P2^4;
sbit T_RST = P2^5;
sbit speaker=P3^7;
uchar showTime[8]={0,0,10,0,0,10,0,0};
uchar setTime[2]={0,0};
uchar time[7]={0,0x59,0x19,0x24,0x7,0x01,0x08};
uchar Tmod=7;
uchar count;
uchar n=0;
unsigned int code LED_code_09[14]={0xfE,0xb0,0xeD,0xf9,0xb3,0xdB,0xdF,0xf0,0xfF,0xfB,0x81,0x00,0x3D,0x5B};
unsigned int code LED_code_L07[8]={0x0100,0x0200,0x0300,0x0400,0x0500,0x0600,0x0700,0x0800};
uchar code music_tab[] ={
0x18, 0x30, 0x1C , 0x10,
0x20, 0x40, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x10,
0x1C, 0x10, 0x18 , 0x40,
0x1C, 0x20, 0x20 , 0x20,
0x1C, 0x20, 0x18 , 0x20,
0x20, 0x80, 0xFF , 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20, 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30, 0x80 , 0xFF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x30,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x40, 0x1C , 0x20,
0x20, 0x20, 0x26 , 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00
};
void delay_1ms(void)
{
unsigned int i;
for (i=1;i<(unsigned int)(1144-2);i++);
}
void delay_ms(unsigned int n)
{
unsigned int i=0;
while(i<n)
{
delay_1ms();
i++;
}
}
void delay (unsigned char m)
{
unsigned i=3*m;
while(--i);
}
void delayms(unsigned char a)
{
while(--a);
}
void int0() interrupt 1
{ TH0=0xd8;
TL0=0xef;
n--;
}
void sound()
{ unsigned char p,m;
unsigned char i=0;
TMOD&=0x0f;
TMOD|=0x01;
TH0=0xd8;
TL0=0xef;
IE=0x82;
play:
while(1)
{
p=music_tab[i];
if(p==0x00) { i=0, delayms(1000); goto play;}
else if(p==0xff) { i=i+1;TR0=0; goto playend;}
else {m=music_tab[i++], n=music_tab[i++];}
TR0=1;
while(n!=0) speaker=~speaker,delay(m);
TR0=0;
}
playend:
speaker=1;
}
void sent_LED( unsigned int n )
{
unsigned int i;
unsigned int a;
count=0;
a= (unsigned char)(n);
CLK = 0;
LOAD = 0;
DIN = 0;
for ( i=0x8000; i>=0x0001; i=i>>1 )
{
if ( ( n & i ) == 0 ) DIN = 0; else DIN = 1;
CLK = 1;
CLK = 0;
count++;
}
LOAD = 1;
}
/******************************************************************************
初始化 MAX7219
******************************************************************************/
void initMAX7219(void)
{
sent_LED( 0x0C01 );
sent_LED( 0x0A04 );
sent_LED( 0x0B07 );
sent_LED( 0x0900 );
}
/******************************************************************************
void cls()
******************************************************************************/
void cls()
{
uint i;
for (i=0x0100; i<=0x0800; i+=0x0100 ) sent_LED(i); /* DIGIT0-7 = 0 */
}
void disp_09(unsigned char H,unsigned char n )
{
if ( ( n & 0x80 ) == 0 )
{
sent_LED( LED_code_L07[ H ] | LED_code_09[ n ] );
}
else
{
sent_LED( LED_code_L07[ H ] | LED_code_09[ n & 0x7F ] | 0x80 );
}
}
void disp_88(unsigned char *showda)
{
char idata i;
for (i=0;i<8;i++)
{
disp_09(i,*showda);
showda++;
}
}
//************************************************
void showDay(void)
{
showTime[7]=time[0] & 0x0f;
showTime[6]=time[0]>>4;
showTime[4]=time[1] & 0x0f;
showTime[3]=time[1]>>4;
showTime[1]=time[2] & 0x0f;
showTime[0]=time[2]>>4;
showTime[2]=showTime[5]=10;
disp_88(& showTime);
}
//*************************************************
void showData(void)
{
showTime[7]=time[3] & 0x0f;
showTime[6]=time[3]>>4;
showTime[4]=time[4] & 0x0f;
showTime[3]=time[4]>>4;
showTime[1]=time[6] & 0x0f;
showTime[0]=time[6]>>4;
showTime[2]=showTime[5]=10;
disp_88(& showTime);
}
//*************************************************
void showDishi(void)
{
showTime[1]=setTime[0] & 0x0f;
showTime[0]=setTime[0]>>4;
showTime[4]=setTime[1] & 0x0f;
showTime[3]=setTime[1]>>4;
showTime[6]=12;
showTime[7]=13;
showTime[2]=showTime[5]=10;
disp_88(& showTime);
}
//*****************************************
void flash_max7219(unsigned char n)
{
switch(n)
{
case 0:
showData();
delay_ms(40);
showTime[0]=11;
showTime[1]=11;
disp_88(& showTime);
break;
case 1:
showData();
delay_ms(40);
showTime[3]=11;
showTime[4]=11;
disp_88(& showTime);
break;
case 2:
showData();
delay_ms(40);
showTime[6]=11;
showTime[7]=11;
disp_88(& showTime);
break;
case 3:
showDay();
delay_ms(40);
showTime[0]=11;
showTime[1]=11;
disp_88(& showTime);
break;
case 4:
showDay();
delay_ms(40);
showTime[3]=11;
showTime[4]=11;
disp_88(& showTime);
break;
case 5:
showDishi();
delay_ms(40);
showTime[0]=11;
showTime[1]=11;
disp_88(& showTime);
break;
case 6:
showDishi();
delay_ms(40);
showTime[3]=11;
showTime[4]=11;
disp_88(& showTime);
break;
}
}
void v_RTInputByte(uchar ucDa)
{
uchar i;
ACC = ucDa;
for(i=8; i>0; i--)
{
T_IO = ACC0;
T_CLK = 1;
T_CLK = 0;
ACC = ACC >> 1;
}
}
uchar uc_RTOutputByte(void)
{
uchar i;
for(i=8; i>0; i--)
{
ACC = ACC >>1;
ACC7=T_IO;
T_CLK = 1;
T_CLK = 0;
}
return(ACC);
}
void v_W1302(uchar ucAddr, uchar ucDa)
{
T_RST = 0;
T_CLK = 0;
T_RST = 1;
v_RTInputByte(ucAddr);
v_RTInputByte(ucDa);
T_CLK = 1;
T_RST =0;
}
uchar uc_R1302(uchar ucAddr)
{
uchar ucDa;
T_RST = 0;
T_CLK = 0;
T_RST = 1;
v_RTInputByte(ucAddr);
ucDa = uc_RTOutputByte();
T_CLK = 1;
T_RST =0;
return(ucDa);
}
void v_Set1302(uchar *pSecDa)
{
uchar i;
uchar ucAddr = 0x80;
v_W1302(0x8e,0x00);
for(i =7;i>0;i--)
{
v_W1302(ucAddr,*pSecDa);
pSecDa++;
ucAddr +=2;
}
v_W1302(0x8e,0x80);
void v_Get1302(uchar ucCurtime[])
{
uchar i;
uchar ucAddr = 0x81;
for (i=0;i<7;i++)
{
ucCurtime[i] = uc_R1302(ucAddr);
ucAddr += 2;
}
}
void main()
{
delay_ms(200);
initMAX7219();
cls();
EX0=1;
EX1=1;
IT1=1;
IT0=1;
EA=1;
v_Get1302(& time);
showDay();
while(1)
{
v_Get1302(& time);
showDay();
if ((setTime[0]==time[2])&&(setTime[1]==time[1]))sound();
}
}
//***********************************************
void int_0(void) interrupt 0
{
uint i;
EA=0;
delay_ms(10);
while(!INT0){;}
Tmod+=1;
if(Tmod==7)goto inout;
if (Tmod==8)Tmod=0;
while(1)
{
flash_max7219(Tmod);
for (i=0;i<20000;i++)
{
if (!INT0)
{
delay_ms(40);
while(!INT0){;}
if(Tmod==6)goto inout;
Tmod+=1;
if(Tmod==8)Tmod=0;
}
else if ((!ADD) || (!SUB))
{
switch(Tmod)
{
case 0:
if (!ADD)
{
time[6]+=0x01;
if ((time[6] & 0x0f)==10)time[6]+=0x06;
if ((time[6]>>4)==10)time[6]=0;
}
else
{
time[6]-=0x01;
if ((time[6] & 0x0f)==15)time[6]-=0x06;
if ((time[6]>>4)==15)time[6]=0x99;
}
break;
case 1:
if (!ADD)
{
time[4]+=0x01;
if((time[4] & 0x0f)==10)time[4]+=0x06;
if(time[4]==0x13)time[4]=0x01;
}
else
{
time[4]-=0x01;
if((time[4] & 0x0f)==15)time[4]-=0x06;
if(time[4]==0)time[4]=0x12;
}
break;
case 2:
if (!ADD)
{
time[3]+=0x01;
if ((time[3] & 0x0f)==10)time[3]+=0x06;
if (time[3]==0x32)time[3]=1;
}
else
{
time[3]-=0x01;
if ((time[3] & 0x0f)==15)time[3]-=0x06;
if (time[3]==0)time[3]=0x31;
}
break;
case 3:
if (!ADD)
{
time[2]+=0x01;
if ((time[2] & 0x0f)==10)time[2]+=0x06;
if (time[2]==0x24)time[2]=0;
}
else
{
time[2]-=0x01;
if ((time[2] & 0x0f)==15)time[2]-=0x06;
if ((time[2]>>4)==15)time[2]=0x23;
}
break;
case 4:
if (!ADD)
{
time[1]+=0x01;
if ((time[1] & 0x0f)==10)time[1]+=0x06;
if (time[1]==0x60)time[1]=0;
}
else
{
time[1]-=0x01;
if ((time[1] & 0x0f)==15)time[1]-=0x06;
if ((time[1]>>4)==15)time[1]=0x59;
}
break;
case 5:
if (!ADD)
{
if (setTime[0]==0xAA)setTime[0]=0x24;
setTime[0]+=0x01;
if ((setTime[0] & 0x0f)==10)setTime[0]+=0x06;
if (setTime[0]==0x25)setTime[0]=0;
if (setTime[0]==0x24)setTime[0]=0xAA;
}
else
{
if (setTime[0]==0xAA)setTime[0]=0x24;
setTime[0]-=0x01;
if ((setTime[0] & 0x0f)==15)setTime[0]-=0x06;
if ((setTime[0]>>4)==15)setTime[0]=0x24;
if (setTime[0]==24)setTime[0]=0xAA;
}
break;
case 6:
if (!ADD)
{
setTime[1]+=0x01;
if ((setTime[1] & 0x0f)==10)setTime[1]+=0x06;
if (setTime[1]==0x60)setTime[1]=0;
}
else
{
setTime[1]-=0x01;
if ((setTime[1] & 0x0f)==15)setTime[1]-=0x06;
if ((setTime[1]>>4)==15)setTime[1]=0x59;
}
break;
case 7:
break;
}
while((!ADD) || (!SUB)){;}
}
}
}
inout:
v_Set1302(& time);
EA=1;
}
//**********************************************
void int_1(void) interrupt 2
{
showData();
delay_ms(200);
}
我也是~~~~~~~~~~~~~~~~~
一周热门 更多>