msp430计算器设计(共13页).doc
《msp430计算器设计(共13页).doc》由会员分享,可在线阅读,更多相关《msp430计算器设计(共13页).doc(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上#include msp430x14x.h#include double r;#include duoxiangshi.h#define RS_1 P3OUT|=BIT0#define RS_0 P3OUT&=BIT0#define RW_1 P3OUT|=BIT1#define RW_0 P3OUT&=BIT1#define E_1 P3OUT|=BIT2#define E_0 P3OUT&=BIT2#define DATA P4OUT#define data_dir P4DIR#define KEYDIR P5DIR#define KEYOUT P5OUT#def
2、ine KEYIN P5IN#define led P2OUT#define LED1 P2DIR=0XFF;#define uchar unsigned char#define uint unsigned intchar table116=1;char table216= ;char flag;int flag1;/*延时*/void delay(void) unsigned int i,j; for(i=0;i50;i+) for(j=0;j10;j+) ; /*消抖延时*/void delay_key(void) int i,j; for(i=0;i500;i+) for(j=0;j10
3、0;j+) ; void delayms(uchar ms) int i,j; for(i=0;ims;i+) for(j=0;j157;j+);int key_column_scan() int a; P5DIR = 0xff; P5OUT = 0x0f; P5DIR = 0X00; a = P5IN; switch(a) case 0x8f:return 4; case 0x4f:return 3; case 0x2f:return 2; case 0x1f:return 1; int key_line_scan() int a,column,key=-1,line; P5DIR = 0x
4、ff; P5OUT = 0xf0; P5DIR = 0X00; a = P5IN; if(a!=0xf0) column = key_column_scan(); switch(a) case 0xf8:line=4;break; case 0xf4:line=3;break; case 0xf2:line=2;break; case 0xf1:line=1;break; key=(line-1)*4+column; delay_key(); /延时消抖 for(;) P5DIR = 0xff; /软件消抖 P5OUT = 0xf0; P5DIR = 0X00; a = P5IN; if(a=
5、0xf0) break; return key;/给LCD1602写命令void write_com(uchar com) RS_0; RW_0; E_0; DATA=com; E_1; delayms(5); E_0; /给LCD1602写数据void write_data(uchar data) RS_1; RW_0; E_0; DATA=data; E_1; delayms(5); E_0; /初始化LCD1602void lcd_init() data_dir=0xff; P3DIR|=BIT0+BIT1+BIT2; write_com(0x38); /设置16*2显示,双行,5*7点
6、阵 write_com(0x01); /清屏 write_com(0x06); /字符进入模式;屏幕不动,字符后移 write_com(0x0f); /显示开,光标开,光标闪烁 write_com(0x80); /在指定位置显示字符串void lcd_string(uchar r,uchar c,uchar *str) /r表示行数,C表示在R行的第几位,*str表示输入的字符串 uchar i=0; uchar DDRAM=0x80,0xc0; /LCD1602两行的起始地址 write_com(DDRAMr|c); /设置显示的起始位置 for(i=0;stri&i16;i+) /输出字符
7、串 write_data(stri); for(;i16;i+) write_data( ); /一行不足时用空格填充int main( void ) / Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; int key,m,i=0; flag=0; flag1=0; lcd_init(); while(1) key=key_line_scan(); if(key!=-1) switch(key) case 1:write_data(7);table1+i=7;break; case 2:write_
8、data(8);table1+i=8;break; case 3:write_data(9);table1+i=9;break; case 4: write_data(+);write_com(0x80+i); while(1) key=key_line_scan(); if(key!=-1) if(key=4) flag1+; if(flag1%4=0) write_data(+);write_com(0x80+i); else if(flag1%4=1) write_data(-);write_com(0x80+i); else if(flag1%4=2) write_data(*);wr
9、ite_com(0x80+i); else if(flag1%4=3) write_data(/);write_com(0x80+i); else if(key!=4) if(flag1%4=0) write_data(+);table1+i=+;flag1=0; else if(flag1%4=1)write_data(-);table1+i=-;flag1=0; else if(flag1%4=2) write_data(*);table1+i=*;flag1=0; else if(flag1%4=3) write_data(/);table1+i=/;flag1=0; switch(ke
10、y) case 1:write_data(7);table1+i=7;break; case 2:write_data(8);table1+i=8;break; case 3:write_data(9);table1+i=9;break; case 5:write_data(4);table1+i=4;break; case 6:write_data(5);table1+i=5;break; case 7:write_data(6);table1+i=6;break; case 8: if(flag=0)write_data(#);table1+i=#;break; else write_da
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- msp430 计算器 设计 13
限制150内