帮我看看程序错在哪里了!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了帮我看看程序错在哪里了!相关的知识,希望对你有一定的参考价值。

我在用Keil编译下面这个C程序时总是提示语法错误,由于刚接触单片机,看了半天不知道错在哪里。
注:提示“sfr”附近语法错误。
谁能告诉我,这个于标准C不同的新类型,到底应该怎么用啊?
谢谢~

#include<at89x51.h>
#include<stdio.h>

void main(void)


int a;
SCON = 0x50; //串口方式1,允许接收
TH1 = 0xE8; //11.0592MHz 1200波特率
TL1 = 0xE8;
TI = 1;
sfr P1=0X90;
P1=1;
for(a=9;a>0;a--)

printf("The P1 is:%d\n",P1);
P1=P1-1;


把SFR去掉,因为在at89x51.h中己定义P1口。再次定义就重复了。

附加一个AT89X51.H的头文件:
/*--------------------------------------------------------------------------
AT89X51.H

Header file for the low voltage Flash Atmel AT89C51 and AT89LV51.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __AT89X51_H__
#define __AT89X51_H__

/*------------------------------------------------
Byte Registers
------------------------------------------------*/
sfr P0 = 0x80;
sfr SP = 0x81;
sfr DPL = 0x82;
sfr DPH = 0x83;
sfr PCON = 0x87;
sfr TCON = 0x88;
sfr TMOD = 0x89;
sfr TL0 = 0x8A;
sfr TL1 = 0x8B;
sfr TH0 = 0x8C;
sfr TH1 = 0x8D;
sfr P1 = 0x90;
sfr SCON = 0x98;
sfr SBUF = 0x99;
sfr P2 = 0xA0;
sfr IE = 0xA8;
sfr P3 = 0xB0;
sfr IP = 0xB8;
sfr PSW = 0xD0;
sfr ACC = 0xE0;
sfr B = 0xF0;

/*------------------------------------------------
P0 Bit Registers
------------------------------------------------*/
sbit P0_0 = 0x80;
sbit P0_1 = 0x81;
sbit P0_2 = 0x82;
sbit P0_3 = 0x83;
sbit P0_4 = 0x84;
sbit P0_5 = 0x85;
sbit P0_6 = 0x86;
sbit P0_7 = 0x87;

/*------------------------------------------------
PCON Bit Values
------------------------------------------------*/
#define IDL_ 0x01

#define STOP_ 0x02
#define PD_ 0x02 /* Alternate definition */

#define GF0_ 0x04
#define GF1_ 0x08

#define SMOD_ 0x80

/*------------------------------------------------
TCON Bit Registers
------------------------------------------------*/
sbit IT0 = 0x88;
sbit IE0 = 0x89;
sbit IT1 = 0x8A;
sbit IE1 = 0x8B;
sbit TR0 = 0x8C;
sbit TF0 = 0x8D;
sbit TR1 = 0x8E;
sbit TF1 = 0x8F;

/*------------------------------------------------
TMOD Bit Values
------------------------------------------------*/
#define T0_M0_ 0x01
#define T0_M1_ 0x02
#define T0_CT_ 0x04
#define T0_GATE_ 0x08
#define T1_M0_ 0x10
#define T1_M1_ 0x20
#define T1_CT_ 0x40
#define T1_GATE_ 0x80

#define T1_MASK_ 0xF0
#define T0_MASK_ 0x0F

/*------------------------------------------------
P1 Bit Registers
------------------------------------------------*/
sbit P1_0 = 0x90;
sbit P1_1 = 0x91;
sbit P1_2 = 0x92;
sbit P1_3 = 0x93;
sbit P1_4 = 0x94;
sbit P1_5 = 0x95;
sbit P1_6 = 0x96;
sbit P1_7 = 0x97;

/*------------------------------------------------
SCON Bit Registers
------------------------------------------------*/
sbit RI = 0x98;
sbit TI = 0x99;
sbit RB8 = 0x9A;
sbit TB8 = 0x9B;
sbit REN = 0x9C;
sbit SM2 = 0x9D;
sbit SM1 = 0x9E;
sbit SM0 = 0x9F;

/*------------------------------------------------
P2 Bit Registers
------------------------------------------------*/
sbit P2_0 = 0xA0;
sbit P2_1 = 0xA1;
sbit P2_2 = 0xA2;
sbit P2_3 = 0xA3;
sbit P2_4 = 0xA4;
sbit P2_5 = 0xA5;
sbit P2_6 = 0xA6;
sbit P2_7 = 0xA7;

/*------------------------------------------------
IE Bit Registers
------------------------------------------------*/
sbit EX0 = 0xA8; /* 1=Enable External interrupt 0 */
sbit ET0 = 0xA9; /* 1=Enable Timer 0 interrupt */
sbit EX1 = 0xAA; /* 1=Enable External interrupt 1 */
sbit ET1 = 0xAB; /* 1=Enable Timer 1 interrupt */
sbit ES = 0xAC; /* 1=Enable Serial port interrupt */
sbit ET2 = 0xAD; /* 1=Enable Timer 2 interrupt */

sbit EA = 0xAF; /* 0=Disable all interrupts */

/*------------------------------------------------
P3 Bit Registers (Mnemonics & Ports)
------------------------------------------------*/
sbit P3_0 = 0xB0;
sbit P3_1 = 0xB1;
sbit P3_2 = 0xB2;
sbit P3_3 = 0xB3;
sbit P3_4 = 0xB4;
sbit P3_5 = 0xB5;
sbit P3_6 = 0xB6;
sbit P3_7 = 0xB7;

