找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7301|回復: 6
收起左側

51單片機秒表不顯示提示 error C171: 'break': missing enclosing...

[復制鏈接]
ID:701099 發(fā)表于 2020-9-12 11:56 | 顯示全部樓層 |閱讀模式
#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
回復

使用道具 舉報

ID:332444 發(fā)表于 2020-9-12 14:40 | 顯示全部樓層
查找171行往前的錯誤
回復

使用道具 舉報

ID:155507 發(fā)表于 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 發(fā)表于 2020-9-12 22:35 | 顯示全部樓層
angmall 發(fā)表于 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).
回復

使用道具 舉報

ID:155507 發(fā)表于 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. }

復制代碼
回復

使用道具 舉報

ID:701099 發(fā)表于 2020-9-13 13:46 | 顯示全部樓層

編譯沒有問題,但是數(shù)碼管還是不顯示
a.png
回復

使用道具 舉報

ID:65956 發(fā)表于 2020-9-14 09:17 | 顯示全部樓層
lidadaccd 發(fā)表于 2020-9-13 13:46
編譯沒有問題,但是數(shù)碼管還是不顯示

你這原理圖不對應你的程序的,你要在網(wǎng)上找個164驅動的芯片顯示函數(shù)就可以了
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表