找回密码
 立即注册

QQ登录

只需一步,快速开始

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

单片机中断程序编写时钟出现不会调用程序是什么回事?

[复制链接]
跳转到指定楼层
楼主
我便写完程序后下载到单片机里只能初始化,时钟不会走动
并且出现警告


时钟程序.docx

13.56 KB, 下载次数: 8

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

使用道具 举报

沙发
ID:164602 发表于 2020-8-28 17:32 | 只看该作者
你的截图显示的警告是那个函数没被调用。为什么没被调用?是不是你说的什么中断程序没被调用?我看不到程序,当然就不知道了嘛。
回复

使用道具 举报

板凳
ID:155507 发表于 2020-8-28 17:35 | 只看该作者
给你改了,对比一下就知道哪里错了。



  1. #include <reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. sbit dula=P2^6;
  5. sbit wela=P2^7;
  6. sbit lcdrs=P3^5;
  7. sbit lcdwr=P3^6;
  8. sbit lcden=P3^4;
  9. uchar code table[]="  2020-8-27 Thu";
  10. uchar code table1[]="   00:00:00";
  11. void write_com(uchar com);
  12. void write_data(uchar dat);
  13. void write_sfm(uchar add,uchar date);
  14. uchar n,shi=11,fen=50,miao=50;
  15. void delay(uint z)
  16. {       
  17.         uint x,y;
  18.         for(x=z;x>0;x--)
  19.         {
  20.                 for(y=110;y>0;y--)
  21.                 {
  22.                 }       
  23.         }
  24. }
  25. void init()
  26. {
  27.         uchar a;
  28.         miao=0;
  29.         dula=0;
  30.         wela=0;
  31.         lcdrs=0;
  32.         lcdwr=0;
  33.         lcden=0;
  34.         write_com(0x38);
  35.         write_com(0x0c);
  36.         write_com(0x06);
  37.         write_com(0x01);
  38.         write_com(0x80);
  39.         for(a=0;a<15;a++)
  40.         {
  41.                 write_data(table[a]);
  42.                 delay(5);
  43.         }
  44.         write_com(0x80+0x40);
  45.         for(a=0;a<11;a++)
  46.         {
  47.                 write_data(table1[a]);
  48.                 delay(5);
  49.         }
  50.         TMOD=0x01;
  51.         TH0=(65536-50000)/256;
  52.         TL0=(65536-50000)%256;
  53.         EA=1;
  54.         ET0=1;
  55.         TR0=1;
  56. }
  57. void write_com(uchar com)
  58. {
  59.         lcdrs=0;
  60.         lcdwr=0;
  61.         lcden=0;
  62.         P0=com;
  63.         delay(5);
  64.         lcden=1;
  65.         delay(15);
  66.         lcden=0;
  67. }
  68. void write_data(uchar dat)
  69. {
  70.         lcdrs=1;
  71.         lcdwr=0;
  72.         lcden=0;
  73.         P0=dat;
  74.         delay(5);
  75.         lcden=1;
  76.         delay(15);
  77.         lcden=0;
  78. }
  79. void main()
  80. {
  81.         init();
  82.         while(1)  //;  多写分号
  83.         {
  84.                 if(n==20)
  85.                 {
  86.                         n=0;
  87.                         miao++;
  88.                         if(miao==60)
  89.                         {
  90.                                 miao=0;
  91.                                 fen++;
  92.                                 if(fen==60)
  93.                                 {
  94.                                         fen=0;
  95.                                         shi++;
  96.                                         if(shi==24)
  97.                                         {
  98.                                                 shi=0;
  99.                                         }
  100.                                 }
  101.                         }
  102.                         write_sfm(9,miao);
  103.                         write_sfm(6,fen);
  104.                         write_sfm(3,shi);
  105.                        
  106.                 }       
  107.         }
  108. }

  109. void write_sfm(uchar add,uchar date)
  110. {
  111.         uchar shi,ge;
  112.         shi=date/10;
  113.         ge=date%10;
  114.         write_com(0x80+0x40+add);
  115.         write_data(0x30+shi);
  116.         write_data(0x30+ge);
  117. }

  118. void timer0() interrupt 1
  119. {       
  120.         TH0=(65536-50000)/256;
  121.         TL0=(65536-50000)%256;
  122.         n++;
  123. }


复制代码
回复

使用道具 举报

地板
ID:213173 发表于 2020-8-28 17:37 | 只看该作者
void main()
{
        init();
        while(1)//; 多了分号
        {
                if(n==20)
                {
                        n=0;
                        miao++;
                        if(miao==60)
                        {
                                miao=0;
                                fen++;
                                if(fen==60)
                                {
                                        fen=0;
                                        shi++;
                                        if(shi==24)
                                        {
                                                shi=0;
                                        }
                                }
                        }
                        write_sfm(3,shi);//添加时
                        write_sfm(6,fen);//添加分
                        write_sfm(9,miao);//改秒位置
                }       
        }
}
回复

使用道具 举报

5#
ID:816038 发表于 2020-8-29 09:21 | 只看该作者
angmall 发表于 2020-8-28 17:35
给你改了,对比一下就知道哪里错了。

谢谢您
回复

使用道具 举报

6#
ID:816038 发表于 2020-8-29 09:31 | 只看该作者
wulin 发表于 2020-8-28 17:37
void main()
{
        init();

谢谢您   
回复

使用道具 举报

7#
ID:816038 发表于 2020-8-29 09:52 | 只看该作者
HC6800-ES-V2.0 发表于 2020-8-28 17:32
你的截图显示的警告是那个函数没被调用。为什么没被调用?是不是你说的什么中断程序没被调用?我看不到程序 ...

找到问题了,while后面多了个分号   
回复

使用道具 举报

8#
ID:130230 发表于 2020-9-2 23:53 | 只看该作者
出问题了进debug模式单步执行看看程序卡在哪里。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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