sbit RXD = 0xB0; /* Serial data input */
sbit TXD = 0xB1; /* Serial data output */
sbit INT0 = 0xB2; /* External interrupt 0 */
sbit INT1 = 0xB3; /* External interrupt 1 */
sbit T0 = 0xB4; /* Timer 0 external input */
sbit T1 = 0xB5; /* Timer 1 external input */
sbit WR = 0xB6; /* External data memory write strobe */
sbit RD = 0xB7; /* External data memory read strobe */

/*------------------------------------------------
IP Bit Registers
------------------------------------------------*/
sbit PX0 = 0xB8;
sbit PT0 = 0xB9;
sbit PX1 = 0xBA;
sbit PT1 = 0xBB;
sbit PS = 0xBC;
sbit PT2 = 0xBD;

/*------------------------------------------------
PSW Bit Registers
------------------------------------------------*/
sbit P = 0xD0;
sbit FL = 0xD1;
sbit OV = 0xD2;
sbit RS0 = 0xD3;
sbit RS1 = 0xD4;
sbit F0 = 0xD5;
sbit AC = 0xD6;
sbit CY = 0xD7;

/*------------------------------------------------
Interrupt Vectors:
Interrupt Address = (Number * 8) + 3
------------------------------------------------*/
#define IE0_VECTOR 0 /* 0x03 External Interrupt 0 */
#define TF0_VECTOR 1 /* 0x0B Timer 0 */
#define IE1_VECTOR 2 /* 0x13 External Interrupt 1 */
#define TF1_VECTOR 3 /* 0x1B Timer 1 */
#define SIO_VECTOR 4 /* 0x23 Serial port */

#endif
参考技术A sfr 如果是类型的话,就要放到上面去,int a 的下面。
不能放到其它代码里面再声名变量。

其它代码指:
SCON = 0x50; //串口方式1,允许接收
TH1 = 0xE8; //11.0592MHz 1200波特率
TL1 = 0xE8;
TI = 1;
参考技术B sfr P1=0X90已经在头文件at89x51.h中定义了,你把sfr P1=0X90删掉就可以编译成功,下边是at89x51.h中的一部分内容:
#ifndef AT89X51_HEADER_FILE
#define AT89X51_HEADER_FILE 1

/*------------------------------------------------
Byte Registers
------------------------------------------------*/
sfr P0 = 0x80;
sfr SP = 0x81;
sfr DPL = 0x82;
sfr DPH = 0x83;
sfr PCON = 0x87;
sfr TCON = 0x88;
sfr TMOD = 0x89;
sfr TL0 = 0x8A;
sfr TL1 = 0x8B;
sfr TH0 = 0x8C;
sfr TH1 = 0x8D;
sfr P1 = 0x90; //看到这句没有,所以没必要再在主程序中说明了,否则会编译错误。
sfr SCON = 0x98;
sfr SBUF = 0x99;
sfr P2 = 0xA0;
sfr IE = 0xA8;
sfr P3 = 0xB0;
sfr IP = 0xB8;
sfr PSW = 0xD0;
sfr ACC = 0xE0;
sfr B = 0xF0;

请帮我看看这段javascript函数错在哪里

我目的是把HTML中所有以<blockquote cite="url">形式出现的标签,把其中的url提出来,并创建连接名叫source的连接,最后添加进网页的末尾

function sss()
var bq = document.getElementsByTagName("blockquote");
for(var i=0;i<bq.length;i++)
var url = bq[i].getArrtibute("cite");
var link = document.createElement("a");
var source = document.createTextNode("source");
link.appendChild(source);
link.setArrtibute("href",url);

document.body.appendChild(link);

function sss()
var bq = document.getElementsByTagName("blockquote");
for(var i=0;i<bq.length;i++)
var url = bq[i].getAttribute("cite");//方法名写错了...
var link = document.createElement("a");
var source = document.createTextNode("source");
link.appendChild(source);
link.setAttribute("href",url); //方法名写错了...
document.body.appendChild(link);


PS:别粗心大意。。。
参考技术A tjpdj1988 写的你直接复制上去就行了,哈哈,要注意啊,我开始都没注意你写的单词是错的 参考技术B 网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; znwb6500; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
时间戳: Tue, 3 May 2011 03:38:36 UTC

消息: 对象不支持此属性或方法
行: 9
字符: 3
代码: 0
URI: file:///C:/Documents%20and%20Settings/Administrator/桌面/新建%20文本文档.html

测试,getArrtibute()这个是XML文档用的,不是HTML文档用的,浏览器不支持这种用法
你下个jQuery吧,这几个都有封装好的系统函数
或者直接改这两句,var url = bq[i].cite;//getArrtibute("cite");
link.href = url;//setArrtibute("href",url);
此外要把document.body.appendChild(link);这句放到for循环里,不然始终只有最后一个blockquote能做成链接
不过这样在各浏览器下的兼容性可能会有点问题,需要测试

以上是关于帮我看看程序错在哪里了!的主要内容,如果未能解决你的问题,请参考以下文章

谁可以帮我看看我这个C语言程序错在哪啊?查询成绩和统计程序都弄不出!··谢谢了

C语言用typedef定义一个单向链表的节点的数据结构,请大侠看看我这种方式错在哪里?如何修改?

linux运行一个TCP服务器端程序,总是提示”段错误“,麻烦帮我看看到底哪里出了问题?

关于CSS滤镜设置的问题,为啥网页显示不出来效果,变不了灰色,帮忙查看一下代码看看错在哪里,谢谢

求助,请各位帮我看看导致app crash的问题在哪里

python tkinter gui库 问题 gif的图片不能显示 高手帮我看看出错在哪里?