找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 951|回复: 1
打印 上一主题 下一主题
收起左侧

proteus仿真1602,中断函数内显示函数无显示内容

[复制链接]
跳转到指定楼层
楼主
本帖最后由 dwhdeng 于 2019-12-12 20:34 编辑

中断内为void string(uchar ad,uchar *s){
        write_command(ad);
        while(*s>0)
        {
                write_data(*s++);
        }
}
1602显示函数
该函数在主程序中能够完成显示功能
但在中断内会得到图片中断后的效果
求大佬解答代码如下
  1. #include<reg52.h>
  2. #include<absacc.h>
  3. #include<stdio.h>
  4. #include<intrins.h>
  5. #define uchar unsigned char
  6. #define uint  unsigned int
  7. #define out P0
  8. sbit RS=P2^0;
  9. sbit RW=P2^1;
  10. sbit E=P2^2;
  11. sbit ctime=P3^2;//ía2¿ÖD¶Ï0,ê±¼äD£×¼
  12. sbit s_alarm=P3^3;//ía2¿ÖD¶Ï1£¬ÄÖÖóé趨
  13. //Îå¸ö°′¼üμíμçƽóDD§,éÏÏÂ×óóò è·èÏ 1234 0

  14. void lcd_initial(void);
  15. void lcd_initial2(void);
  16. void check_busy(void);
  17. void write_command(uchar com);
  18. void write_data(uchar dat);
  19. void string(uchar ad,uchar*s);
  20. void delay(uint);
  21. int read_keys(void);
  22. void c_string(uchar ad,uchar s);
  23. void write_time(void);

  24. struct xwei
  25. {
  26.         uchar x_address;//ÏÔê¾ÆáμÄμØÖ·
  27.         uchar* zhi;//Ö¸Ïò′«μYÖμμÄÖ¸Õë
  28. }wei[2][8];

  29. uchar code mdays[12]={31,29,31,30,31,30,31,31,30,31,30,31};
  30. uchar code weeks[7][5]={"Mon","Tues","Wed","Thur","Fri","Sat","Sun"};
  31. uchar code tab1[]={"    -  -   "};
  32. uchar code tab2[]={"  :  :    T=  "};
  33. uchar second[3]={53,57};//¼Ç¼s//ËùóDêyÖμ¾ùòÔASCIIÖμ±íê¾
  34. uchar minute[3]={53,57};//¼Ç¼min
  35. uchar hour[3]={50,51};//¼Ç¼h
  36. uchar day[3]={51,49};//¼Ç¼èÕ
  37. uchar month[3]={49,50};//¼Ç¼ÔÂ
  38. uchar year[5]={50,48,49,56};//¼Ç¼Äê
  39. uchar week=7;//¼Ç¼DÇÆú¼¸
  40. uchar x=0,y=0;//1a±êλÖÃ
  41. uchar pFlag=1;
  42. uint timer=0;//ÖD¶Ï¼Ç¼±äá¿
  43. int  B_state_tag=-1;//°′¼ü×′쬱ê¼Çλ

  44. void timer1() interrupt 1 using 0//»ù±¾ê±Öó
  45. {
  46.         timer++;
  47.         if(timer==10000)
  48.         {
  49.                 timer=0;
  50.                 second[1]++;
  51.                 if(second[1]%58==0)
  52.                 {
  53.                         second[1]=48;
  54.                         second[0]++;
  55.                         if(second[0]%54==0)
  56.                         {
  57.                                 second[0]=48;
  58.                                 minute[1]++;
  59.                         }
  60.                 }
  61.                 if(minute[1]%58==0)
  62.                 {
  63.                         minute[1]=48;
  64.                         minute[0]++;
  65.                         if(minute[0]%54==0)
  66.                         {
  67.                                 minute[0]=48;
  68.                                 hour[1]++;
  69.                         }
  70.                 }
  71.                 if(hour[1]%58==0)
  72.                 {
  73.                         hour[1]=48;
  74.                         hour[0]++;
  75.                 }
  76.                 if(hour[0]%50==0&&hour[1]%52==0)
  77.                 {
  78.                         hour[0]=48;
  79.                         hour[1]=48;
  80.                         day[1]++;
  81.                         week++;
  82.                         if(week==8)
  83.                                 week=1;
  84.                 }
  85.                 if(day[1]%58==0)
  86.                 {
  87.                         day[1]=48;
  88.                         day[0]++;
  89.                 }
  90.                 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)
  91.                 {
  92.                         day[1]=49;
  93.                   day[0]=48;
  94.                         month[1]+=1;
  95.                 }
  96.                 if(month[1]==58)
  97.                 {
  98.                         month[1]=48;
  99.                         month[0]+=1;
  100.                 }
  101.                 if(month[0]==49&&month[1]==51)
  102.                 {
  103.                         month[1]=49;
  104.                   month[0]=48;
  105.                         year[3]++;
  106.                 }
  107.         }
  108. }


  109. void int0() interrupt 0 using 1//ê±¼äD£×¼
  110. {
  111.         TR0=0;
  112.         pFlag=1;
  113.         //lcd_initial2();
  114.         delay(1);
  115.         x=0;
  116.         y=0;
  117.         while(pFlag)
  118.         {
  119.                 while(read_keys()==-1);//μè′y°′¼ü°′ÏÂ
  120.                 B_state_tag=read_keys();
  121.                 x=B_state_tag-1;//éÏÏ°′¼üÑ¡ÔñèÕÆú»òÕßê±¼ä
  122.                 while(pFlag)//°′¼üóëÏÔê¾Æá2ù×÷
  123.                 {
  124.                         while(read_keys()==-1);
  125.                         B_state_tag=read_keys();//¶áè¡°′¼üÖμ
  126.                         while(read_keys()!=-1);
  127.                         switch(B_state_tag)
  128.                         {
  129.                                 case 1://éÏ
  130.                                 {
  131.                                        
  132.                                 }break;
  133.                                 case 2://ÏÂ
  134.                                 {
  135.                                        
  136.                                 }break;
  137.                                 case 3://×ó
  138.                                 {
  139.                                         if(y==0)//Ôúμúò»áDÔòÖ±½ó·μ»Ø
  140.                                                 break;
  141.                                         y--;
  142.                                        
  143.                                 }break;
  144.                                 case 4://óò
  145.                                 {
  146.                                         if(y==7)//Ôú×îoóò»áDÔòÖ±½ó·μ»Ø
  147.                                                 break;
  148.                                         y++;
  149.                                        
  150.                                 }break;
  151.                                 case 0://è·èÏ
  152.                                 {
  153.                                         pFlag=0;
  154.                                 }break;
  155.                                 default:break;
  156.                         }
  157.                         while(read_keys()!=-1);
  158.                 }
  159.         }
  160.         TR0=1;
  161. }
  162. void int1() interrupt 2//1|ÄüÑ¡Ôñ
  163. {
  164.        
  165. }
  166. //Ïμí3ê±ÖóÎa12MHZ
  167. void main()
  168. {
  169.         lcd_initial();
  170.        
  171.         EA=1;
  172.         //ê1Äü¶¨ê±Æ÷ÖD¶Ï2¢¿aÆô¶¨ê±Æ÷
  173.         ET0=1;
  174.         TR0=1;
  175.         //ê1Äüὸöía2¿ÖD¶Ï2¢½«Æäé趨ÎaìøÑØ′¥·¢
  176.         EX0=1;
  177.         IT0=1;
  178.         EX1=1;
  179.         IT1=1;
  180.        
  181.         //ê1óö¨ê±Æ÷0£¬×ö¼ÆêyÆ÷
  182.         TMOD=0x02;
  183.         TH0=0x9C;//100us ÖD¶Ïò»′Î
  184.         TL0=0x9C;
  185.        
  186.         P1=0xff;//¶áè¡°′¼ü£¬ÏèD′èë
  187.         string(0x80,tab1);
  188.         string(0xc0,tab2);
  189.         while(1)
  190.         {
  191.                 write_time();
  192.         }
  193. }
  194. //1602 oˉêy
  195. void check_busy(void)
  196. {
  197.         uchar dt;
  198.         do
  199.         {
  200.                 dt=0xff;
  201.                 E=0;
  202.                 RS=0;
  203.                 RW=1;
  204.                 E=1;
  205.                 dt=out;
  206.         }while(dt&0x80);
  207.         E=0;
  208. }
  209. void write_command(uchar com)
  210. {
  211.         check_busy();
  212.         E=0;
  213.         RS=0;
  214.         RW=0;
  215.         out=com;
  216.         E=1;
  217.         _nop_();
  218.         E=0;
  219.         delay(1);
  220. }
  221. void write_data(uchar dat)
  222. {
  223.         check_busy();
  224.         E=0;
  225.         RS=1;
  226.         RW=0;
  227.         out=dat;
  228.         E=1;
  229.         _nop_();
  230.         E=0;
  231.         delay(1);
  232. }
  233. void lcd_initial(void)
  234. {
  235.         write_command(0x38);
  236.         _nop_();
  237.         write_command(0x0e);
  238.         _nop_();
  239.         write_command(0x06);
  240.         _nop_();
  241.         write_command(0x01);
  242.         delay(1);
  243.         //ÏÔê¾ÆáéÏμØÖ·,±äá¿μØÖ·
  244.           wei[0][0].x_address=0x80;
  245.         wei[1][0].x_address=0xc0;
  246.                 wei[0][1].x_address=0x81;
  247.         wei[1][1].x_address=0xc1;
  248.                 wei[0][2].x_address=0x82;
  249.         wei[1][2].x_address=0xc3;
  250.                 wei[0][3].x_address=0x83;
  251.         wei[1][3].x_address=0xc4;
  252.                 wei[0][4].x_address=0x85;
  253.         wei[1][4].x_address=0xc6;
  254.                 wei[0][5].x_address=0x86;
  255.         wei[1][5].x_address=0xc7;
  256.                 wei[0][6].x_address=0x88;
  257.         wei[1][6].x_address=0xc9;
  258.                 wei[0][7].x_address=0x89;
  259.                
  260.         wei[0][0].zhi=&year[0];
  261.         wei[0][1].zhi=&year[1];
  262.         wei[0][2].zhi=&year[2];
  263.         wei[0][3].zhi=year+3;
  264.        
  265.         wei[0][4].zhi=month;
  266.         wei[0][5].zhi=month+1;
  267.        
  268.         wei[0][6].zhi=day;
  269.         wei[0][7].zhi=day+1;
  270.        
  271.         wei[1][0].zhi=hour;
  272.         wei[1][1].zhi=hour+1;
  273.        
  274.         wei[1][2].zhi=minute;
  275.         wei[1][3].zhi=minute+1;
  276.        
  277.         wei[1][4].zhi=second;
  278.         wei[1][5].zhi=second+1;
  279. }
  280. void lcd_initial2(void)
  281. {
  282.         write_command(0x38);
  283.         _nop_();
  284.         write_command(0x0e);
  285.         _nop_();
  286.         write_command(0x06);
  287.         _nop_();
  288.         write_command(0x01);
  289.         delay(1);
  290.         write_time();
  291.         delay(5);
  292.         write_command(0x00);
  293.         delay(2);
  294. }
  295. void string(uchar ad,uchar *s)
  296. {
  297.         write_command(ad);
  298.         while(*s>0)
  299.         {
  300.                 write_data(*s++);
  301.         }
  302. }
  303. void c_string(uchar ad,uchar *s)
  304. {
  305.         write_command(ad);
  306.   write_data(*s);
  307. }

  308. int read_keys(void)
  309. {
  310.         switch(P1)
  311.         {
  312.                 case 247 :return  1;
  313.                 case 239 :return  2;
  314.                 case 223 :return  3;
  315.           case 191 :return  4;
  316.           case 127 :return  0;
  317.           default  :return -1;
  318.         }
  319. }
  320. void delay(uint j)
  321. {
  322.         uchar i=250;
  323.         for(;j>0;j--)
  324.         {
  325.                 while(--i);
  326.                 i=249;
  327.                 while(--i);
  328.                 i=250;
  329.         }
  330. }
  331. void write_time(void)
  332. {
  333.         string(0x80,year);
  334.         string(0x85,month);
  335.         string(0x88,day);
  336.         string(0xC0,hour);
  337.         string(0xC3,minute);
  338.         string(0xC6,second);
  339.         string(0xC9,weeks[week-1]);
  340. }
