msp430f149,想通过按键在1602上显示一个值,按一下,值变化,再按一下又变化。但是我写出来,烧录出来后,直接显示了一串字符,求帮助,谢谢大神们#include "io430.h"
#include "TLC5615.h"
#include "Lcd1602.h"
void Init_CLK(void)
{
int index;
BCSCTL1&=~0X00; //打开XT2振荡器
do
{
IFG1 &= ~OFIFG; // 清除振荡器失效标志
for (index = 0xFF; index > 0; index--)// 延时,等待XT2起振
{
;
}
} while ((IFG1 & OFIFG) != 0);// 判断XT2是否起振
BCSCTL2 =SELM_2+SELS; //选择MCLK、SMCLK为XT2
}
void Tlc5615_port()
{
//将P6口所有的管脚设置为一般I/O口
P6SEL = 0;
P1SEL = 0;
//P6.5 6.6 1.0作为输出管脚
P6DIR |= BIT5;
P6DIR |= BIT6;
P1DIR |= BIT0;
SET_SPI_CS;
}
void Delay1ms(UINT count)
{
UINT i,j;
for(i = 0;i<count;i++)
{
for(j=0;j<120;j++)
{
;
}
}
}
void lcd1602_port(void)
{
// 将P5设置为I/O口
P5SEL = 0;
// 将P4设置为I/O口
P4SEL = 0;
// 将P4设置为输出方向
P4DIR |= 0xFF;
// 将P5.0 P5.1 P5.2 设置为输出方向
P5DIR |= BIT0;
P5DIR |= BIT1;
P5DIR |= BIT2;
P5DIR |= BIT3;//LED+
P5DIR |= BIT4;//LED-
P5OUT |= BIT3;
P5OUT &=~BIT4;
}
void Tlc5615_test(dac_out)
{
//unsigned short dac_out;
Tlc5615_port();
Delay1ms(2000);
DA_Conver(dac_out);
/*for(dac_out=0; dac_out<4095;dac_out++)
{
DA_Conver(dac_out);
Delay1ms(1);
}
for(dac_out=4095; dac_out>0;dac_out--)
{
DA_Conver(dac_out);
Delay1ms(1);
}*/
//display_string(2,1,"DAC Test Over");
return ;
}
UCHAR GetKey(void)
{
P1DIR =0xf0;
P1OUT = 0xef;//扫描第一列
//_NOP();
//_NOP();
//P1DIR &= 0x0f;//读列
if((P1IN & 0x0f)==0x0e)return '1';
if((P1IN & 0x0f)==0x0d)return '5';
if((P1IN & 0x0f)==0x0b)return '9';
if((P1IN & 0x0f)==0x07)return 'D';
//P1DIR =0x0f;
P1OUT = 0xdf;//扫描第二行
//_NOP();
// _NOP();
//P1DIR &= 0x0f;//读列
if((P1IN & 0x0f)==0x0e)return '2';
if((P1IN & 0x0f)==0x0d)return '6';
if((P1IN & 0x0f)==0x0b)return 'A';
if((P1IN & 0x0f)==0x07)return 'E';
//P1DIR =0xff;
P1OUT = 0xbf;//扫描第三行
// _NOP();
//_NOP();
//P1DIR &= 0x0f;//读列
if((P1IN & 0x0f)==0x0e)return '3';
if((P1IN & 0x0f)==0x0d)return '7';
if((P1IN & 0x0f)==0x0b)return 'B';
if((P1IN & 0x0f)==0x07)return 'F';
//P1DIR =0xff;
P1OUT = 0x7f;//扫描第四行
//_NOP();
// _NOP();
//P1DIR &= 0x0f;//读列
if((P1IN & 0x0f)==0x0e)return '4';
if((P1IN & 0x0f)==0x0d)return '8';
if((P1IN & 0x0f)==0x0b)return 'C';
if((P1IN & 0x0f)==0x07)return '0';
return 0;
}
void Lcd1602_test()
{
lcd1602_port();
lcd_init();
//display_char(8,0,'v');
//display_char(9,0,'=');
display_string(8,0,"mv=(unsigned char *)s");
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//UCHAR key;
Init_CLK();
int i=-1;
UCHAR key;
int a[11]={0,165,330,495,660,825,990,1155,1320,1485,1650};
unsigned char h[11]={0,2,4,6,8,10,12,14,16,10,20};
unsigned char *s=h;
// P1DIR = 0xf0;
// P1SEL = 0x00;
while(1)
{ key=GetKey();
if(key=='1')
{
i++;
}
if(key=='2')
{
i--;
}
Tlc5615_test(a[i]);
Lcd1602_test();
if(i==11)
{ i=0; }
if(i==-1)
{ i=0; }
}
}
void display_string(unsigned char x,unsigned char y,unsigned char *s)
{
display_xy(x,y);
while(*s)
{
WriteDataLcd(*s);
s++;
}
}
|