我是在例程的基础上,在进行了简单的扩展,完整代码如下,但是编译出现如下错误
"sw8.c", line 24: warning: nested comment is not allowed
"sw8.c", line 200: error: declaration may not appear after executable statement in block // 查了下,是说在可执行语句前,变量声明应该在函数的前面,但是
我的声明全部在main()前,应该不会出错啊?不知道这个错误到底是指什么??
"sw8.c", line 200: error: expected a "}"// 括号的数量是对的,但还显示缺括号??
"sw8.c", line 286: error: declaration may not appear after executable statement in block
"sw8.c", line 287: error: expected a ";" //找不出哪里缺分号??
"sw8.c", line 330: warning: nested comment is not allowed
At end of source: warning: parsing restarts here after previous syntax error
At end of source: error: expected a "}"
At end of source: warning: missing return statement at end of non-void function "SW_detect"
At end of source: error: expected a "}"
/*********************************************************************
** Module Name: BUTTON **
** Author: CTH **
** Version: 1.0 **
** CreateDate: 2008-8-10 **
** Description: **
** Remark: **
** Revision History: 2008-8-10 **
**********************************************************************
/*********************************************************************
** 实验目的:通过学习本实验来掌握按键的处理 **
** 实验说明:通过读取按键端口的数值,来判断哪个按键按下,K1~K8按下 **
** 分别对应数据1,2,4,8,16,32,64,128 **
** 实验结果:将按下的键码通过数码管显示出来
/*********************************************************************
**拓展部分:按下相应的键,显示对应的数字,并且对应的led闪烁,液晶显示,
** 当再次按下原来的按键时,同时led和数码关闭,液晶显示 **
**********************************************************************/
#include <csl.h>
#include <csl_pll.h>
#include <csl_emif.h>
#include <csl_chip.h>
#include <stdio.h>
/*宏定义模块:寄存器映射*/
#define DATA_DIR (*((unsigned int *)0x200000))
#define LCD_REG (*((unsigned int *)0x200003))
#define USE_SW (*((unsigned int *)0x200005))
#define LCD_DATA (*((unsigned int *)0x200006))
#define led8 (*((unsigned int *)0x200001))
#define DIG_DATA (*((unsigned int *)0x200002))
#define buzzer (*((unsigned int *)0x200004))
#define comm 0
#define dat 1
/*待显示字符、数字*/
unsigned char str1[]={"key pressed! "};
unsigned char str2[]={"key pressed again!"};
Uint16 Code[]={0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x3f};
Uint16 Num_led[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
int temp,k_count,k_detect,i,n;
/*函数声明*/
void LCD1602_initial(void);
void wr_lcd(unsigned char dat_comm, unsigned int content);
void Delay(unsigned int nDelay);
void delaynum(unsigned int d_time);
int SW_detect(void);
void LED_light(int m);
void LCD1602_fp_display(void);
void delay(unsigned int d_time);
void LCD1602_ap_display(void);
/*锁相环的设置*/
PLL_Config myConfig = {
0, //IAI: the PLL locks using the same process that was underway
//before the idle mode was entered
1, //IOB: If the PLL indicates a break in the phase lock,
//it switches to its bypass mode and restarts the PLL phase-locking
//sequence
12, //PLL multiply value; multiply 12 times
2 //Divide by 2 PLL divide value; it can be either PLL divide value
//(when PLL is enabled), or Bypass-mode divide value
//(PLL in bypass mode, if PLL multiply value is set to 1)
};
/*SDRAM的EMIF设置*/
EMIF_Config emiffig = {
0x221, //EGCR : the MEMFREQ = 00,the clock for the memory is equal to cpu frequence
// the WPE = 0 ,forbiden the writing posting when we debug the EMIF
// the MEMCEN = 1,the memory clock is reflected on the CLKMEM pin
// the NOHOLD = 1,HOLD requests are not recognized by the EMIF
0xFFFF, //EMI_RST: any write to this register resets the EMIF state machine
0x1fff, //CE3_1: CE0 space control register 1
0x00ff, //CE3_2: CE0 space control register 2
0x00ff, //CE3_3: CE0 space control register 3
0x1fff, //CE1_1: CE0 space control register 1
// Asynchronous, 16Bit
0x00ff, //CE1_2: CE0 space control register 2
0x00ff, //CE1_3: CE0 space control register 3
0x1FFF, //CE2_1: CE0 space control register 1
// Asynchronous, 16Bit
0xFFFF, //CE2_2: CE0 space control register 2
0x00FF, //CE2_3: CE0 space control register 3
0x1fff, //CE3_1: CE0 space control register 1
0x00ff, //CE3_2: CE0 space control register 2
0x00ff, //CE3_3: CE0 space control register 3
0x2911, //SDC1: SDRAM control register 1
// TRC = 8
// SDSIZE = 0;SDWID = 0
// RFEN = 1
// TRCD = 2
// TRP = 2
0x0410, //SDPER : SDRAM period register
// 7ns *4096
0x07FF, //SDINIT: SDRAM initialization register
// any write to this register to init the all CE spaces,
// do it after hardware reset or power up the C55x device
0x0131 //SDC2: SDRAM control register 2
// SDACC = 0;
// TMRD = 01;
// TRAS = 0101;
// TACTV2ACTV = 0001;
};
main()
{
//int temp,k_count,k_detect,i,n;
/*初始化CSL库*/
CSL_init();
/*EMIF为全EMIF接口*/
CHIP_RSET(XBSR,0x0a01);
/*设置系统的运行速度为48MHz*/
PLL_config(&myConfig);
/*初始化DSP的EMIF*/
EMIF_config(&emiffig);
LCD1602_initial( );
while(1)
{
SW_detect( );
while(1)
{
DIG_DATA=Code[i-1];
LED_light(i);
LCD1602_fp_display();
/*是否按下原来的按键*/
temp=USE_SW&0xff;
if(temp!=0x00)
{
Delay(20);
if(temp!=0x00)
{
if(temp==k_detect)//按下的是原来的按键
{
while(temp!=0x00)
{
temp=USE_SW&0xff;
} //等待按键松开
}
DIG_DATA=0x00;
LCD1602_ap_display();
break;
}
}
}
}
}
/*************子模块***********************/
/*液晶初始化*/
void LCD1602_initial( )
{
wr_lcd(comm,0x01);
wr_lcd(comm,0x38);
wr_lcd(comm,0x0e);
wr_lcd(comm,0x06);
}
/*写数据/命令*/
void wr_lcd(unsigned char dat_comm, unsigned int content)
{
//EN 高变低电平,液晶开始操作
//RS 高电平为数据寄存器 低电平为指令寄存器
Delay(40);
if(dat_comm) //写数据
{
LCD_REG=0x01;
LCD_DATA=content; //数据端口
LCD_REG=0x03; //en=0
delaynum(80);
LCD_REG=0x00; //en=0
}
else //写命令
{
LCD_REG=0x00;
LCD_DATA=content;
LCD_REG=0x02; //rs==1 en==0 写指令端口
delaynum(80);
LCD_REG=0x00; //en=0
}
Delay(100);
}
/*忙检测延时*/
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii<nDelay;ii++ )
{
for ( jj=0;jj<1024;jj++ )
{
kk++;
}
}
}
/*时序延时*/
void delaynum(unsigned int d_time)
{
while(d_time--);
}
/*首次按键检测*/
int SW_detect(void )
{
temp=USE_SW&0xff;
if(temp!=0x00)
{
Delay(20); //按键消抖
if(temp!=0x00)
{
k_count=temp; //保存当前按键的值:用于计数和检测
k_detect=temp;
/***等待按键释放***/
while(temp!=0x00)
{
temp=USE_SW&0xff;
}
i=0;
while(k_count!=0)
{
k_count=k_count>>1;
i++;
} //转换为键码,1~8分别对应1,2,4,8,16,32,64,128
}
}
return i;
}
/*灯闪烁*/
void LED_light(int m)
{
led8=Num_led[m-1];
Delay(500);
led8=Num_led[m-1]&0x00;
Delay(500);
}
/*液晶字符显示*/
void LCD1602_fp_display(void )
{
wr_lcd(comm,0x80); //写入SDRAM显示的地址
for(i=0;i<16;i++)
{
wr_lcd(dat,str1[i]);
delay(200);
}
}
/*相邻字符显示延时*/
void delay(unsigned int d_time)
{
while(d_time--);
}
/*再次按键液晶显示*/
void LCD1602_ap_display( )
{
wr_lcd(comm,0xc0);
for(i=0;i<16;i++)
{
wr_lcd(dat,str2[i]);
delay(200);
}
}
/******************************************************************************\
* End of lcd.c
\******************************************************************************/
|