注册会员
- 积分
- 158
- 威望
- 95
- 贡献
- 41
- 兑换币
- 28
- 注册时间
- 2012-11-3
- 在线时间
- 11 小时
|
求教各位大神:
我写的K60程序有LCD模块,里面放了循环等待程序以检测按键来显示不同页面,当按下最后一个键时退出LCD,执行main程序的其他部分,与LCD就没有关系了,LCD主要起起动前的调试作用,但问题就出在这里,如果我打开小车电源后直接进入程序就会运行正常,电机,伺服电机可以正常运行,用于检测的小灯可以闪,但如果我按一些键进行一些调试后就会不能正常运行,表现为程序中用以检测的小灯可以亮,但不能闪,电机,伺服电机不能动。但小灯的亮是在电机程序的下面,这是怎么回事?
void main (void)
{
DisableInterrupts;
delay();
PORTC_PCR0 = PORT_PCR_MUX(0x1); //LED5
GPIOC_PDDR = 1<<0;
GPIOC_PDOR = 1<<0;
PORTE_PCR24= PORT_PCR_MUX(0x1); //电机
GPIOE_PDDR = 1<<24;
GPIOE_PDOR |= 1<<24;
InitLCD();
SetLCD(); //LCD的初始化在这里
ClearLCD();
FTM1PWMInit(100); //舵机PTA8
FTM1PWMOpen(0,1419); //转角为0
FTM0PWMInit(10000); //电机PWM
FTM0PWMOpen(4,0);
FTM0PWMOpen(3,0);
FTM0PWMChangeDuty(3,0);//电机转动
FTM0PWMChangeDuty(4,2000);//电机转动
EnableInterrupts;
while(1)
{
for(i=0;i<300;i++)
{
FTM1PWMChangeDuty(0,1419+i);
time_delay_ms(10);
} //这两个for 语句是为了让舵机来回摆动
for(i=0;i<300;i++)
{
FTM1PWMChangeDuty(0,1419-i);
time_delay_ms(10);
}
delay();
GPIOC_PTOR |= 1<<0; //小灯闪烁
}
}
LCD的主要部分在这里,请看一下:
void InitLCD(void);//初始化LCD
void ClearLCD(void);//清屏
void SetLCD(void);
//扫描键盘
uint8 ScanKey(void)
void InitLCD(void)
{
//-------注意更改输入输出------------
PORTC_PCR6 = ( PORT_PCR_MUX(1) );
PORTC_PCR7 = ( PORT_PCR_MUX(1) );
PORTC_PCR8 = ( PORT_PCR_MUX(1) );
PORTC_PCR9 = ( PORT_PCR_MUX(1) );
PORTC_PCR10 = ( PORT_PCR_MUX(1) );
PORTC_PCR11 = ( PORT_PCR_MUX(1) );
PORTC_PCR12 = ( PORT_PCR_MUX(1) );
PORTC_PCR13 = ( PORT_PCR_MUX(1) );
PORTC_PCR14 = ( PORT_PCR_MUX(1) );
GPIOC_PDDR |= 1<<6;
GPIOC_PDDR |= 1<<7;
GPIOC_PDDR |= 1<<8;
GPIOC_PDDR |= 1<<9;
GPIOC_PDDR |= 1<<10;
GPIOC_PDDR &= ~(1<<11);
GPIOC_PDDR &= ~(1<<12);
GPIOC_PDDR &= ~(1<<13);
GPIOC_PDDR &= ~(1<<14);
//-------注意更改输入输出------------
// DelaymS_LCD(20); //before reset the LCD,delay not more than 100 ms to wait the VDD rising to its high value
RES=0;
DelaymS_LCD(10);
RES=1; //first to reset ----important
SCE=0;
DelaymS_LCD(10);
SCE=1;
SDIN=1;
SCLK=1; //set to high
write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令function set
//PD = 0 and V = 0, select
//extended instruction set
//(H = 1 mode)
write_byte(0xcc,0);//设定液晶偏置电压(高--低)
// write_byte(0x06,0); //温度校正
write_byte(0x20,0);//使用基本指令
// function set
//PD = 0 and V = 0, select
//normal instruction set
//(H = 0 mode)
ClearLCD();//清屏
write_byte(0x0c,0); // 设定显示模式,正常显示
//display control set
//normal mode
//(D = 1 and E = 0)
SCE=0;
ShowPage();
}
void ClearLCD(void)
{
uint8 t;
uint8 k;
uint16 d;
d=0;
for(t=0;t<7;t++)
for(k=0;k<0x85;k++)
{
write_byte(0,1);
d=d+1;
}
}
void SetLCD(void)
{
uint8 k;
while(SetOK == 0) //在此循环,直到改变为止
{
k = ScanKey(); //键盘扫描,k为按键的号码
switch(k)
{
case SHIFT:
ShowPage();
break;
case INC:
if (LCDPage < 4)//向前翻
LCDPage++;
else
LCDPage = 1;
ShowPage();
break;
case DEC:
if (LCDPage > 1) //向后翻
LCDPage--;
else
LCDPage = 4;
ShowPage();
break;
case ENTER:
Set_b=1; //进入画面操作
ShowPage();
break;
default : break;
}
}
}
//扫描键盘
uint8 ScanKey(void)
{
BYTE key;
key.Byte=0xff;
key.Bits.B0=KEY1;
key.Bits.B1=KEY2;
key.Bits.B2=KEY3;
key.Bits.B3=KEY4;
if((key.Byte & 0x0f)!=0x0f)
{
DelaymS_LCD(10);
if (KEY4==0) Keynum=ENTER;
else if (KEY3==0)Keynum=DEC;
else if (KEY2==0)Keynum=INC;
else Keynum=SHIFT;
while((key.Byte & 0x0f)!=0x0f)
{
key.Bits.B0=KEY1;
key.Bits.B1=KEY2;
key.Bits.B2=KEY3;
key.Bits.B3=KEY4;
}
DelaymS_LCD(10);
}
else Keynum=0;
return(Keynum);
}
|
|