复制代码




1576152428(1).jpg (24.07 KB, 下载次数: 18)

中断前

中断前

1576152509(1).jpg (14.71 KB, 下载次数: 23)

中断后

中断后
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:591385 发表于 2019-12-12 20:28 | 只看该作者
代码如下:
  1. #include<reg52.h>
  2. #include<absacc.h>
  3. #include<stdio.h>
  4. #include<intrins.h>
  5. #define uchar unsigned char
  6. #define uint  unsigned int
  7. #define out P0
  8. sbit RS=P2^0;
  9. sbit RW=P2^1;
  10. sbit E=P2^2;
  11. sbit ctime=P3^2;
  12. sbit s_alarm=P3^3;


  13. void lcd_initial(void);
  14. void lcd_initial2(void);
  15. void check_busy(void);
  16. void write_command(uchar com);
  17. void write_data(uchar dat);
  18. void string(uchar ad,uchar*s);
  19. void delay(uint);
  20. int read_keys(void);
  21. void c_string(uchar ad,uchar s);
  22. void write_time(void);

  23. struct xwei
  24. {
  25.         uchar x_address;
  26.         uchar* zhi;
  27. }wei[2][8];

  28. uchar code mdays[12]={31,29,31,30,31,30,31,31,30,31,30,31};
  29. uchar code weeks[7][5]={"Mon","Tues","Wed","Thur","Fri","Sat","Sun"};
  30. uchar code tab1[]={"    -  -   "};
  31. uchar code tab2[]={"  :  :    T=  "};
  32. uchar second[3]={53,57};
  33. uchar minute[3]={53,57};
  34. uchar hour[3]={50,51};
  35. uchar day[3]={51,49};
  36. uchar month[3]={49,50};
  37. uchar year[5]={50,48,49,56};
  38. uchar week=7;
  39. uchar x=0,y=0;
  40. uchar pFlag=1;
  41. uint timer=0;
  42. int  B_state_tag=-1;

  43. void timer1() interrupt 1 using 0
  44. {
  45.         timer++;
  46.         if(timer==10000)
  47.         {
  48.                 timer=0;
  49.                 second[1]++;
  50.                 if(second[1]%58==0)
  51.                 {
  52.                         second[1]=48;
  53.                         second[0]++;
  54.                         if(second[0]%54==0)
  55.                         {
  56.                                 second[0]=48;
  57.                                 minute[1]++;
  58.                         }
  59.                 }
  60.                 if(minute[1]%58==0)
  61.                 {
  62.                         minute[1]=48;
  63.                         minute[0]++;
  64.                         if(minute[0]%54==0)
  65.                         {
  66.                                 minute[0]=48;
  67.                                 hour[1]++;
  68.                         }
  69.                 }
  70.                 if(hour[1]%58==0)
  71.                 {
  72.                         hour[1]=48;
  73.                         hour[0]++;
  74.                 }
  75.                 if(hour[0]%50==0&&hour[1]%52==0)
  76.                 {
  77.                         hour[0]=48;
  78.                         hour[1]=48;
  79.                         day[1]++;
  80.                         week++;
  81.                         if(week==8)
  82.                                 week=1;
  83.                 }
  84.                 if(day[1]%58==0)
  85.                 {
  86.                         day[1]=48;
  87.                         day[0]++;
  88.                 }
  89.                 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)
  90.                 {
  91.                         day[1]=49;
  92.                   day[0]=48;
  93.                         month[1]+=1;
  94.                 }
  95.                 if(month[1]==58)
  96.                 {
  97.                         month[1]=48;
  98.                         month[0]+=1;
  99.                 }
  100.                 if(month[0]==49&&month[1]==51)
  101.                 {
  102.                         month[1]=49;
  103.                   month[0]=48;
  104.                         year[3]++;
  105.                 }
  106.         }
  107. }


  108. void int0() interrupt 0 using 1
  109. {
  110.         TR0=0;
  111.         pFlag=1;
  112.         
  113.         delay(1);
  114.         x=0;
  115.         y=0;
  116.         while(pFlag)
  117.         {
  118.                 while(read_keys()==-1);
  119.                 B_state_tag=read_keys();
  120.                 x=B_state_tag-1;
  121.                 while(pFlag)
  122.                 {
  123.                         while(read_keys()==-1);
  124.                         B_state_tag=read_keys();
  125.                         while(read_keys()!=-1);
  126.                         switch(B_state_tag)
  127.                         {
  128.                                 case 1:
  129.                                 {
  130.                                        
  131.                                 }break;
  132.                                 case 2:
  133.                                 {
  134.                                        
  135.                                 }break;
  136.                                 case 3:
  137.                                 {
  138.                                         if(y==0)
  139.                                                 break;
  140.                                         y--;
  141.                                        
  142.                                 }break;
  143.                                 case 4:
  144.                                 {
  145.                                         if(y==7)
  146.                                                 break;
  147.                                         y++;
  148.                                        
  149.                                 }break;
  150.                                 case 0:
  151.                                 {
  152.                                         pFlag=0;
  153.                                 }break;
  154.                                 default:break;
  155.                         }
  156.                         while(read_keys()!=-1);
  157.                 }
  158.         }
  159.         TR0=1;
  160. }
  161. void int1() interrupt 2
  162. {
  163.         
  164. }
  165. //?μí3ê±?ó?a12M
  166. void main()
  167. {
  168.         lcd_initial();
  169.         
  170.         EA=1;
  171.         
  172.         ET0=1;
  173.         TR0=1;
  174.         
  175.         EX0=1;
  176.         IT0=1;
  177.         EX1=1;
  178.         IT1=1;
  179.         
  180.         
  181.         TMOD=0x02;
  182.         TH0=0x9C;
  183.         TL0=0x9C;
  184.         
  185.         P1=0xff;
  186.         string(0x80,tab1);
  187.         string(0xc0,tab2);
  188.         while(1)
  189.         {
  190.                 write_time();
  191.         }
  192. }
  193. //1602 oˉ
  194. void check_busy(void)
  195. {
  196.         uchar dt;
  197.         do
  198.         {
  199.                 dt=0xff;
  200.                 E=0;
  201.                 RS=0;
  202.                 RW=1;
  203.                 E=1;
  204.                 dt=out;
  205.         }while(dt&0x80);
  206.         E=0;
  207. }
  208. void write_command(uchar com)
  209. {
  210.         check_busy();
  211.         E=0;
  212.         RS=0;
  213.         RW=0;
  214.         out=com;
  215.         E=1;
  216.         _nop_();
  217.         E=0;
  218.         delay(1);
  219. }
  220. void write_data(uchar dat)
  221. {
  222.         check_busy();
  223.         E=0;
  224.         RS=1;
  225.         RW=0;
  226.         out=dat;
  227.         E=1;
  228.         _nop_();
  229.         E=0;
  230.         delay(1);
  231. }
  232. void lcd_initial(void)
  233. {
  234.         write_command(0x38);
  235.         _nop_();
  236.         write_command(0x0e);
  237.         _nop_();
  238.         write_command(0x06);
  239.         _nop_();
  240.         write_command(0x01);
  241.         delay(1);
  242.         
  243.           wei[0][0].x_address=0x80;
  244.         wei[1][0].x_address=0xc0;
  245.                 wei[0][1].x_address=0x81;
  246.         wei[1][1].x_address=0xc1;
  247.                 wei[0][2].x_address=0x82;
  248.         wei[1][2].x_address=0xc3;
  249.                 wei[0][3].x_address=0x83;
  250.         wei[1][3].x_address=0xc4;
  251.                 wei[0][4].x_address=0x85;
  252.         wei[1][4].x_address=0xc6;
  253.                 wei[0][5].x_address=0x86;
  254.         wei[1][5].x_address=0xc7;
  255.                 wei[0][6].x_address=0x88;
  256.         wei[1][6].x_address=0xc9;
  257.                 wei[0][7].x_address=0x89;
  258.                
  259.         wei[0][0].zhi=&year[0];
  260.         wei[0][1].zhi=&year[1];
  261.         wei[0][2].zhi=&year[2];
  262.         wei[0][3].zhi=year+3;
  263.         
  264.         wei[0][4].zhi=month;
  265.         wei[0][5].zhi=month+1;
  266.         
  267.         wei[0][6].zhi=day;
  268.         wei[0][7].zhi=day+1;
  269.         
  270.         wei[1][0].zhi=hour;
  271.         wei[1][1].zhi=hour+1;
  272.         
  273.         wei[1][2].zhi=minute;
  274.         wei[1][3].zhi=minute+1;
  275.         
  276.         wei[1][4].zhi=second;
  277.         wei[1][5].zhi=second+1;
  278. }
  279. void lcd_initial2(void)
  280. {
  281.         write_command(0x38);
  282.         _nop_();
  283.         write_command(0x0e);
  284.         _nop_();
  285.         write_command(0x06);
  286.         _nop_();
  287.         write_command(0x01);
  288.         delay(1);
  289.         write_time();
  290.         delay(5);
  291.         write_command(0x00);
  292.         delay(2);
  293. }
  294. void string(uchar ad,uchar *s)
  295. {
  296.         write_command(ad);
  297.         while(*s>0)
  298.         {
  299.                 write_data(*s++);
  300.         }
  301. }
  302. void c_string(uchar ad,uchar *s)
  303. {
  304.         write_command(ad);
  305.   write_data(*s);
  306. }

  307. int read_keys(void)
  308. {
  309.         switch(P1)
  310.         {
  311.                 case 247 :return  1;
  312.                 case 239 :return  2;
  313.                 case 223 :return  3;
  314.           case 191 :return  4;
  315.           case 127 :return  0;
  316.           default  :return -1;
  317.         }
  318. }
  319. void delay(uint j)
  320. {
  321.         uchar i=250;
  322.         for(;j>0;j--)
  323.         {
  324.                 while(--i);
  325.                 i=249;
  326.                 while(--i);
  327.                 i=250;
  328.         }
  329. }
  330. void write_time(void)
  331. {
  332.         string(0x80,year);
  333.         string(0x85,month);
  334.         string(0x88,day);
  335.         string(0xC0,hour);
  336.         string(0xC3,minute);
  337.         string(0xC6,second);
  338.         string(0xC9,weeks[week-1]);
  339. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表