Build target 'Target 1'
compiling dzz.c...
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?MIAN?DZZ
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?C_INITSEG
Program Size: data=22.0 xdata=0 code=458
"dzz" - 0 Error(s), 2 Warning(s).
程序如下:
#include <reg51.h>
#include <intrins.h>
#define INT8U unsigned char
#define INT16U unsigned int
sbit K1 = P0^0;
sbit K2 = P0^1;
sbit K3 = P0^2;
sbit K4 = P0^3;
INT8U current_Time[] = {12,59,40};
INT8U disp_Buffer[] = {0,0,0,0,0,0,0x00};
INT8U f_24 = 0, f_AM = 0, f_set = 0;
void delay_ms(INT16U x)
{
INT8U i;while (--x) for (i = 0; i<120; i++);
}
void Add_Hour()
{
++current_Time[0];
if ( f_24 ==1 && current_Time[0] == 24) current_Time[0] = 0;
if ( f_24 ==0 && current_Time[0] == 13)
{ current_Time[0] = 1;
disp_Buffer[6] = (disp_Buffer[6] & 0xFE) | (~(disp_Buffer[6] & 0x01)&0x01);
}
}
void Add_Minute()
{
if(++current_Time[1] == 60)
{ current_Time[1] = 0; Add_Hour();
}
}
void Refresh_Disp_Buffer()
{
INT8U i;
for (i = 0; i < 3 ; i++)
{ disp_Buffer[2 * i] = current_Time[i]/10;
disp_Buffer[2 * i + 1] = current_Time[i]%10;
}
}
void EX0_INT() interrupt 0
{
static INT8U tCount = 0;
tCount++;
if (tCount ==25) disp_Buffer[6] &=0xF7;
if (tCount ==50)
{ tCount = 0;
disp_Buffer[6] |= 0x08;
if (++current_Time[2] == 60)
{ current_Time[2] = 0; Add_Minute();
}
Refresh_Disp_Buffer();
}
}
void Display_Time()
{
INT8U i;
for (i = 0; i < 7; i++)
{
P2 = (disp_Buffer[i] << 4 )| i | 0x08;
P2 &= 0xF7;
}
}
void Adjust_and_Set_Clock()
{
while (K2 == 0)
{
if (K1 == 0)
{ f_24 = 1; disp_Buffer[6] |= 0x02;}
else
{ f_24 = 0; disp_Buffer[6] &= 0xFD;}
if (K3 == 0)
{ delay_ms(150);
Add_Hour();
}
if (K4 == 0)
{ delay_ms (150);
current_Time[1] = (current_Time[1] + 1) % 60;
}
Refresh_Disp_Buffer(); Display_Time();
}
}
void mian()
{
IE = 0x81; IT0 = 1;PX0 = 1;
f_24 = (K1 == 0);
while (1)
{ Display_Time();
if (K1 == 0)
{ f_24 = 1; disp_Buffer[6] |= 0x02;}
else
{ f_24 = 0; disp_Buffer[6] &= 0xFD;}
if (K2 == 0)
{ EX0 = 0;
f_set = 1; disp_Buffer[6] |= 0x04;}
else
{ if (!EX0) EX0 = 1; disp_Buffer[6] &= 0xFB; f_set = 0;
}
Adjust_and_Set_Clock();
}
}
compiling dzz.c...
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?MIAN?DZZ
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?C_INITSEG
Program Size: data=22.0 xdata=0 code=458
"dzz" - 0 Error(s), 2 Warning(s).
程序如下:
#include <reg51.h>
#include <intrins.h>
#define INT8U unsigned char
#define INT16U unsigned int
sbit K1 = P0^0;
sbit K2 = P0^1;
sbit K3 = P0^2;
sbit K4 = P0^3;
INT8U current_Time[] = {12,59,40};
INT8U disp_Buffer[] = {0,0,0,0,0,0,0x00};
INT8U f_24 = 0, f_AM = 0, f_set = 0;
void delay_ms(INT16U x)
{
INT8U i;while (--x) for (i = 0; i<120; i++);
}
void Add_Hour()
{
++current_Time[0];
if ( f_24 ==1 && current_Time[0] == 24) current_Time[0] = 0;
if ( f_24 ==0 && current_Time[0] == 13)
{ current_Time[0] = 1;
disp_Buffer[6] = (disp_Buffer[6] & 0xFE) | (~(disp_Buffer[6] & 0x01)&0x01);
}
}
void Add_Minute()
{
if(++current_Time[1] == 60)
{ current_Time[1] = 0; Add_Hour();
}
}
void Refresh_Disp_Buffer()
{
INT8U i;
for (i = 0; i < 3 ; i++)
{ disp_Buffer[2 * i] = current_Time[i]/10;
disp_Buffer[2 * i + 1] = current_Time[i]%10;
}
}
void EX0_INT() interrupt 0
{
static INT8U tCount = 0;
tCount++;
if (tCount ==25) disp_Buffer[6] &=0xF7;
if (tCount ==50)
{ tCount = 0;
disp_Buffer[6] |= 0x08;
if (++current_Time[2] == 60)
{ current_Time[2] = 0; Add_Minute();
}
Refresh_Disp_Buffer();
}
}
void Display_Time()
{
INT8U i;
for (i = 0; i < 7; i++)
{
P2 = (disp_Buffer[i] << 4 )| i | 0x08;
P2 &= 0xF7;
}
}
void Adjust_and_Set_Clock()
{
while (K2 == 0)
{
if (K1 == 0)
{ f_24 = 1; disp_Buffer[6] |= 0x02;}
else
{ f_24 = 0; disp_Buffer[6] &= 0xFD;}
if (K3 == 0)
{ delay_ms(150);
Add_Hour();
}
if (K4 == 0)
{ delay_ms (150);
current_Time[1] = (current_Time[1] + 1) % 60;
}
Refresh_Disp_Buffer(); Display_Time();
}
}
void mian()
{
IE = 0x81; IT0 = 1;PX0 = 1;
f_24 = (K1 == 0);
while (1)
{ Display_Time();
if (K1 == 0)
{ f_24 = 1; disp_Buffer[6] |= 0x02;}
else
{ f_24 = 0; disp_Buffer[6] &= 0xFD;}
if (K2 == 0)
{ EX0 = 0;
f_set = 1; disp_Buffer[6] |= 0x04;}
else
{ if (!EX0) EX0 = 1; disp_Buffer[6] &= 0xFB; f_set = 0;
}
Adjust_and_Set_Clock();
}
}