这个程序在keil中调试不了,到底是哪里出了问题啊?求编程大神指点指点 - 爱问答

(爱问答)

这个程序在keil中调试不了,到底是哪里出了问题啊?求编程大神指点指点

#include <reg52.h>

#include <string.h>

#include <intrins.h>

#define uchar unsigned char

#define uint unsigned int

sbit SDA=P1^0;//DS1302数据线

sbit CLK=P1^1;//DS1302时钟线

sbit RST=P1^2;//DS1302复位线

 

sbit RS=P2^0;//数据、指令选择端口

sbit RW=P2^1;//读写端口

sbit EN=P2^2;//使能端口

 

sbit K1=P3^4;//选择

sbit K2=P3^5;//加

sbit K3=P3^6;//减

sbit K4=P3^7;//确定

 

uchar tCount=0;//一年中每个月的天数,2月的天数由年份决定

uchar MonthsDays[]={0,31,0,31,30,31,30,31,31,30,31,30,31};

uchar *WEEK[]={“sun”, “mon”, “tus”, “wen”, “thu”, “fri”, “sat”};//周日,周一到周六

uchar LCD_DSY_BUFFER1[]={“Date 00-00-00”};//LCD显示缓冲

uchar LCD_DSY_BUFFER2[]={“Time 00-00-00”};

uchar_dataeTime[7];//所读取的日期时间

char Adjust_Index=-1;//当前调节的时间:秒、分、时、日

uchar Change_Flag[]=“-MHDM-Y”;

 

uchar Read_LCD_State();//读LCD状态

void LCD_Busy_Wait()//判忙

void Write_Date(uchar_data);//写数据

void Write_com(uchar com);//写命令

void Init_LCD();//LCD初始化

void Set_LCD_POS(uchar p);//设置显示位置

void Display_LCD_String(uchar p,uchar *s);//写字符串

void DelayMS(unit x);//延时

{

uchar i;

While(x--) for(i=0;i<120;i++);

}

uchar Read_LCD_State()//读LCD状态

{

uchar state;

RS=0;

RW=1;

EN=1;

DelayMS(1);

state=P0;

EN=0;

DelayMS(1);

return state;

}

void LCD_Busy_Wait()//判忙

{

while((Read_LCD_State()&0x08)==0x80);

DelayMS(5);

}

void Write_Date(uchar_data);//写数据

{

LCD_Busy_Wait();

RS=1;

RW=0;

EN=0;

P0=dat;

EN=1;

DelayMS(1);

EN=0;

}

void Write_com(uchar com);//写命令

{

LCD_Busy_Wait();

RS=0;

RW=0;

EN=0;

P0=cmd;

EN=1;

DelayMS(1);

EN=0;

}

void Init_LCD();//LCD初始化

{

Write_com(0x38); DelayMS(1);

Write_com(0x01); DelayMS(1);

Write_com(0x06); DelayMS(1);

Write_com(0x0c); DelayMS(1);

Display_LCD_String(0x00, “lingnanshifanxueyuan”);

//DelayMS(1000);

Display_LCD_String(0x40, “dian zi zhong”);

DelayMS(2000);

}

void Set_LCD_POS(uchar p) //设置显示位置

{

Write_com(p|0x80);

}

void Display_LCD_String(uchar p,uchar *s) //写字符串

 

{

uchar i;

Set_LCD_POS(p);

for(i=0;i<16;i++)

{

Write_Date(s[i]);

DelayMS(1);

}

}

/*向DS1302写入一字节*/

void DS1302_Write_Byte(uchar x)

{

uchar i;

for(i=0;i<8;i++)

{

SDA=x&1;

CLK=1;

CLK=0;

x>>=1;

}

}

/*向DS1302读取一字节*/

void DS1302_Read_Byte()

{

uchar i,b,t;

for(i=0;i<8;i++)

{

b>>=1;

t=SDA;

b|=t<<7;

CLK=1;

CLK=0;

}

return b/16*10+b%16;

}

/*从DS1302指定位置数据*/

uchar Read_Date(uchar addr)

{

Uchar_data;

RST=0;

CLK=0;

RST=1;

DS1302_Write_Byte(addr);

dat= DS1302_ Read _Byte();

CLK=1;

RST=0;

return dat;

}

/*向DS1302某地址写入数据*/

void Write_ DS1302(uchar addr,uchar_data)

{

CLK=0;

RST=1;

DS1302_Write_Byte(addr)

DS1302_Write_Byte(dat)

CLK=0;

RST=0;

}

/*设置时间*/

void SET_DS1302()

{

uchar i;

Write_DS1302(0x8e,0x00);

for(i=0;i<7;i++)

{

Write_DS1302(0x80+2*i,(DateTime[i]/10<<4|(DateTime[i]%10)));

}

Write_DS1302(0x8e,0x80);

}

/*读取当前时期时间*/

void GetTime()

{

uchar i;

for(i=0;i<7;i++)

{

DateTime[i]=Read_Date(0x81+2*i);

}

}

/*时间和日期转换成数字字符*/

Void Format_DateTime(uchar d,uchar *a)

