找回密码
 立即注册

QQ登录

只需一步,快速开始

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

大神们帮个忙为什么我的程序会有这些错误》》

[复制链接]
跳转到指定楼层
楼主
ID:64215 发表于 2014-9-25 20:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned uchar
#define uint unsigned uint

sbit trig=P1^2;
sbit echo=P1^0;

sbit LCD_RS=P1^0;
sbit LCD_RW=P1^1;
sbit LCD_EN=P1^2;
sbit LCD_PSB=P1^6;

bit flag;

void delay(uchar x )
{
  uchar i,j;
  for(j=0;j<x;j++)
          for(i=0;i<110;i++);
}
void write_cmd(uchar cmd)
{
        LCD_RS=0;
        LCD_RW=0;
        LCD_EN=0;
        P0=cmd;
        delay(5);
        LCD_EN=1;
        delay(5);
        LCD_EN=0;
}
void write_dat(uchar dat)
{
        LCD_RS=1;
        LCD_RW=0;
        LCD_EN=0;
        P0=dat;
        delay(5);
        LCD_EN=1;
        delay(5);
        LCD_EN=0;
}

void lcd_init()
{
        LCD_PSB=1;
        write_cmd(0x30);
        delay(5);
    write_cmd(0x0c);
        delay(5);
        write_cmd(0x01);
        delay(5);
}

void init()
{
        TMOD=0x01;
        TH0=0;
        TL0=0;
        TR0=0;
        IT0=1;
        EX0=1;
        EA=1;
        lcd_init();
}
uint test_distance(void)
{
        uint value;
        TH0=0;
        TL0=0;
        trig=0;
        _nop()_;
        trig=1;
        _nop_();_nop_();_nop_();_nop_();_nop_();
        _nop_();_nop_();_nop_();_nop_();_nop_();
        trig=0;
        while(!echo);
        TR0=1;
        while(echo);
        TR0=0;
        value=TH0*256+TL0;
        return value;       
}

void timer() interrupt 0;
{
        flag=1;
}

void lcd_pos(uchar x, uchar y)
{
        uchar pos;

        if(x == 0)           // 第一行的地址是80H
        {
                x = 0x80;
        }
               
        else if(x == 1)  //第二行的地址是90H
        {
                x = 0x90;       
        }
       
        else if(x == 2)  //第三行的地址是88H
        {
                x = 0x88;
        }
       
        else if(x == 3)
        {
                x = 0x98;
        }
       
        pos = x + y;
        write_cmd(pos);
}


void main()
{       
    uchar table[4];
        uint value;
        uint a,b,c,d,e,i;
        init();
        while(1)
        {
                if(flag)
                {
                        flag=0;
                        value=test_distance();
                           a=value/100;
                        b=a/2;
                        c=b*340;
                        e=c/10;
                        table[0]=e/1000;
                        table[1]=(e%1000)/100;
                        table[2]=((e%1000)%100)/10;
                    table[3]=e%10;
                        delay(5);
                        EA=1;
                }
        lcd_pos(0,0);
       
        for(i=0;i<4;i++)
        {
                write_dat(table[i]+0x30);
               
        }
       
        }
}



SS.C(16): error C141: syntax error near 'x', expected ')'
SS.C(18): error C231: 'uchar': redefinition
SS.C(18): error C141: syntax error near 'i'
SS.C(19): error C202: 'x': undefined identifier
SS.C(22): error C141: syntax error near 'cmd', expected ')'
SS.C(27): error C202: 'cmd': undefined identifier
SS.C(33): error C141: syntax error near 'dat', expected ')'
SS.C(38): error C202: 'dat': undefined identifier
SS.C(66): error C141: syntax error near ';'
SS.C(67): error C129: missing ';' before 'test_distance'
Target not created

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

使用道具 举报

沙发
ID:66661 发表于 2014-9-26 10:24 | 只看该作者
回复

使用道具 举报

板凳
ID:66665 发表于 2014-9-26 12:17 | 只看该作者
undefined identifier 未定义      其他很多都是未在英文状态下写的所以出错了,重新写一遍就好了
回复

使用道具 举报

地板
ID:2318 发表于 2014-9-26 12:40 来自手机 | 只看该作者
幻灭想 发表于 2014-9-26 12:17
undefined identifier 未定义      其他很多都是未在英文状态下写的所以出错了,重新写一遍就好了

这个答案是正解
回复

使用道具 举报

5#
ID:58502 发表于 2014-9-26 18:48 | 只看该作者
#define uchar unsigned uchar
#define uint unsigned uint
这两句定义错了,后面的uchar改为char,后面的uint改为int,
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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