main.c
/***************************************************
程序功能:动态显示文字“welcome!”
----------------------------------------------------
测试说明:观察液晶显示
****************************************************/
#include #include "Cry1602.h" #define uchar unsigned char uchar *s1 = "welcome!"; void main( void ) { uchar i; WDTCTL = WDT_ADLY_250; //间隔定时器,定时16ms LcdReset(); DispStr(4,0,s1); LocateXY(0,9); //确定写入字符的显示位置 LcdWriteCommand(0x07, 1); //整体显示左移 for(i = 12; i > 0; i--) { LcdWriteData(0x20); //延时250ms IFG1 &= ~WDTIFG; while(!(IFG1 & WDTIFG)); IFG1 &= ~WDTIFG; } while(1) { LcdWriteCommand(0x05, 1); //整体显示右移 for(i = 24; i > 0; i--) { LcdWriteData(0x20); //延时250ms IFG1 &= ~WDTIFG; while(!(IFG1 & WDTIFG)); IFG1 &= ~WDTIFG; } LcdWriteCommand(0x07, 1); //整体显示左移 for(i = 24; i > 0; i--) { LcdWriteData(0x20); //延时250ms IFG1 &= ~WDTIFG; while(!(IFG1 & WDTIFG)); IFG1 &= ~WDTIFG; } } } cry1602.h void DispStr(unsigned char x,unsigned char y,unsigned char *ptr); void DispNChar(unsigned char x,unsigned char y, unsigned char n,unsigned char *ptr); void LocateXY(unsigned char x,unsigned char y); void Disp1Char(unsigned char x,unsigned char y,unsigned char data); void LcdReset(void); void LcdWriteCommand(unsigned char cmd,unsigned char chk); void LcdWriteData( unsigned char data ); void WaitForEnable(void); void Delay5ms(void); cry1602.c #include #include "cry1602.h" typedef unsigned char uchar; typedef unsigned int uint; /**************宏定义***************/ #define DataDir P4DIR #define DataPort P4OUT #define Busy 0x80 #define CtrlDir P3DIR #define CLR_RS P3OUT&=~BIT0; //RS = P3.0 #define SET_RS P3OUT|=BIT0; #define CLR_RW P3OUT&=~BIT1; //RW = P3.1 #define SET_RW P3OUT|=BIT1; #define CLR_EN P3OUT&=~BIT2; //EN = P3.2 #define SET_EN P3OUT|=BIT2; /*********************************************** 函数名称:DispStr 功 能:让液晶从某个位置起连续显示一个字符串 参 数:x--位置的列坐标 y--位置的行坐标 ptr--指向字符串存放位置的指针 返回值 :无 ***********************************************/ void DispStr(uchar x,uchar y,uchar *ptr) { uchar *temp; uchar i,n = 0; temp = ptr; while(*ptr++ != '