{

a[0]=d/10+’0’; a[1]=d%10+’0’;

}

/*判断是否为闰年*/

uchar isLeepYear(unit y)

{

Return(y%4==0&&y%100!=0)||(y%400==0);

}

/*星期转换*/

void RefreshWeekDay()

{

unit i,d,w=5;

for(i=2000;i<2000+DateTime[6];i++)

{

d= isLeepYear(i)?366:365;

w=(w+d)%7;

}

d=0;

for(i=1;i<DateTime[4];i++) d+=MonthsDay[i];

d+= DateTime[3];

DateTime[5] =(w+d)%7+1;

}

/*年月日时分秒++/--*/

void DateTime_Adjust(char x)

{

switch(Adjust_Index)

{

case6://年

if(x==1&& DateTime[6]<99) DateTime[6]++;

if(x==-1&& DateTime[6]>0) DateTime[6]--;

MonthsDay[2]= isLeepYear(2000+DateTime[6])? 29:28;

if(DateTime[3]> MonthsDay[DateTime[4]])

DateTime[3]=MonthsDay[DateTime[4]];

RefreshWeekDay();

Break;

case 4://月

if(x==1&& DateTime[4]<12) DateTime[4]++;

if(x==-1&& DateTime[4]>1) DateTime[4]--;

MonthsDay[2]= isLeepYear(2000+DateTime[6])? 29:28;

if(DateTime[3]> MonthsDay[DateTime[4]])

DateTime[3]=MonthsDay[DateTime[4]];

RefreshWeekDay();

Break;

case 3://日

MonthsDay[2]= isLeepYear(2000+DateTime[6])? 29:28;

if(x==1&& DateTime[3]> MonthsDay[DateTime[4]]) DateTime[3]++;

if(x==-1&& DateTime[3]>0) DateTime[3]--;

RefreshWeekDay();

Break;

case 2://时

if(x==1&& DateTime[2]<23) DateTime[2]++;

if(x==-1&& DateTime[2]>0) DateTime[2]--;

Break;

case 1://分

if(x==1&& DateTime[1]<59) DateTime[1]++;

if(x==-1&& DateTime[1]>0) DateTime[1]--;

Break;

case 0://秒

if(x==1&& DateTime[0]<59) DateTime[0]++;

if(x==-1&& DateTime[0]>0) DateTime[0]--;

Break;

}

}

/*定时器每秒刷新LCD显示*/

void T0_INT() interrupt1

{

TH0=-50000/256;

TL0=-50000%256;

if(++tCount!=2) return;

tCount=0;

Format_DateTime(DateTime[6],LCD_DSY_BUFFER1+5);

Format_DateTime(DateTime[4],LCD_DSY_BUFFER1+8);

Format_DateTime(DateTime[3],LCD_DSY_BUFFER1+11);

strcpy(LCD_DSY_BUFFER1+13,WEEK[DateTime[5]-1]);

Format_DateTime(DateTime[2],LCD_DSY_BUFFER2+5);

Format_DateTime(DateTime[1],LCD_DSY_BUFFER2+8);

Format_DateTime(DateTime[0],LCD_DSY_BUFFER2+11);

Display_LCD_String(0x00, LCD_DSY_BUFFER1);

Display_LCD_String(0x40, LCD_DSY_BUFFER2);

}

/*键盘中断*/

void EX_INT0() interrupt0

{

if(K1==0)//选择调整对象:年、月、日、时、分、秒

{

while(K1==0);

if(Adjust_Index==5) Adjust_Index=4;

LCD_DSY_BUFFER2[13]= ‘ [’;

LCD_DSY_BUFFER2[14]=Change_Flag[Adjust_ Index;

LCD_DSY_BUFFER2[15]= ‘] ’;

}

else

if(K2==0)//加

{

while(K2==0);DateTime_ Adjust(1);

}

else

if(K3==0)//减

{

while(K3==0);DateTime_ Adjust(-1);

}

else

if(K4==0)//确定

{

while(K4==0)

SET_DS1302();//调整后的时间写入DS1302

LCD_DSY_BUFFER2[13]=’’;

LCD_DSY_BUFFER2[14]=’’;

LCD_DSY_BUFFER2[15]=’’;

Adjust_Index=-1;

}

}

/*主程序*/

void main()

{

Init_LCD();//LCD初始化

IE=0x83;//允许INT0,T0中断

IP=0x01;

IT0=0x01;

TMOD=0X01;

TH0=-50000/256;

TL0=-50000%256;

TR0=1;

while(1)

{

if(Adjust_Index==-1) GetTime();

}

}


看上去你的程序中抄网上的,可以说网上程序99%都是不能被编译的

你程序最多的错是很多(修改有一定的工作量的)的符号是中文全角的

uchar *WEEK[]={“sun”, “mon”, “tus”, “wen”, “thu”, “fri”, “sat”};//周日,周一到周六

正确的是

uchar *WEEK[]={"sun", "mon", "tus", "wen", "thu", "fri", "sat"};//周日,周一到周六

你程序中的引号,单引号基本都是错的

这个要一点点修改了


相关标签:大神

下一篇:什么是web前端

上一篇:excel的问题

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?