proteus仿真四个外部中断按键+1602液晶.docx

上传人:b****8 文档编号:10649970 上传时间:2023-02-22 格式:DOCX 页数:9 大小:42.24KB
下载 相关 举报
proteus仿真四个外部中断按键+1602液晶.docx_第1页
第1页 / 共9页
proteus仿真四个外部中断按键+1602液晶.docx_第2页
第2页 / 共9页
proteus仿真四个外部中断按键+1602液晶.docx_第3页
第3页 / 共9页
proteus仿真四个外部中断按键+1602液晶.docx_第4页
第4页 / 共9页
proteus仿真四个外部中断按键+1602液晶.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

proteus仿真四个外部中断按键+1602液晶.docx

《proteus仿真四个外部中断按键+1602液晶.docx》由会员分享,可在线阅读,更多相关《proteus仿真四个外部中断按键+1602液晶.docx(9页珍藏版)》请在冰豆网上搜索。

proteus仿真四个外部中断按键+1602液晶.docx

proteus仿真四个外部中断按键+1602液晶

Proteus仿真外部中断,共4个按键,控制1602液晶显示,基于MSP430F249

程序1(库文件KU.h):

/**************************************************//****

//延时设置~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//***********************************************************

#defineCPU_F((double)4000000)////主时钟的频率4MHz

#definedelay_us(x)__delay_cycles((long)(CPU_F*(double)x/1000000.0))

#definedelay_ms(x)__delay_cycles((long)(CPU_F*(double)x/1000.0))

#defineRS0P3OUT&=~BIT0

#defineRS1P3OUT|=BIT0

#defineRW0P3OUT&=~BIT1

#defineRW1P3OUT|=BIT1

#defineEN0P3OUT&=~BIT2

#defineEN1P3OUT|=BIT2

//***************************************************//

//时钟设置

//************************************************//

 

//驱动1602**************************

voidLCD_write_com(unsignedcharcom)

{

RS0;

RW0;

EN0;

P1OUT=com;

delay_ms

(1);

EN1;

delay_ms

(1);

EN0;

}

 

voidLCD_write_data(unsignedchardata)

{

RS1;

RW0;

EN0;

P1OUT=data;

delay_ms

(1);

EN1;

delay_ms

(1);

EN0;

}

voidLCD_clear(void)

{

LCD_write_com(0x01);

delay_ms

(1);

}

 

voidLCD_write_str(unsignedcharx,unsignedchary,unsignedchar*s)

{

if(y==0)

{

LCD_write_com(0x80+x);

}

else

{

LCD_write_com(0xC0+x);

}

while(*s)

{

LCD_write_data(*s);

s++;

}

}

voidLCD_write_char(unsignedcharx,unsignedchary,unsignedchardata)

{

if(y==0)

{

LCD_write_com(0x80+x);

}

else

{

LCD_write_com(0xC0+x);

}

LCD_write_data(data);

}

voidLCD_init(void)

{

EN0;

delay_ms

(1);

LCD_write_com(0x38);

delay_ms

(1);

LCD_write_com(0x0C);

delay_ms

(1);

LCD_write_com(0x06);

delay_ms

(1);

LCD_write_com(0x01);

delay_ms

(1);

}

程序2:

主文件

#include

#include"KU.h"

unsignedcharA1;

unsignedcharA2;

unsignedcharB1;

unsignedcharB2;

unsignedcharMENU;

#pragmavector=PORT2_VECTOR

__interruptvoidP21_IRQ(void)

{

switch(P2IFG&0x0f)

{

case0x01:

//菜单

if(MENU==0)

{

A1=0;

A2=0;

B1=0x00;

B2=0;

LCD_clear();

LCD_write_str(0,0,"menu:

");

LCD_write_char(0x0e,1,0x30+A1);

LCD_write_char(0x0f,1,0x30+A2);

P2IFG=0x00;

MENU=1;

}

else

{

MENU=0;

P2IFG=0x00;

}

break;

case0x02:

//置数

if(MENU==1)

{

if((B1&0x01)==0x00)

{

if(A1==9)

{

A1=0;

}

else

{

A1++;

}

}

if((B1&0x01)==0x01)

{

if(A2==9)

{

A2=0;

}

else

{

A2++;

}

}

LCD_write_char(0x0e,1,0x30+A1);

LCD_write_char(0x0f,1,0x30+A2);

}

P2IFG=0x00;

break;

case0x04:

//移位

if(MENU==1)

{

B1=~B1;

LCD_write_char(0x0e,1,0x30+A1);

LCD_write_char(0x0f,1,0x30+A2);

}

P2IFG=0x00;

break;

case0x08:

//确认

if(MENU==1)

{

if((A1==2)&(A2==5))

{

LCD_clear();

LCD_write_str(0,0,"lmnop:

");

}

}

MENU=2;

P2IFG=0x00;

break;

}

}

 

intmain(void)

{

WDTCTL=WDTPW+WDTHOLD;

P1SEL=0x00;

P1DIR=0xFF;//P1液晶数据

P3SEL=0x00;

P3DIR|=BIT0+BIT1+BIT2;//P3液晶控制

delay_ms(100);

P2SEL=0x00;//P1普通IO功能

P2DIR=0xf0;//P1。

0~P13。

3输入模式,外部电路已接上拉电阻

P2IE=0x0f;//开启P1低四位中断

P2IES=0x01;//下降沿触发中断

P2IFG=0x00;

_EINT();

LCD_init();

LCD_clear();

while

(1)

{

if(MENU==0)

{

LCD_clear();

LCD_write_str(0,0,"Thenumber:

");

LCD_write_str(0X08,1,"1234.5");

delay_ms(500);

}

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 机械仪表

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1