错误如下:
Build target 'Target 1'
compiling LED2.c...
LED2.c(13): error C247: non-address/-constant initializer
LED2.c(14): error C100: unprintable character 0xBB skipped
LED2.c(15): error C141: syntax error near 'unsigned'
Target not created.
Build Time Elapsed: 00:00:00
程序如下:
#include"reg52.h"
#include"intrins.h"
#define uchar unsigned int
#define DelayNOP(){_nop_();_nop_();_nop_();}
sbit K1=P1^0;//Ñ¡Ôñμ÷ÕûD¡ê±»ò·ÖÖó
sbit K2=P1^1;//+
sbit K3=P1^2;//-
sbit K4=P1^3;//íê3ééèÖÃ
sbit SPK=P3^0;
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
uchar code Str1[]=" Current Time ";
uchar code Str2[]=" Set New Time "£»
uchar HMS_String[]=" 00:00:00 ";//′yÏÔê¾ê±¼ä
bit Settime=0;//êÇ·ñDT¸Äê±¼ä
bit Change_H_or_M_=1;//1 is change H,0 is not change M
uchar Millisecond,Hour=0,Minute=0,Second=0;
//------------------------------------------------------
//Ñó3ùoˉêy
//------------------------------------------------------
void DelayMS(int x)
{
uchar i;
while(x--)for(i=0;i<120;i++);
}
//-------------------------------------------------------
//LEDÃ|×′쬼ì2a
//--------------------------------------------------------
bit LCD_Busy_check()
{
bit result;
RS=0;RW=1;E=1;DelayNOP();result=(bit)(P0&0x80);E=0;
return result;
}
//---------------------------------------------------------
//D′LCDÃüáî
//----------------------------------------------------------
void LCD_Write_Command(uchar cmd)
{
while(LCD_Busy_Check());//LCD is busy or not
RS=0;RW=0;E=0;nop_();nop_();P0=cmd;DelayNOP();
E=1;DelayNOP();E=0;
}
//-----------------------------------------------------------
//éèÖÃLCDÏÔê¾Î»ÖÃ
//------------------------------------------------------------
void LCD_Set_Pos(uchar pos)
{
LCD_Write_Command(pos|0x80);//?
}
//------------------------------------------------------------
//D′LCDêy¾Y
//--------------------------------------------------------------
void LCD_Write_Data(uchar dat)
{
while(LCD_Busy_Check());//LCD is busy or not
RS=1;RW=0;E=0;
P0=dat; DelayNOP();
E=1;DelayNOP();E=0;
}
//----------------------------------------------------------------
//LCD3õê¼»ˉ
//-----------------------------------------------------------------
void LCD_Initialize()
{
LCD_Write_Command(0x38);DelayMS(1);//éèÖÃ8λ¸ñê½£¬2DDÏÔê¾£¬5*7 1|Äüé趨ָáî
LCD_Write_Command(0x0c);DelayMS(1);//ÏÔê¾1|Äü¿a£¬ÎT1a±ê£¬1a±êéá˸ ÏÔ꾿a1a¿ØÖÆÖ¸áî
LCD_Write_Command(0x06);DelayMS(1);//D′èëDÂêy¾Y1a±êóòòÆ£¬ÏÔê¾Æá2»òƶˉ Ä£ê½éèÖÃÖ¸¶¨
LCD_Write_Command(0x01);DelayMS(1);//ÇåÆá1|Äü
}
//----------------------------------------------------------------------
//ÏÔê¾êy¾Y£¬ÔúLCDÖ¸¶¨μÄDDéÏÏÔê¾×Ö·û
//-----------------------------------------------------------------------
void Display_String(uchar*str,uchar LineNo)
{
uchar k;
LCD_Set_Pos(LineNo);
for(k=0;k<16;k++)
LCD_Write_Data(str[k]);
}
//----------------------------------------------------------------------
//·äÃùÆ÷
//----------------------------------------------------------------------
void Beep()
{
uchar i,j=70;
for(i=0;i<200;i++)
{
while(--j);
SPK=~SPK;
}
DelayMS(300);
SPK=0;
}
//---------------------------------------------------------------------------
//ê±·ÖÃëÏÔê¾
//---------------------------------------------------------------------------
void Display_HMS(uchar h,m,s)
{
if(settime)HMS_String[3]='>';
else HMS_String[3]=' ';
HMS_String[4]=h/10+'0';//ê±
HMS_String[5]=h%10+'0';
HMS_String[7]=m/10+'0';//·Ö
HMS_String[8]=m%10+'0';
HMS_String[10]=s/10+'0';//Ãë
HMS_String[11]=s%10+'0';
}
//----------------------------------------------------------------------------
//éèÖÃê±¼ä
//----------------------------------------------------------------------------
void Change_Time()
{
Settime=0;
if(K1==0||K2==0||K3==0)
{
TR0=0;
Display_String(Str2,0x00);
Settime=1;
}
while(Settime)
{
if(K1==0)
{
Beep();
while(K1==0);
Change_H_or_M=!Change_H_or_M;
}
else if(K2==0)
{
Beep();
while(K2==0);
if(Change_H_or_M=1)
{
if(++Hour==24)Hour=0;
}
else
{
if(++Minute==60)Minute=0;
}
}
else if(K3==0)
{
Beep();
while(K3==0);
if(Change_H_or_M=1)
{
if(-Hour==0xff)Hour=23;
}
else
{
if(-Minute==0xff)Minute=59;
}
}
else if(K4==0)
{
Beep();
while(K4==0);
Display_String(Str1,0x00);
Settime=0;
TR0=1;
}
}
}
//----------------------------------------------------------------------
//¶¨ê±Æ÷ÖD¶Ï0
//----------------------------------------------------------------------
void Time() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
if(++MilliSecond==20)
{
MilliSecond=0;
if(++Second==60)
{
Second=0;
if(++Minute==60)
{
Minute=0;
if(++Hour==24)
{
Hour=0;Minute=0;Second=0;
}
}
}
}
}
//------------------------------------------------------------------------
//Ö÷oˉêy
//------------------------------------------------------------------------
void main()
{
TMOD|=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
IE=0x82;
SPK=0;
LCD_Initialize();
Display_String(Str1,0x00);//μúò»DDÏÔê¾
TR0=1;
P1=0xFF;
while(1)
{
Display_HSM(Hour,Minute,Second);
DelayMS(500);
Change_Time();
}
}
|