|
本帖最后由 dwhdeng 于 2019-12-12 20:34 编辑
中断内为void string(uchar ad,uchar *s){
write_command(ad);
while(*s>0)
{
write_data(*s++);
}
}
1602显示函数
该函数在主程序中能够完成显示功能
但在中断内会得到图片中断后的效果
求大佬解答代码如下
- #include<reg52.h>
- #include<absacc.h>
- #include<stdio.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define out P0
- sbit RS=P2^0;
- sbit RW=P2^1;
- sbit E=P2^2;
- sbit ctime=P3^2;//ía2¿ÖD¶Ï0,ê±¼äD£×¼
- sbit s_alarm=P3^3;//ía2¿ÖD¶Ï1£¬ÄÖÖóé趨
- //Îå¸ö°′¼üμíμçƽóDD§,éÏÏÂ×óóò è·èÏ 1234 0
- void lcd_initial(void);
- void lcd_initial2(void);
- void check_busy(void);
- void write_command(uchar com);
- void write_data(uchar dat);
- void string(uchar ad,uchar*s);
- void delay(uint);
- int read_keys(void);
- void c_string(uchar ad,uchar s);
- void write_time(void);
- struct xwei
- {
- uchar x_address;//ÏÔê¾ÆáμÄμØÖ·
- uchar* zhi;//Ö¸Ïò′«μYÖμμÄÖ¸Õë
- }wei[2][8];
- uchar code mdays[12]={31,29,31,30,31,30,31,31,30,31,30,31};
- uchar code weeks[7][5]={"Mon","Tues","Wed","Thur","Fri","Sat","Sun"};
- uchar code tab1[]={" - - "};
- uchar code tab2[]={" : : T= "};
- uchar second[3]={53,57};//¼Ç¼s//ËùóDêyÖμ¾ùòÔASCIIÖμ±íê¾
- uchar minute[3]={53,57};//¼Ç¼min
- uchar hour[3]={50,51};//¼Ç¼h
- uchar day[3]={51,49};//¼Ç¼èÕ
- uchar month[3]={49,50};//¼Ç¼ÔÂ
- uchar year[5]={50,48,49,56};//¼Ç¼Äê
- uchar week=7;//¼Ç¼DÇÆú¼¸
- uchar x=0,y=0;//1a±êλÖÃ
- uchar pFlag=1;
- uint timer=0;//ÖD¶Ï¼Ç¼±äá¿
- int B_state_tag=-1;//°′¼ü×′쬱ê¼Çλ
- void timer1() interrupt 1 using 0//»ù±¾ê±Öó
- {
- timer++;
- if(timer==10000)
- {
- timer=0;
- second[1]++;
- if(second[1]%58==0)
- {
- second[1]=48;
- second[0]++;
- if(second[0]%54==0)
- {
- second[0]=48;
- minute[1]++;
- }
- }
- if(minute[1]%58==0)
- {
- minute[1]=48;
- minute[0]++;
- if(minute[0]%54==0)
- {
- minute[0]=48;
- hour[1]++;
- }
- }
- if(hour[1]%58==0)
- {
- hour[1]=48;
- hour[0]++;
- }
- if(hour[0]%50==0&&hour[1]%52==0)
- {
- hour[0]=48;
- hour[1]=48;
- day[1]++;
- week++;
- if(week==8)
- week=1;
- }
- if(day[1]%58==0)
- {
- day[1]=48;
- day[0]++;
- }
- if((day[0]==((mdays[month[1]-48+(month[0]-48)*10-1]/10+48)))&&day[1]%((mdays[month[1]-1-48+(month[0]-48)*10]%10+48))==1)
- {
- day[1]=49;
- day[0]=48;
- month[1]+=1;
- }
- if(month[1]==58)
- {
- month[1]=48;
- month[0]+=1;
- }
- if(month[0]==49&&month[1]==51)
- {
- month[1]=49;
- month[0]=48;
- year[3]++;
- }
- }
- }
- void int0() interrupt 0 using 1//ê±¼äD£×¼
- {
- TR0=0;
- pFlag=1;
- //lcd_initial2();
- delay(1);
- x=0;
- y=0;
- while(pFlag)
- {
- while(read_keys()==-1);//μè′y°′¼ü°′ÏÂ
- B_state_tag=read_keys();
- x=B_state_tag-1;//éÏÏ°′¼üÑ¡ÔñèÕÆú»òÕßê±¼ä
- while(pFlag)//°′¼üóëÏÔê¾Æá2ù×÷
- {
- while(read_keys()==-1);
- B_state_tag=read_keys();//¶áè¡°′¼üÖμ
- while(read_keys()!=-1);
- switch(B_state_tag)
- {
- case 1://éÏ
- {
-
- }break;
- case 2://ÏÂ
- {
-
- }break;
- case 3://×ó
- {
- if(y==0)//Ôúμúò»áDÔòÖ±½ó·μ»Ø
- break;
- y--;
-
- }break;
- case 4://óò
- {
- if(y==7)//Ôú×îoóò»áDÔòÖ±½ó·μ»Ø
- break;
- y++;
-
- }break;
- case 0://è·èÏ
- {
- pFlag=0;
- }break;
- default:break;
- }
- while(read_keys()!=-1);
- }
- }
- TR0=1;
- }
- void int1() interrupt 2//1|ÄüÑ¡Ôñ
- {
-
- }
- //Ïμí3ê±ÖóÎa12MHZ
- void main()
- {
- lcd_initial();
-
- EA=1;
- //ê1Äü¶¨ê±Æ÷ÖD¶Ï2¢¿aÆô¶¨ê±Æ÷
- ET0=1;
- TR0=1;
- //ê1Äüὸöía2¿ÖD¶Ï2¢½«Æäé趨ÎaìøÑØ′¥·¢
- EX0=1;
- IT0=1;
- EX1=1;
- IT1=1;
-
- //ê1óö¨ê±Æ÷0£¬×ö¼ÆêyÆ÷
- TMOD=0x02;
- TH0=0x9C;//100us ÖD¶Ïò»′Î
- TL0=0x9C;
-
- P1=0xff;//¶áè¡°′¼ü£¬ÏèD′èë
- string(0x80,tab1);
- string(0xc0,tab2);
- while(1)
- {
- write_time();
- }
- }
- //1602 oˉêy
- void check_busy(void)
- {
- uchar dt;
- do
- {
- dt=0xff;
- E=0;
- RS=0;
- RW=1;
- E=1;
- dt=out;
- }while(dt&0x80);
- E=0;
- }
- void write_command(uchar com)
- {
- check_busy();
- E=0;
- RS=0;
- RW=0;
- out=com;
- E=1;
- _nop_();
- E=0;
- delay(1);
- }
- void write_data(uchar dat)
- {
- check_busy();
- E=0;
- RS=1;
- RW=0;
- out=dat;
- E=1;
- _nop_();
- E=0;
- delay(1);
- }
- void lcd_initial(void)
- {
- write_command(0x38);
- _nop_();
- write_command(0x0e);
- _nop_();
- write_command(0x06);
- _nop_();
- write_command(0x01);
- delay(1);
- //ÏÔê¾ÆáéÏμØÖ·,±äá¿μØÖ·
- wei[0][0].x_address=0x80;
- wei[1][0].x_address=0xc0;
- wei[0][1].x_address=0x81;
- wei[1][1].x_address=0xc1;
- wei[0][2].x_address=0x82;
- wei[1][2].x_address=0xc3;
- wei[0][3].x_address=0x83;
- wei[1][3].x_address=0xc4;
- wei[0][4].x_address=0x85;
- wei[1][4].x_address=0xc6;
- wei[0][5].x_address=0x86;
- wei[1][5].x_address=0xc7;
- wei[0][6].x_address=0x88;
- wei[1][6].x_address=0xc9;
- wei[0][7].x_address=0x89;
-
- wei[0][0].zhi=&year[0];
- wei[0][1].zhi=&year[1];
- wei[0][2].zhi=&year[2];
- wei[0][3].zhi=year+3;
-
- wei[0][4].zhi=month;
- wei[0][5].zhi=month+1;
-
- wei[0][6].zhi=day;
- wei[0][7].zhi=day+1;
-
- wei[1][0].zhi=hour;
- wei[1][1].zhi=hour+1;
-
- wei[1][2].zhi=minute;
- wei[1][3].zhi=minute+1;
-
- wei[1][4].zhi=second;
- wei[1][5].zhi=second+1;
- }
- void lcd_initial2(void)
- {
- write_command(0x38);
- _nop_();
- write_command(0x0e);
- _nop_();
- write_command(0x06);
- _nop_();
- write_command(0x01);
- delay(1);
- write_time();
- delay(5);
- write_command(0x00);
- delay(2);
- }
- void string(uchar ad,uchar *s)
- {
- write_command(ad);
- while(*s>0)
- {
- write_data(*s++);
- }
- }
- void c_string(uchar ad,uchar *s)
- {
- write_command(ad);
- write_data(*s);
- }
- int read_keys(void)
- {
- switch(P1)
- {
- case 247 :return 1;
- case 239 :return 2;
- case 223 :return 3;
- case 191 :return 4;
- case 127 :return 0;
- default :return -1;
- }
- }
- void delay(uint j)
- {
- uchar i=250;
- for(;j>0;j--)
- {
- while(--i);
- i=249;
- while(--i);
- i=250;
- }
- }
- void write_time(void)
- {
- string(0x80,year);
- string(0x85,month);
- string(0x88,day);
- string(0xC0,hour);
- string(0xC3,minute);
- string(0xC6,second);
- string(0xC9,weeks[week-1]);
- }
复制代码
|
|