yilaozhuang 发表于 2010-8-12 21:01:18

ARM的C程序碰到的点问题,搞不清楚,来请教牛人

主程序
#include <stdio.h>                     /* standard I/O .h-file            */
#include <ctype.h>                     /* character functions               */
#include <LPC23xx.H>
#include "config.h"//提示错误的头文件
#include "I2CINT.h"


int main(void)
{
//锁定PLL
PLLCON = 1; // 使能PLL
PLLCFG = 0xB; // 设置M 为6,P 为2
PLLFEED = 0xAA; // 发送PLL 馈送序列
PLLFEED = 0x55;   


while((PLLSTAT & (1 << 26)) == 0); // 等待PLL 锁定
PLLCON = 3; // PLL使能和连接
PLLFEED = 0xAA; // 发送PLL 馈送序列
PLLFEED = 0x55;

//配置管脚
PINSEL0=0xC0000050;
PINSEL1=0x014043FF;
PINSEL3=0x00000000;
PINSEL2=0x01500000;

//RTC地址0XEB
//uint8 I2C_ReadNByte (uint8 sla, uint32 suba_type, uint32 suba, uint8 *s, uint32 num);
#define RTC 0xEB
#define RTC_sec 0x00
uint8 sec;//问题出在这里,uint8在config.h头文件里面定义
//I2C_ReadNByte(RTC,ONE_BYTE_SUBA,RTC_sec,sec,1);
sec=1;//还有这里
}
*****************************
config.h头文件
#ifndef __CONFIG_H
#define __CONFIG_H

// 不能被更改
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef unsigned char uint8; /* 无符号8 位整型变量 */
typedef signed char int8; /* 有符号8 位整型变量 */
typedef unsigned short uint16; /* 无符号16 位整型变量 */
typedef signed short int16; /* 有符号16 位整型变量 */
typedef unsigned int uint32; /* 无符号32 位整型变量 */
typedef signed int int32; /* 有符号32 位整型变量 */
typedef float fp32; /* 单精度浮点数(32 位长度) */
typedef double fp64; /* 双精度浮点数(64 位长度) */
#endif
**************************************************

yilaozhuang 发表于 2010-8-12 21:02:05

提示的错误也提出来,高手给看看:
main.c(32): error: #268: declaration may not appear after executable statement in block
main.c: uint8 sec;
main.c: ^
main.c(32): error: #67: expected a "}"
main.c: uint8 sec;
main.c: ^
main.c(34): error: #77-D: this declaration has no storage class or type specifier
main.c: sec=1;
main.c: ^
main.c(34): error: #147: declaration is incompatible with "uint8 sec" (declared at line 32)
main.c: sec=1;
main.c: ^
main.c(35): error: #169: expected a declaration
main.c: }
main.c: ^
main.c: main.c: 0 warnings, 5 errors

yilaozhuang 发表于 2010-8-12 21:39:42

问题解决了:
int main(void)
{
PLLCON = 1; // 这个(以及下面若干行)就是所谓的“executable statement ”
......
uint8 sec; // 这就是“declaration ”

这种在语句之后声明变量的方式,c++里面是正常的,现在的很多c编译器也允许。
但是最早的c是不许这么写的,要求所有的局部变量必须在函数开头声明,楼主用的编译器也是这样要求的
页: [1]
查看完整版本: ARM的C程序碰到的点问题,搞不清楚,来请教牛人