18B20.c(128): error C141: syntax error near 'void', expected '__asm'
新手求助,謝謝大家
單片機源程序如下:
- #include <reg52.h>
- sbit RS=P2^0;
- sbit RW=P2^1;
- sbit E=P1^2;
- sbit DQ=P1^4;
- int readtemp=0;
- unsigned char str[]={"0123456789"};
- unsigned char s[]={"Temperature:"};
- void delay(unsigned int n)
- {
- unsigned i=0,j=0;
- for(i=0;i<n;i++)
- {
- for(j=0;j<120;j++);
- }
- }
- void Init_DS18B20(void) //3õê¼»ˉ
- {
- unsigned char x=0;
- DQ = 1;
- delay(8);
- DQ = 0;
- delay(80);
- DQ = 1;
- delay(14);
- x=DQ;
- delay(20);
- }
- unsigned char ReadOneChar(void)
- {
- unsigned char i=0;
- unsigned char dat = 0;
- for (i=8;i>0;i--)
- {
- DQ = 0;
- dat>>=1;
- DQ = 1;
- if(DQ)
- dat|=0x80;
- delay(4);
- }
- return(dat);
- }
-
- void WriteOneChar(unsigned char dat)
-
- {
- unsigned char i=0;
- for (i=8; i>0; i--)
- {
- DQ = 0;
- DQ = dat&0x01;
- if(DQ){delay(1);DQ=1;}
- else{delay(5);DQ = 1;}
- dat>>=1;
- }
- }
- unsigned char ReadTemperature(void)//¶áζè
- {
- unsigned char a=0,b=0;
- unsigned int temp=0;
- Init_DS18B20();
- WriteOneChar(0xCC);
- WriteOneChar(0x44);
- delay(100); //
- Init_DS18B20();
- WriteOneChar(0xCC);
- WriteOneChar(0xBE);
- delay(100);
- a=ReadOneChar();
- b=ReadOneChar();
- temp=((b*256+a)>>4);
- return(temp);
- }
- void writedat(unsigned char dat)
- {
- RS=1;
- RW=0;
- E=0;
- P1=dat;
- delay(5);
- E=1;
- E=0;
- }
- void writecom(unsigned char com)//D′Ãüáîoˉêy
- {
- RS=0;
- RW=0;
- E=0;
- P1=com;
- delay(5);
- E=1;
- E=0;
- }
- //********************************************************
- void lcd_send(unsigned char i,unsigned char j,unsigned char str[],unsigned char n)
- {
- //??:????i,??j,????,??????n
- unsigned char x=0;
- if(i==1)
- {writecom(0x80+j);}
- else
- {writecom(0x80+0x40+j);}
- for(x=0;x<n;x++)
- {
- writedat(str[x]);
- delay(150);
- }
- //********************************************************
- void initlcd()//3õê¼»ˉLCD1602
- {
- writecom(0x38);
- writecom(0x0c);
- writecom(0x06);
- writecom(0x01);
- }
- void display()//ÏÔê¾oˉêy
- {
- unsigned int temp0=0,temp1=0,temp2=0,i=0;
- temp0=readtemp/100;
- temp1=(readtemp%100)/10;
- temp2=readtemp%10;
- writecom(0x80);
- delay(5);
- while(s[i]!='\0')
- {
- writedat(s[i]);
- delay(5);
- i++;
- }
-
- writecom(0x80+0x40+5);
- delay(5);
- writedat(str[temp0]);
- delay(5);
- writedat(str[temp1]);
- delay(5);
- writedat(str[temp2]);
- delay(5);
- writedat(0xDF);
- delay(5);
- writedat('C');
- delay(5);
- }
- void main()
- {
- initlcd();
- while(1)
- {
- readtemp=ReadTemperature();
- display();
- }
- }
復制代碼
|