|
我用msp430编写的lcd显示和中断扫描矩阵按键 当总中断不开启的时候lcd能正常显示数据 打开总中断后不显示了 求助!!!
开启总中断在初始化程序的最后一行!!!
#include "msp430x14x.h"
#define uint unsigned int
#define uchar unsigned char
#define zhilin_PORT P3OUT
#define zhilin_DDR P3DIR
#define DB_PORT P4OUT
#define DB_DDR P4DIR
void write_dat(uchar dat);
void delay_ms(uint ms);
void write_com(uchar com);
void Init_Port(void);
void show(uint x);
void delay(void);//按键去抖
uint keyprocess(void);
uint key=0;
#pragma vector=PORT1_VECTOR
__interrupt void ITRPT_1(void)
{
delay();
key = keyprocess();
P1IFG=0;
}
void main(void)
{
Init_Port();
while(1)
{
show(key);
}
}
/**********************************/
#include "msp430x14x.h"
#define uint unsigned int
#define uchar unsigned char
void delay_ms(uint ms)
{
uint i,j;
for(;ms>0;ms--)
for(i=0;i<1000;i++)
for(j=0;j<8;j++);
}
void delay(void)//按键去抖
{
int i;
for(i = 100;i--;i > 0);
}
/*******************************/
#include "msp430x14x.h"
#define uint unsigned int
#define uchar unsigned char
#define zhilin_PORT P3OUT
#define zhilin_DDR P3DIR
#define DB_PORT P4OUT
#define DB_DDR P4DIR
void write_dat(uchar dat);
void delay_ms(uint ms);
void write_com(uchar com);
void Init_Port(void)
{
uchar j = 0;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 &= ~ XT2OFF; //打开XT2高频晶振,XT1默认低频晶振--DIVA默认1分频
do
{
IFG1 &= ~ OFIFG; //关闭晶振错误中断标志
for(j= 0xff ; j > 0;j--); //延时
}
while(IFG1 & OFIFG); //判断是否关闭成功
BCSCTL2 |= SELM_2; //主系统时钟使用XT2高频晶振,DIVM默认不分频
BCSCTL2 |= SELS;
//将P1口所有的管教在初始化的时候设置为输入
P1DIR = 0;
//将P1端口所有的管脚设置为一般I/O口
P1SEL = 0;
//打开管脚的中断功能
//对应管脚由高到低电平跳变使相应的标志置位
P1IES = BIT0 + BIT1 + BIT2 + BIT3;
P1IE = BIT0 + BIT1 + BIT2 + BIT3;
P2OUT = 0XFF;
P2DIR = 0XFF;
P2SEL = 0X00;
zhilin_DDR=0XFF;
zhilin_PORT=0X00;
DB_DDR=0XFF;
DB_PORT=0X00;
P3SEL = 0X00;
P4SEL = 0X00;
write_com(0x38);//设置16*2显示 5*7点阵屏
delay_ms(5);
//write_com(0x01);//清屏
//delay(1);
write_com(0x0C);//显示光标闪烁
delay_ms(5);
write_com(0X06);//写入字符后光标加一 字符加一
delay_ms(5);
_EINT();
}
/****************************/
#include "msp430x14x.h"
#define uint unsigned int
#define uchar unsigned char
#define zhilin_PORT P3OUT
#define zhilin_DDR P3DIR
#define DB_PORT P4OUT
#define DB_DDR P4DIR
uint keyprocess(void)
{
int nP10,nP11,nP12,nP13;
int nRes = 0;
//P1.4输出低电平
P1OUT &= ~(BIT4);
nP10 = P1IN & BIT0;
if (nP10 == 0) nRes = 13;
nP11 = P1IN & BIT1;
if (nP11 == 0) nRes = 14;
nP12 = P1IN & BIT2;
if (nP12 == 0) nRes = 15;
nP13 = P1IN & BIT3;
if (nP13 == 0) nRes = 16;
//P1.5输出低电平
P1OUT &= ~(BIT4);
nP10 = P1IN & BIT0;
if (nP10 == 0) nRes = 9;
nP11 = P1IN & BIT1;
if (nP11 == 0) nRes = 10;
nP12 = P1IN & BIT2;
if (nP12 == 0) nRes = 11;
nP13 = P1IN & BIT3;
if (nP13 == 0) nRes = 12;
//P1.6输出低电平
P1OUT &= ~(BIT4);
nP10 = P1IN & BIT0;
if (nP10 == 0) nRes = 5;
nP11 = P1IN & BIT1;
if (nP11 == 0) nRes = 6;
nP12 = P1IN & BIT2;
if (nP12 == 0) nRes = 7;
nP13 = P1IN & BIT3;
if (nP13 == 0) nRes = 8;
//P1.7输出低电平
P1OUT &= ~(BIT4);
nP10 = P1IN & BIT0;
if (nP10 == 0) nRes = 1;
nP11 = P1IN & BIT1;
if (nP11 == 0) nRes = 2;
nP12 = P1IN & BIT2;
if (nP12 == 0) nRes = 3;
nP13 = P1IN & BIT3;
if (nP13 == 0) nRes = 4;
P1OUT = 0x00;//恢复以前值。
//读取各个管脚的状态
nP10 = P1IN & BIT0;
nP11 = P1IN & BIT1;
nP12 = P1IN & BIT2;
nP13 = P1IN & BIT3;
for(;;)
{
if(nP10 == 1 && nP11 == 1 && nP12 == 1 && nP13 == 1)
{
//等待松开按键
break;
}
}
return nRes;
}
/*******************************/
#include "msp430x14x.h"
#define uint unsigned int
#define uchar unsigned char
#define zhilin_PORT P3OUT
#define zhilin_DDR P3DIR
#define DB_PORT P4OUT
#define DB_DDR P4DIR
void write_dat(uchar dat);
void delay_ms(uint ms);
void write_com(uchar com);
void show(uint x)
{
uchar i;
uchar DAT1[7]={0,};
uchar table1[10]={48,49,50,51,52,53,54,55,56,57};
DAT1[0]=x/100;
DAT1[1]=x%100/10;
DAT1[2]=x%10;
write_com(0X80+0X00);
delay_ms(5);
for(i=0;i<3;i++)
{
write_dat(table1[DAT1]);
delay_ms(5);
}
}
void write_com(uchar com)//写指令
{
zhilin_PORT&=~BIT0;//RS设置为输入指令
zhilin_PORT&=~BIT1;//R/W设置为向lcd写入指令
DB_PORT =com;//输入指令内容
zhilin_PORT|=BIT2;//使能位为高电平 读取信息
delay_ms(1);//使能延迟
zhilin_PORT&=~BIT2;
//使能位跳为低电平 E出现下降沿 执行指令
}
void write_dat(uchar dat)//写数据
{
zhilin_PORT|=BIT0;//RS设置为输入数据
zhilin_PORT&=~BIT1;//R/W设置为向lcd写入数据
DB_PORT=dat;//输入数据内容
zhilin_PORT|=BIT2;//使能位为高电平 读取信息
delay_ms(1);//使能延迟
zhilin_PORT&=~BIT2;
//使能位跳为低电平 E出现下降沿 显示数据
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|