帮忙看个程序

2019-07-18 15:01发布

#include "msp430.h"
#include "lcd1602.c"
unsigned char tishi[]={"undefinedRESS KEY IS :"};
unsigned char table[]={"0123456789"};
unsigned char keyval;
#define QH BIT0
#define SHIFT BIT1
#define CLOCK BIT2
#define HC165SEL P3SEL
#define HC165DIR P3DIR
#define HC165OUT P3OUT
#define HC165IN P3IN
//74HC165与单片机的连接端口初始设置
unsigned int GetHC74165(void);
void HC74165_Init()
{
HC165SEL &= ~(QH+SHIFT+CLOCK);
HC165DIR |= SHIFT + CLOCK;
HC165DIR &= ~QH;
}
/********************************************************
*名 称:GetHC74165()
*功 能:锁存74HC165的8位输入,并逐位读出
*出 口:读取的8位状态数据,放在整型数据的低八位
********************************************************/
unsigned int GetHC74165(void)
{
unsigned char i;
unsigned int indata=0;
HC165OUT &= ~SHIFT;
_NOP();
HC165OUT |= SHIFT;
_NOP();
_NOP();
for(i=0;i<8;i++)
{
indata <<= 1;
if(HC165IN & QH) indata += 1;
HC165OUT |= CLOCK;
_NOP();
HC165OUT &= ~CLOCK;
}
return indata;
}

void main( void )
{
unsigned int key,a;
WDTCTL = WDTPW + WDTHOLD;

DCOCTL=CALDCO_16MHZ;
BCSCTL1= CALBC1_16MHZ;

P1DIR = 0XFFundefined1OUT = 0XFF;
P2DIR = 0XFFundefined2OUT = 0XFF;
init_IO_1602();
LCD_init_first();
init_1602();
HC74165_Init();
P3DIR = 0xff;
P3OUT = 0xff;
for(a=0;a<14;a++)
dispchar(a+1,0,tishi[a]);
while(1)
{
if((key=GetHC74165())!=0xff)
{
switch(key)
{
case 0xfe:
keyval=1;
break;
case 0xfd:
keyval=2;
break;
case 0xfb:
keyval=3;
break;
case 0xf7:
keyval=4;
break;
case 0xef:
keyval=5;
break;
case 0xdf:
keyval=6;
break;
case 0xbf:
keyval=7;
break;
case 0x7f:
keyval=8;
break;
}
dispchar(2,1,table[key]);
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。