找回密码
 立即注册

QQ登录

只需一步,快速开始

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

51单片机秒表不显示提示 error C171: 'break': missing enclosing...

[复制链接]
跳转到指定楼层
楼主
#include<reg51.h>
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
unsigned char dula[]=(0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
                      0xf8,0x80,0x90);
unsigned char wela[]=(0xfe,0xfd,0xfb,0xf7);
unsigned char tab[4];
unsigned char sec,count;
void delay (unsigned int i)
{
while(i--);
}
void keytest()
{
if(key1==0)
{
delay(200);
if (key1==0)
{
TR0=1;
while(key1==0);
}
}
else if(key2==0)
{
delay(200);
if(key2==0)
{TR0=0;
while(key2==0);
}}
else if(key3==0)
{
delay(200);
if(key3==0)
{TR0=0;
sec=0;
count=0;
while(key3==0);}break;
}}      
void main()
{TMOD=0x01;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;
ET0=1;
while(1)
{unsigned char a=0;
keytest();
display();
}}
void T0()interrupt 1
{TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
count++;
if(count==100)
{count=0;
sec++;
if(sec==60)sec=0;
}}
void display()
{tab[0]=sec/10;
tab[1]=sec%10;
tab[2]=count/10;
tab[3]=count%10;
for(a=0;a<4;a++)
{switch(a)
{case 0:P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
case 1:P1=wela[a];P2=dula[tab[a]]&0x7f;delay(500);P1=0xff;break;
case 2:P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
case 3:P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
}
}}

IMG_20200912_105934.jpg (3.03 MB, 下载次数: 126)

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

使用道具 举报

沙发
ID:332444 发表于 2020-9-12 14:40 | 只看该作者
查找171行往前的错误
回复

使用道具 举报

板凳
ID:155507 发表于 2020-9-12 18:34 | 只看该作者
给你改了一下试试。

  1. #include <reg51.h>
  2. sbit key1=P3^0;
  3. sbit key2=P3^1;
  4. sbit key3=P3^2;
  5. unsigned char dula[]=(0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
  6. 0xf8,0x80,0x90);
  7. unsigned char wela[]=(0xfe,0xfd,0xfb,0xf7);
  8. unsigned char tab[4];
  9. unsigned char sec,count;
  10. void delay (unsigned int i)
  11. {
  12.         while(i--);
  13. }
  14. void keytest()
  15. {
  16.         if(key1==0)
  17.         {
  18.                 delay(200);
  19.                 if (key1==0)
  20.                 {
  21.                         TR0=1;
  22.                         while(key1==0);
  23.                 }
  24.         }
  25.         else if(key2==0)
  26.         {
  27.                 delay(200);
  28.                 if(key2==0)
  29.                 {
  30.                         TR0=0;
  31.                         while(key2==0);
  32.                 }
  33.         }
  34.         else if(key3==0)
  35.         {
  36.                 delay(200);
  37.                 if(key3==0)
  38.                 {
  39.                         TR0=0;
  40.                         sec=0;
  41.                         count=0;
  42.                         while(key3==0);
  43.                        
  44.                 }//break;
  45.         }
  46. }      
  47. void main()
  48. {
  49.         TMOD=0x01;
  50.         TH0=(65536-10000)/256;
  51.         TL0=(65536-10000)%256;
  52.         EA=1;
  53.         ET0=1;
  54.         while(1)
  55.         {
  56.                 unsigned char a=0;
  57.                 keytest();
  58.                 display();
  59.         }
  60. }
  61. void T0()interrupt 1
  62. {
  63.         TH0=(65536-10000)/256;
  64.         TL0=(65536-10000)%256;
  65.         count++;
  66.         if(count==100)
  67.         {
  68.                 count=0;
  69.                 sec++;
  70.                 if(sec==60) sec=0;
  71.         }
  72. }
  73. void display()
  74. {
  75.         tab[0]=sec/10;
  76.         tab[1]=sec%10;
  77.         tab[2]=count/10;
  78.         tab[3]=count%10;
  79.         for(a=0;a<4;a++)
  80.         {
  81.                 switch(a)
  82.                 {
  83.                 case 0: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
  84.                 case 1: P1=wela[a];P2=dula[tab[a]]&0x7f;delay(500);P1=0xff;break;
  85.                 case 2: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
  86.                 case 3: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
  87.                 }
  88.         }
  89. }

