1602四线制驱动程序.doc_第1页
1602四线制驱动程序.doc_第2页
1602四线制驱动程序.doc_第3页
1602四线制驱动程序.doc_第4页
1602四线制驱动程序.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/* 1602四线制驱动程序-基于MSP430F149 FileName:LCD1602x4_mps.h Author:HuNB */ #include #defineset(x)P6OUT|=x #defineclr(x)P6OUT&=x #definersBIT2/RA1 #definerwBIT3/RA2 #defineeBIT4/RA3 /*- 函数说明 -*/ voidinit();/申明I/O口初始化函数 voiddelay_nus(unsignedintn);/NnS延时函数 voiddelay_nms(unsignedintn);/NmS延时函数 voidLCD_init(void);/LCD初始化函数 voidLCD_en_write(void);/LCD写入使能函数 voidLCD_write_command(unsignedcharcommand);/LCD写入命令函数 voidLCD_write_data(unsignedcharRecdata);/LCD写入数据函数 voidLCD_set_xy(unsignedcharx,unsignedchary);/LCD设置显示位置函数 voidLCD_write_char(unsignedcharX,unsignedcharY,unsignedcharRecdata);/LCD显示字符函数 intLCD_PutStr(unsignedchar*DData,intpos);/LCD显示字符串函数 /intLCD_PutNum(unsignedlongnum,intXS,intpos);/LCD显示数字函数 intp=0; /- /- /I/O口初始化函数 voidinit() /ADCON1=0X07;/设置A口为普通I/O口 /TRISA=0X00;/设置A口为输出 /TRISD=0X00;/设置D口为输出 P4DIR=0xff; P6DIR=0x1c;/设置A口为输出 WDTCTL=WDTPW+WDTHOLD;/杀狗 voiddelay_1us(void)/1us延时函数 _NOP(); voiddelay_nus(unsignedintn)/Nus延时函数 unsignedinti=0; for(i=0;in;i+) delay_1us(); voiddelay_1ms(void)/1ms延时函数 unsignedinti; for(i=0;i1140;i+); voiddelay_nms(unsignedintn)/Nms延时函数 unsignedinti=0; for(i=0;i4;/高四位移到低四位 delay_nus(16); clr(rs);/RS=0选择指令地址 clr(rw);/RW=0写操作 P4OUT&=0Xf0;/清低四位 P4OUT|=temp&0x0f;/写高四位 /command&0x0f; LCD_en_write(); P4OUT&=0xf0;/清高四位 P4OUT|=command&0x0f;/写低四位 LCD_en_write(); set(rw);/RW=1结束写操作 voidLCD_write_data(unsignedcharRecdata)/写数据 unsignedchartemp; temp=Recdata4;/高四位移到低四位 delay_nus(16); set(rs);/RS=1选择数据地址 clr(rw);/RW=0写操作 P4OUT&=0Xf0;/清高四位 P4OUT|=temp&0x0f;/Recdata&0xf0写高四位 LCD_en_write(); /Recdata=Recdata4;/低四位移到高四位 P4OUT&=0Xf0;/清高四位 P4OUT|=Recdata&0x0f;/写低四位 LCD_en_write(); set(rw);/RW=1结束写操作 voidLCD_set_xy(unsignedcharx,unsignedchary)/写地址函数 unsignedcharaddress; if(y=0)address=0x80+x; elseaddress=0xc0+x; LCD_write_command(address); voidLCD_init(void)/液晶初始化 LCD_write_command(0x28); delay_nus(40); LCD_write_command(0x28); delay_nus(40); LCD_write_command(0x28); delay_nus(40); LCD_en_write(); delay_nus(40); LCD_write_command(0x28);/4位显示 LCD_write_command(0x0c);/显示开 LCD_write_command(0x01);/清屏 delay_nms(5); voidLCD_write_char(unsignedcharX,unsignedcharY,unsignedcharRecdata)/列x=015,行y=0,1 LCD_set_xy(X,Y);/写地址 LCD_write_data(Recdata); intLCD_PutStr(unsignedchar*DData,intpos) unsignedchari; if(pos=-1) LCD_write_command(0x01);/清屏 delay_nms(2); pos=0; while(*DData)!=0) switch(*DData) casen:/如果是n,则换行 if(pos17) for(i=pos;i16;i+) LCD_write_char(i%16,i/16,); pos=16; else for(i=pos;i0)pos-; LCD_write_char(pos%16,pos/16,); break; default: if(*DData)0x20) *DData=; LCD_write_char(pos%16,pos/16,*DData); pos+; break; DData+; return(pos); /*-以下函数用于输出数字- intLCD_PutNum(unsignedlongnum,intXS,intpos)/从右边数,保留几位小数 unsignedlongtmp=0; unsignedcharnumbits=0; if(pos=-1) LCD_write_command(0x01); delay_nms(2); pos=0; if(num=0) LCD_write_char(pos%16,pos/16,0); pos+; else if(num0) LCD_write_char(pos%16,pos/16,-); num*=(-1); pos+; while(num) tmp=tmp*10+(num%10); num=num/10; numbits+; while(tmp) LCD_write_char(pos%16,pos/16,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论