1524 views|0 replies

1667

Posts

0

Resources
The OP
 

MSP430 non-continuous IO parallel port output matrix keyboard [Copy link]

When I was working on msp430f5529, I found that there were not so many continuous IO ports, and only one P3 had 8 continuous ports. So I wondered if I could use discontinuous IO ports, that is, take the upper 4 bits of P2 and the fourth bit of P4 to form a group of 8 parallel ports to output a control scanning matrix keyboard. Because I am a novice and my C language foundation is not very good, the code I wrote is relatively complicated, and the majority of netizens can just take a look at it for fun.

//This is the delay function of the code

#include "MSP430F235.h"
typedef unsigned char uchar;
typedef unsigned int uint;
void delayms(uint ms)
{
uchar i;
while(ms--)
for(i=0;i<123;i++);
}

```c
this is the code
suchar key,di,gao;
uchar key_checkin;
uchar key_checkgaoin;
uchar key_checkin;
uchar key_check;
P4DIR=0x0f;
P4OUT=0xf0;
P2DIR=0x00;
P2OUT=0xff;
key_checkin=P4IN;
key_checkin&=0x00;
key_checkgaoin=P2IN;
key_checkgaoin&=0xf0;
key_checkin=key_checkdin+key_checkgaoin;
// Key scan function

if(key_checkin!=0xf0)
{
delayms(10);
key_checkdiin=P4IN;key_checkgaoin=P2IN;
key_checkdiin&=0x00; key_checkgaoin&=0xf0;
key_checkin=key_checkdiin+key_checkgaoin;
if(key_checkin!=0xf0)
{
P4OUT=0x0e;
P2OUT=0Xf0;
di=P4IN;gao=P2IN;
di&=0x0f;gao&=0xf0;
key_check=di|gao;
switch(key_check)
{
case 0xee:key=15;break;
case 0xde:key=11;break;
case 0xbe:key=7;break;
case 0x7e:key=3;break;
}
P4OUT=0x0d;
P2OUT=0Xf0;
di=P4IN;gao=P2IN;
di&=0x0f;gao&=0xf0;
key_check=di+gao;

switch(key_check)
{
case 0xed:key=14;break;
case 0xdd:key=10;break;
case 0xbd:key=6;break;
case 0x7d:key=2;break;
}
P4OUT=0xfb;
P2OUT=0Xff;
di=P4IN;gao=P2IN;
di&=0x0f;gao&=0xf0;
key_check=di+gao;

switch(key_check)
{
case 0xeb:key=13;break;
case 0xdb:key=9;break;
case 0xbb:key=5;break;
case 0x7b:key=1;break;
}
P4OUT=0x07;
P2OUT=0Xf0;
di=P4IN;gao=P2IN;
di&=0x0f;gao&=0xf0;
key_check=di+gao;

switch(key_check)
{
case 0xe7:key=12;break;
case 0xd7:key=8;break;
case 0xb7:key=4;break;
case 0x77:key=0;break;
}
}
}
else
{
key=0xff;
return key;
}
return key;
}
//控制lcd命令的代码
void w_com(uchar com)
{
P6DIR=0x07;//0000 0111
P6OUT=0x04;//0000 0100
P1OUT=com;
P6OUT=0x00;
delayms(1);
}
void w_dat(uchar dat)
{ P6DIR=0x07;///设置P6的低三位输出
P6OUT=0x05;//0000 0101
P1OUT=data;///向lcd输出数据
P6OUT=0x01;///0000 0001
delayms(1);
}
void lcd_ini()
{
delayms(10);
w_com(0x38);
delayms(10);
w_com(0x0c);
delayms(10); w_com(0x06);
delayms(10);
w_com(0x01); delayms(10);
w_com(0x38);
delayms(10);
};
主函数以后更新

This post is from Microcontroller MCU
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list