LCD1602 dynamic display--based on MSP430F149 single chip microcomputer[Copy link]
main.c /******************************************************** Program function: Dynamically display the text "welcome!" ---------------------------------------------------- Test instructions: Observe the LCD display ********************************************************/ #include #include "Cry1602.h" #define uchar unsigned char uchar *s1 = "welcome!"; void main ( void ) { uchar i; WDTCTL = WDT_ADLY_250; //Interval timer, 16ms LcdReset(); DispStr(4,0,s1); LocateXY(0,9); LcdWriteCommand(0x07, 1); LcdWriteCommand(0x07, 1); for(i = 12; i > 0; i--) { LcdWriteData(0x20); //Delay 250ms IFG1 &= ~WDTIFG; while(!(IFG1 & WDTIFG)); IFG1 &= ~WDTIFG; } while(1) { LcdWriteCommand(0x05, 1); //Move the overall display to the right for(i = 24; i > 0; i--) { LcdWriteData(0x20); //Delay 250ms IFG1 &= ~WDTIFG; while(!(IFG1 & WDTIFG)); IFG1 &= ~WDTIFG; } LcdWriteCommand(0x07, 1); //Move the overall display to the left for(i = 24; i > 0; i--) { LcdWriteData(0x20); //Delay 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; [size =4] /**************Macro definition***************/ [ size=4]#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; /************************ *************************** Function name: DispStr Function : Let the LCD display a string continuously from a certain position Parameters: x--column coordinate of the position y--row coordinate of the position [/size ] ptr--pointer to the location where the string is stored Return value: None ********************************************** **/ void DispStr(uchar x,uchar y,uchar *ptr) { uchar *temp;[/ size] uchar i,n = 0; temp = ptr; while(*ptr++ != '\0') n++; //Calculate the number of valid characters in the string for (i= 0;i" &="0x01;" (chk)="" (i="0;i<n;i++)" (x="=" )="" );="" *ptr)="" 0);="" 0);[="" 0x0f)[="" 1);="" <="" [="" [size="4]" ^="1;" _nop();="" _nop();[="" busy)!="0);" chk)="" chk--是否判忙的标志,1:判忙,0:不判[="" clr_en;="" clr_en;[="" clr_rs;="" clr_rs;[="" clr_rw;="" cmd,uchar="" ctrldir="" data="" data)="" data--显示的字符数据[="" datadir="0xFF;" dataport="cmd;" delay5ms();[="" delay5ms(void)[="" disp1char(uchar="" disp1char(x++,y,ptr);[="" disp1char(x++,y,temp);[="" dispnchar(uchar="" div="" for="" i="40000;" i--;[="" i;[="" if="" if(y)="" lcdreset(void)="" lcdwritecommand(0x01,="" lcdwritecommand(0x06,="" lcdwritecommand(0x08,="" lcdwritecommand(0x0c,="" lcdwritecommand(0x38,="" lcdwritecommand(temp,1);[="" lcdwritecommand(uchar="" lcdwritedata(="" locatexy(="" locatexy(uchar="" n,uchar="" n--字符个数[="" p4dir="" ptr--指向字符存放位置的指针[="" set_en;="" set_rs;[="" set_rw;[="" size]="" temp="x&0x0f;" temp;[="" uchar="" uint="" waitforenable();="" waitforenable(void)="" while="" while((p4in="" x="0;" x,="" x,uchar="" y="" y)="" y,="" y,uchar="" y--位置的行坐标[="" {[="" |="0x40;" }[="" 产生使能脉冲信号[="" 写字符时整体不移动[="" 如果在第2行[="" 将p4口切换为输入状态[="" 将p4口切换为输出状态[="" 将命令字写入数据端口="" 将显示数据写入数据端口[="" 控制线端口设为输出状态="" 数据端口设为输出状态[="" 数:cmd--命令,[="" 数:data--显示字符数据[="" 数:x--位置的列坐标[="" 数:无[="" 显示关闭[="" 显示开,不开游标,不闪烁[="" 显示模式设置[="" 显示清屏[="" 检测忙信号?[="" 检测忙标志[="" 等待液晶不忙[="" 能:向液晶显示的当前地址写入显示数据[="" 能:向液晶模块写入命令[="" 能:向液晶输入显示字符位置的坐标信息[="" 能:在某个位置显示一个字符[="" 能:对1602液晶模块进行复位操作[="" 能:延时约5ms[="" 能:等待1602液晶完成内部操作[="" 能:让液晶从某个位置起连续显示n个字符[="" 规定的复位操作[="" :无[="">
Thanks for sharing
1) First of all, thank you for sharing. 2) For delays exceeding 1ms, you can use timed event polling or message mechanism. It is best not to use the dead waiting method of while(!(IFG1 & WDTIFG)); This method has no real-time performance, especially when the system is large and has many functions. The result is unimaginable:titter:
Thanks for sharing, I'll learn from it~~{:1_103:}{:1_103:}{:1_103:}{:1_103:}{:1_103:}{:1_103:}
Lazy Cat Loves Flying published on 2019-3-12 13:18 1) First of all, thank you for sharing 2) For delays exceeding 1ms, you can make it into a timed event polling or cooperate with the message mechanism. It is best not to use while(!(IFG1 ...[/quote] In this program, you really need to wait, but this delay time can be appropriately shortened according to the actual test results
[quote]tiankai001 posted on 2019-3-14 11:39 In this program, you really need to wait, but the delay time can be shortened appropriately according to the actual test results
1) Whether to wait depends mainly on the program architecture. 2) You have to write the program to wait, and then process the next step. 3) I can also make it into a state machine, use it with a timer, and execute it in different steps (states), and it can still be completed.
Why is there no display on my LCD? The compilation is correct. Can you use it?
LCD1602 dynamic display--based on MSP430F149 single chip microcomputer
1) First of all, thank you for sharing. 2) For delays exceeding 1ms, you can use timed event polling or message mechanism. It is best not to use the dead waiting method of while(!(IFG1 & WDTIFG)); This method has no real-time performance, especially when the system is large and has many functions. The result is unimaginable
In this program, you really need to wait, but this delay time can be shortened appropriately according to the actual test results.
Details
Published on 2019-3-14 11:39
Personal signature专注智能产品的研究与开发,专注于电子电路的生产与制造……QQ:2912615383,电子爱好者群: void
Lazy Cat Loves Flying published on 2019-3-12 13:18 1) First of all, thank you for sharing 2) For delays exceeding 1ms, you can make it into a timed event polling or cooperate with the message mechanism. It is best not to use while(!(IFG1 ...
In this program, you really need to wait, but this delay time can be appropriately shortened according to the actual test results
1) Whether to wait or not depends on the program architecture. 2) You should write the program to wait and then process the next step. 3) I can also make it into a state machine, use it with a timer, and execute it in different steps (states), and it can still be completed.
Details
Published on 2019-3-14 15:05
tiankai001 posted on 2019-3-14 11:39 In this program, you really need to wait, but the delay time can be shortened appropriately according to the actual test results
1) Whether to wait depends mainly on the program architecture. 2) You have to write the program to wait, and then process the next step. 3) I can also make it into a state machine, use it with a timer, and execute it in different steps (states), and it can still be completed.