复制代码
回复

使用道具 举报

地板
ID:701099 发表于 2020-9-12 22:35 | 只看该作者
angmall 发表于 2020-9-12 18:34
给你改了一下试试。

不行,显示错误wenc.c(58): warning C206: 'display': missing function-prototype
wenc.c(62): error C231: 'T0': redefinition
wenc.c(72): error C231: 'T0': redefinition
wenc.c(74): error C231: 'display': redefinition
wenc.c(79): error C202: 'a': undefined identifier
wenc.c(81): error C202: 'a': undefined identifier
wenc.c(83): error C202: 'a': undefined identifier
wenc.c(83): error C202: 'a': undefined identifier
wenc.c(84): error C202: 'a': undefined identifier
wenc.c(84): error C202: 'a': undefined identifier
wenc.c(85): error C202: 'a': undefined identifier
wenc.c(85): error C202: 'a': undefined identifier
wenc.c(86): error C202: 'a': undefined identifier
wenc.c(86): error C202: 'a': undefined identifier
wenc.c(89): error C231: 'display': redefinition
wenc.c - 14 Error(s), 1 Warning(s).
回复

使用道具 举报

5#
ID:155507 发表于 2020-9-12 23:22 | 只看该作者
  1. #include <reg51.h>
  2. sbit key1=P3^0;
  3. sbit key2=P3^1;
  4. sbit key3=P3^2;
  5. unsigned char dula[]=(0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
  6. 0xf8,0x80,0x90);
  7. unsigned char wela[]=(0xfe,0xfd,0xfb,0xf7);
  8. unsigned char tab[4];
  9. unsigned char sec,count;
  10. void delay (unsigned int i)
  11. {
  12.         while(i--);
  13. }
  14. void keytest()
  15. {
  16.         if(key1==0)
  17.         {
  18.                 delay(200);
  19.                 if (key1==0)
  20.                 {
  21.                         TR0=1;
  22.                         while(key1==0);
  23.                 }
  24.         }
  25.         else if(key2==0)
  26.         {
  27.                 delay(200);
  28.                 if(key2==0)
  29.                 {
  30.                         TR0=0;
  31.                         while(key2==0);
  32.                 }
  33.         }
  34.         else if(key3==0)
  35.         {
  36.                 delay(200);
  37.                 if(key3==0)
  38.                 {
  39.                         TR0=0;
  40.                         sec=0;
  41.                         count=0;
  42.                         while(key3==0);
  43.                        
  44.                 }//break;
  45.         }
  46. }
  47. void display()
  48. {
  49.         unsigned char a=0;
  50.        
  51.         tab[0]=sec/10;
  52.         tab[1]=sec%10;
  53.         tab[2]=count/10;
  54.         tab[3]=count%10;
  55.         for(a=0;a<4;a++)
  56.         {
  57.                 switch(a)
  58.                 {
  59.                 case 0: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
  60.                 case 1: P1=wela[a];P2=dula[tab[a]]&0x7f;delay(500);P1=0xff;break;
  61.                 case 2: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
  62.                 case 3: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
  63.                 }
  64.         }
  65. }
  66.      
  67. void main()
  68. {
  69.         TMOD=0x01;
  70.         TH0=(65536-10000)/256;
  71.         TL0=(65536-10000)%256;
  72.         EA=1;
  73.         ET0=1;
  74.         while(1)
  75.         {
  76.                
  77.                 keytest();
  78.                 display();
  79.         }
  80. }
  81. void Timer0() interrupt 1
  82. {
  83.         TH0=(65536-10000)/256;
  84.         TL0=(65536-10000)%256;
  85.         count++;
  86.         if(count==100)
  87.         {
  88.                 count=0;
  89.                 sec++;
  90.                 if(sec==60) sec=0;
  91.         }
  92. }

复制代码
回复

使用道具 举报

6#
ID:701099 发表于 2020-9-13 13:46 | 只看该作者

编译没有问题,但是数码管还是不显示

a.png (74.32 KB, 下载次数: 120)

a.png
回复

使用道具 举报

7#
ID:65956 发表于 2020-9-14 09:17 | 只看该作者
lidadaccd 发表于 2020-9-13 13:46
编译没有问题,但是数码管还是不显示

你这原理图不对应你的程序的,你要在网上找个164驱动的芯片显示函数就可以了
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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