/*---------------------------------------------------------------*/
/* ------------2011年08月15日------------------- */
/*本程序实现飞思卡尔单片机HCS12X128控制RT-1602C LCD液晶显示模块 */
/*主要功能:实现翻页显示以字符数字组成的字符串,长度任意 每隔6s翻页并清屏*/
/*** 本程序接口:PORTA_PA2=RS;PORTA_PA1=R/W;PORTA_PA0=EN;PORTB=D0~D7;*/
/*VSS=BLK=GND;VDD=BLA=+5V;VO接电位器可调端,电位器两端接电源+5V*/
/*----------------------------------------------------------------*/
#include
#include "derivative.h" /* derivative-specific definitions */
void Init_MCU(void)
{ DisableInterrupts;//(1)禁止总中断
CLKSEL &= 0x7f; //此时:BusClock=OSCCLK/2
PLLCTL &= 0xbf; //先关闭PLL
//(4)根据需要的时钟频率设置SYNR和REFDV寄存器
//计算公式:PLLCLK=2*OSCCLK*((SYNR+1)/(REFDV+1))
SYNR = 0x04; //对PLLCLK增频的因子
REFDV = 0x03; //对PLLCLK分频的因子
PLLCTL |= (1<<6); //PLLCTL.6(pllon)设为1;开PLL
while ((CRGFLG&0x08) == 0x00);
CLKSEL |= (1<<7); //本句执行后:BusClock=PLLCLK/2
}
void Init_PORT(void)
{
DDRAB=0xffff; //为输出
PORTAB=0X0000;
}
void Delay_ms(unsigned int k)
{ unsigned int i=0,j=0;for (i=0; i
/*****************LCD忙碌状态测试**************************/
unsigned int LCD_busy()
{ unsigned int s;
unsigned int j;
PORTA_PA2=0;//RS 指令
PORTA_PA1=1; //R/W 读
PORTA_PA0=1; //EN使能
PORTA=0X03;
for(j=0;j<4;j++);
s=PORTB&0x80;
//PORTA_PA0=0;
PORTA=0X02;
return s;
}
/*****************写入指令数据到LCD**************************/
void LCD_wcmd( char cmd)
{ unsigned int j;
Delay_ms(2);
//while(LCD_busy());
PORTA_PA2=0;//RS 指令
PORTA_PA1=0; //R/W 读
PORTA_PA0=0; //EN使能
//PORTAB=0X0000;
for(j=0;j<2;j++);
PORTB=cmd;
for(j=0;j<4;j++);
PORTA_PA0=1; //EN使能置高电平
for(j=0;j<4;j++);
PORTA_PA0=0; //EN使能
}
/*****************LCD显示位置设定**************************/
void LCD_pos(unsigned int pos)
{
LCD_wcmd(pos|0x80);
}
/*****************写入字符显示数据到LCD**************************/
void LCD_wdata(unsigned char data)
{ unsigned int j;
Delay_ms(2);
//while(LCD_busy());
PORTA_PA2=1;//RS 指令
PORTA_PA1=0; //R/W 读
PORTA_PA0=0; //EN使能
//PORTA=0X04;
PORTB=data;
Delay_ms(80);
for(j=0;j<4;j++);
PORTA_PA0=1; //EN使能
// PORTA=0X01;
for(j=0;j<4;j++);
PORTA_PA0=0; //EN使能
//PORTA=0X00;
}
/*****************LCD初始化**************************/
void LCD_init()
{ LCD_wcmd(0x01);//清屏
Delay_ms(1);
LCD_wcmd(0x05);//光标滚动 从右到左 内容移动
Delay_ms(1);
LCD_wcmd(0x3f);// 不显示 不闪烁
Delay_ms(1);
LCD_wcmd(0x0f);//
Delay_ms(1);
LCD_wcmd(0x06);//
Delay_ms(1);
}
unsigned char dis[1000]={"Fixed an issue where the file name would be a messy code Or its extension would be missed,Fit Visible mode enables the PDF pages to fit the width of the window"};
unsigned char dis1[20]={" This is the end "};
unsigned char dis2[20]={" --Replay--"};
void main(void)
{
unsigned int i=0,j=0;
unsigned int line=1;
Init_MCU();
Init_PORT();
LCD_init();
Delay_ms(10);
for(;;)
{
if(dis[i]!='\0')
{ j=i%16;
if(line==1)
LCD_pos(0x00+j);
else LCD_pos(0x40+j);
LCD_wdata(dis[i]);
if((i+1)%16==0) {i++;line++;} else i++;
line=line%2;
if((i%16==0)&&(line==1))
{
Delay_ms(10000);LCD_wcmd(0x01);
}
}
else
{ Delay_ms(10000);
LCD_wcmd(0x01);
i=0; j=0;
while(dis1[i]!='\0')
{
LCD_pos(0x00+j);
LCD_wdata(dis1[i]);
i++;j++;
}
Delay_ms(10000);
LCD_wcmd(0x01);
i=0; j=0;
while(dis2[i]!='\0')
{
LCD_pos(0x00+j);
LCD_wdata(dis2[i]);
i++;j++;
}
Delay_ms(10000);
i=0;j=0;
line=1;
}
}
}