这是一段MSP430G2553做出来的LCD1602的字符循环显示程序,有两个问题,第一个是现在字符循环速度太快了,怎么把循环速度改慢;第二个问题是,怎么改能去掉循环显示,只在屏幕上显示不移动的字符,在线等,谢了。
主程序
#include <msp430G2553.h>
#include "cry1602.h"
#define uchar unsigned char
uchar *s1 = "mmmmmmmmmmmmmmmmmmmmmm";
void main(void)
{
WDTCTL = WDT_ADLY_250;
uchar *s2;
uchar j,k,l;
uchar i = 0;
s2 = s1;
LcdReset();
while(*s1++ != '\0') i++;
while(1)
{
for(j = 0;j < i;j++)
{
l = j;
for(k = 0;k < 16;k++)
{
if(l < i)
Disp1Char(k,0,s2[l++]);
else
Disp1Char(k,0,' ');
}
IFG1 &= ~WDTIFG;
IFG1 &= ~WDTIFG;
IFG1 &= ~WDTIFG;
}
}
}
子程序
#include<msp430G2553.h>
#include"cry1602.h"
/*宏定义*/
#define datadir P1DIR
#define dataport P1OUT
#define busy 0x80
#define ctrldir P2DIR
#define CLR_RS P2OUT &= ~BIT0;
#define SET_RS P2OUT |= BIT0;
#define CLR_RW P2OUT &= ~BIT1;
#define SET_RW P2OUT |= BIT1;
#define CLR_EN P2OUT &= ~BIT2;
#define SET_EN P2OUT |= BIT2;
/*让液晶从某个位置起连续显示一个字符串*/
void DispStr(uchar x,uchar y,uchar *ptr)
{
uchar*temp;
uchari,n = 0;
temp= ptr;
while(*ptr++ != '\0') n++;
for(i = 0; i < n; i++)
{
Disp1Char(x++,y,temp[i]);
if(x == 0x0f)
{
x=0;
y^=1;
}
}
/*让液晶从某个位置起连续显示一个字符串*/
void DispNChar(ucharx,uchar y,uchar n,uchar *ptr)
{
uchari;
for(i = 0; i < n; i++)
{
Disp1Char(x++,y,ptr[i]);
if(x == 0x0f)
{
x=0;
y^=1;
}
}
}
/*向液晶输入显示字符位置的坐标信息*/
void LocateXY(ucharx,uchar y)
{
uchartemp;
temp= x&0x0f;
y&= 0x01;
if(y)
temp|= 0x40;
temp|= 0x80;
LcdWriteCommand(temp,1);
}
/*在某个位置显示一个字符*/
void Disp1Char(ucharx,uchar y,uchar data)
{
LocateXY(x,y);
LcdWriteData(data);
}
/*对1602液晶模块进行复位操作*/
void LcdReset(void)
{
ctrldir|= 0x07;
datadir= 0xff;
LcdWriteCommand(0x38,0);
Delay5ms();
LcdWriteCommand(0x38,0);
Delay5ms();
LcdWriteCommand(0x38,0);
Delay5ms();
LcdWriteCommand(0x38,1);
LcdWriteCommand(0x08,1);
LcdWriteCommand(0x01,1);
LcdWriteCommand(0x06,1);
LcdWriteCommand(0x0c,1);
}
/*向液晶模块写入命令*/
void LcdWriteCommand(ucharcmd,uchar chk)
{
if(chk) WaitForEnable();
CLR_RS;
CLR_RW;
_NOP();
dataport= cmd;
_NOP();
SET_EN;
_NOP();
_NOP();
CLR_EN;
}
/*向液晶显示的当前地址写入显示数据*/
void LcdWriteData(uchardata)
{
WaitForEnable();
SET_RS;
CLR_RW;
_NOP();
dataport= data;
_NOP();
SET_EN;
_NOP();
_NOP();
CLR_EN;
}
/*等待1602液晶完成内部操作*/
void WaitForEnable(void)
{
P1DIR&= 0X00;
CLR_RS;
SET_RW;
_NOP();
SET_EN;
_NOP();
_NOP();
while((P1IN & busy) !=0);
CLR_EN;
P1DIR|= 0xff;
}
/*延时约5ms*/
void Delay5ms(void)
{
uinti = 40000;
while(i != 0)
{
i--;
}
}
} |