标题: 编译错误EX20.C(71): error C202: 'sound': undefined identifier,要怎么修改 [打印本页]

作者: 建筑人生    时间: 2015-7-25 20:59
标题: 编译错误EX20.C(71): error C202: 'sound': undefined identifier,要怎么修改
#include<reg51.h>  //包含单片机寄存器的头文件
sbit S1=P0^4;     //将S1位定义为P1.4
sbit Sound=P3^6;     //将S1位定义为P1.4
/*****************************
函数功能:延时一段时间
*****************************/
void delay(void)
{
unsigned int n;
for(n=0;n<10000;n++)
        ;
}  
/*****************************/
   void delay1600(void)
{
unsigned int n;
for(n=0;n<100;n++)
        ;
}
   void delay800(void)
{
unsigned int n;
for(n=0;n<200;n++)
        ;
}
   
/*****************************
函数功能:主函数
*****************************/
void main(void)
{  
   unsigned int i;     //unsigned
   unsigned int j;  
  
   i=0;    //将i初始化为0
while(1)
  {
    if(S1==0)     //如果S1键按下
     {
     delay();  //延时一段时间
     if(S1==0) //如果再次检测到S1键按下
       i++;    //i自增1
     if(i==9)  //如果i=9,重新将其置为1
       i=1;   
     }
   switch(i)   //使用多分支选择语句
     {
       case 1: P1=0xfe;  //第一个LED亮
         
       //  sound=0;
       /*****************************/
       // unsigned int j;
           //sbit Sound=P3^6;
       for(j=0;j<830;j++)
      
      {
       sound=0;
       delay1600();
      sound=1;
       delay1600();
       }
      for(j=0;j<200;j++)
     
      {
      sound=0;
       delay800();
       sound=1;
       delay800();
       }
      
       /*****************************/
         break;
      
     case 2: P1=0xfd;  //第二个LED亮
           break;
     case 3:P1=0xfb;   //第三个LED亮
           break;
     case 4:P1=0xf7;   //第四个LED亮
           break;
     case 5:P1=0xef;   //第五个LED亮
           break;
     case 6:P0=0xdf;   //第六个LED亮
           break;
     case 7:P1=0xbf;   //第七个LED亮
             break;
     case 8:P1=0x7f;   //第八个LED亮
           break;
     default:   //缺省值,关闭所有LED
           P1=0xff;
     }
   }   
}

以上代码错误提示   EX20.C(71): error C202: 'sound': undefined identifier,要怎么修改

作者: sxlwh    时间: 2015-7-25 22:05
位定义的是Sound,下面写成sound了
作者: new116    时间: 2015-7-25 22:18
sound 定义 时和使用时的S 一个是大写,一个是小写,C语言是区分 大小写的,要一致




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1