资源描述:
《proteus仿真四个外部中断按键+1602液晶.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Proteus仿真外部中断,共4个按键,控制1602液晶显示,基于MSP430F249程序1(库文件KU.h):/**************************************************//****//延时设置~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~////***********************************************************#defineCPU_F((double)4000000)////主时钟的频率4MHz#definedelay_us(x)_
2、_delay_cycles((long)(CPU_F*(double)x/1000000.0))#definedelay_ms(x)__delay_cycles((long)(CPU_F*(double)x/1000.0))#defineRS0P3OUT&=~BIT0#defineRS1P3OUT
3、=BIT0#defineRW0P3OUT&=~BIT1#defineRW1P3OUT
4、=BIT1#defineEN0P3OUT&=~BIT2#defineEN1P3OUT
5、=BIT2//****************************************
6、***********////时钟设置//************************************************////驱动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);
7、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(
8、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
9、.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_c
10、har(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://移位
11、if(MENU==1){B1=~B1;