这个简单,你在当前菜单下设置一个下翻的按键,按一下时,重新写入后面的显示内容,也就是将前三行的内容删除掉,重新写入。
if(KEY_NEXT)
{
delate(page1);
write(page2);
}
void delate(unsigned char page)
{
}
void write(unsigned char page)
{
}
这个是1602内部结构决定的,你只需要在初始化的时候先设置三次显示,然后再设置你的其他要求。
芯片厂家推荐的用法:
INT:
MOV
A,#30H
MOV
DATR,#CW_ADD
MOV
R2,#03H
INT1:
MOVX
@DPTR,A
CALL
DELAY
DJNZ
R2,INT1
这上面就是1602对于51单片机推荐的初始化之前加的三次模式设置
#include "reg52h"
sbit LED=P1^0;//LED锁存器
sbit SEG=P1^1;//数码管段选锁存器
sbit DIG=P1^2;//数码管位选锁存器
unsigned char t;
sbit LCDRS=P2^7;//数据指令控制
sbit LCDRW=P2^6;//读写控制
sbit LCDEN=P2^5;//液晶屏使能控制
//延时函数,延时n1ms
void delay(unsigned char n)
{
int i,j;
for (i=0; i<n; i++)
for (j=0; j<100; j++)
;
}
//写命令
void Write_Cmd(unsigned char C)
{
LCDEN=1;//使能端,由高电平跳变成低电平时,液晶屏模块执行命令
LCDRS=0;//指令寄存器选择
P0=C;
delay(5);
LCDEN=0;
}
//写数据
void Write_Data(unsigned char D)
{
LCDEN=1;//使能端,由高电平跳变成低电平时,液晶屏模块执行命令
LCDRS=1;//选择数据寄存器
P0=D;
delay(5);
LCDEN=0;
}
//LCD初始化
void LCD_Init()
{
LCDRS=0;//指令寄存器选择
Write_Cmd(0x01);//清屏
Write_Cmd(0x38);//功能设置8位双行显示57点阵
Write_Cmd(0x0F);//开关显示设置
Write_Cmd(0x06);//输入方式设置,光标从左向右移动,内容不移动
}
void main()
{
unsigned char Code1[]="I LOVE MCU!";
unsigned char m;
//LED,数码管锁存器片选设置
LED=0;
DUAN=0;
WEI=0;
LCDRW=0;//写选择
LCD_Init();
Write_Cmd(0x80+0x01);//写入显示缓冲区起始地址为1行2列
for(m=0;m<11;m++)
{
Write_Data(Code1[m]);
delay(3);
}
while (1)
;
}//end of main
整个液晶的延时还用定时器啊,大哥你太大题小做了吧,延时时间 去看数据手册,现在的液晶有做的很好的,上面各种数据写的清楚的呢,还10ms?,你以为80年代的技术啊,正轨的程序你是要随时 查忙型号的 他俩就是图省事,弄个大延时,不用查忙信号。楼主还是按正轨的走吧。
i_data&=0xf0; // i_data=i_data&0xf0; 高位字节与上1则不变,低四位则被清零 ,因为该12864为串行方式写入,一次需写入8个bit,故采用循环结构比较好 *** 作,建议多看DATASHEET以及C语言相关
应该不是判断忙碌或者不只是判断忙碌,这个语句应该是送了一串命令进去
//HD44780 LCD DRIVER
#include <AT89X52H>
#include <ctypeh>
//LCD Commands
#define LCD_CLS 1 //Clears entire display and sets DDRAM address 0
#define LCD_HOME 2 //Sets DDRAM address 0 in address counter
#define LCD_SETMODE 4 //Sets cursor move direction and specifies display shift
#define LCD_SETVISIBLE 8 //Sets entire display (D) on/off,cursor on/off (C), and blinking of cursor position character (B)
#define LCD_SHIFT 16 //Moves cursor and shifts display without changing DDRAM contents
#define LCD_SETFUNCTION 32 //Sets interface data length (DL), number of display lines (N), and character font (F)
#define LCD_SETCGADDR 64 //Sets CGRAM addressCGRAM data is sent and received after this setting
#define LCD_SETDDADDR 128 //Sets DDRAM address DDRAM data is sent and received after this setting
#define TURE 1
#define FORSE 0
#define TMH 0xf8 //delay timeh 2ms
#define TML 0xCD //delay timel
//------------------------------------------
#define MAX_DISPLAY_CHAR 2
//-----------------------------------------
unsigned char code text[6]="hellow";
static unsigned char data counter,a;
void wcchar(unsigned char d); //write a command char
void wdchar(unsigned char i); //write a data char
char wtbusy(); //wait busy sign
void clrscr(void); //clear screen
void initime0(void); //initial time0
void delay(unsigned char i); //delay
//-------------------------------
unsigned char crc8(unsigned char pData,unsigned char count);
unsigned char pData[]={0x33,0x12,0x34,0x56,0x78,0x33,0x12,0x23,0x45,0x56};
unsigned char data crc;
static char outputbuffer[MAX_DISPLAY_CHAR];
char calc_decascii(char num);
//-------------------------------
void ISR_Timer0(void) interrupt 1
{
TL0=TML;
TH0=TMH;
counter--;
}
void ISR_Int0(void) interrupt 0
{
wdchar(text[a++]); //display "hellow"
if (a>=6)
{a=0;wdchar(' ');}
}
//main program display "hellow"
main(void)
{
unsigned char data k;
initime0();
wcchar(0x38); //initial lcd
wcchar(LCD_SETVISIBLE+6); //set lcd visible
clrscr(); //clear lcd
while(1)
{
crc8(&pData,10);
calc_decascii(crc);
wdchar (outputbuffer[1]);
wdchar (outputbuffer[2]);
wdchar (' ');
for(k=0;k<=6;k++)
{
// wdchar(text[k]); //display "hellow"
P1_2=0;
delay(55); //delay
P1_2=1;
delay(55); //delay
}
}
}
//sub function || display a char
void wdchar(unsigned char i) //write a char
{
unsigned char xdata j;
P1_0=1;
P1_1=0;
j=0x8000;
j=i;
while (wtbusy())
{}
}
void wcchar(unsigned char d) //write a command char
{
unsigned char xdata j;
P1_0=0;
P1_1=0;
j=0x8000;
j=d;
while (wtbusy())
{}
}
char wtbusy() //wait busy sign
{
unsigned char xdata j;
P1_0=0;
P1_1=1;
j=0x8000;
if(j&0x80)
{
return TURE;
}
else
{
return FORSE;
}
}
//clear screen
void clrscr()
{
wcchar(LCD_CLS);
}
//initial time0
void initime0()
{
TL0=TML;
TH0=TMH;
TR0=TURE;
IE=0x93; //Enable T0 and Serial Port
}
//sub function time delay
void delay(unsigned char i)
{
counter=i;
while (counter)
{}
}
unsigned char crc8(unsigned char pData,unsigned char count)
{
// unsigned char crc;
crc = 0;
while (count-- > 0)
{
crc ^= pData++;
}
return crc;
}
char calc_decascii(char num)
// A rather messy function to convert a floating
// point number into an ASCII string
{ long data temp = num;
char data arrayptr = &outputbuffer[MAX_DISPLAY_CHAR];
long data divisor = 10;
long data result;
char data remainder,asciival;
int data i;
// If the result of the calculation is zero
// insert a zero in the buffer and finish
if (!temp)
{ arrayptr = 48;
goto done;
}
// Handle Negative Numbers
if (temp < 0)
{ outputbuffer[0] = '-';
temp -= 2temp;
}
for (i=0 ; i < sizeof(outputbuffer) ; i++)
{ remainder = temp % divisor;
result = temp / divisor;
// If we run off the end of the number insert a space into
// the buffer
if ((!remainder) && (!result))
{ arrayptr = ' ';}
// We're in business - store the digit offsetting
// by 48 decimal to account for the ascii value
else
{ asciival = remainder + 48;
arrayptr = asciival;
}
temp /= 10;
// Save a place for a negative sign
if (arrayptr != &outputbuffer[1]) arrayptr--;
}
done: return outputbuffer;
}
程序只是没有逻辑错误和语法错误,但液晶的控制貌似有些问题。给你一段1602的驱动程序做参考。
#define LCD1602_FLAG
#define LCD1602_PORT P1
#include<reg52h>
#include<stddefh>
#include"dtypeh"
sbit lcd1602_rs=P3^7;
sbit lcd1602_e=P3^5;
sbit lcd1602_rw=P3^6;
sbit lcd1602_busy=P1^7;
/
函数名称:lcd1602_CheckBusy()
函数功能:状态查询
/
void lcd1602_CheckBusy()
{
do
{
lcd1602_busy=1;
lcd1602_rs=0;
lcd1602_rw=1;
lcd1602_e=0;
lcd1602_e=1;
}
while(lcd1602_busy);
}
/
函数名称: lcd1602_WriteCmd()
函数功能:写命令
入口参数:命令字
出口参数:无
/
void lcd1602_WriteCmd(const INT8U cmd)
{
lcd1602_CheckBusy();
lcd1602_rs=0;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=cmd;
lcd1602_e=0;
}
/
函数名称:lcd1602_WriteData()
函数功能:写数据
入口参数:c--待写数据
出口参数:无
/
void lcd1602_WriteData(const INT8U c)
{
lcd1602_CheckBusy();
lcd1602_rs=1;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=c;
lcd1602_e=0;
}
/
函数名称:lcd1602_Init()
函数功能:初始化LCD
入口参数:无
出口参数:无
/
void lcd1602_Init()
{
lcd1602_WriteCmd(0x38); //显示模式为8位2行57点阵
lcd1602_WriteCmd(0x0f); //display enable,flag enable,flash enable,
lcd1602_WriteCmd(0x06); //flag move to right,screen don't move
lcd1602_WriteCmd(0x01); //clear screen
}
/
函数名称:lcd1602_Display()
函数功能: 字符显示
入口参数:ptr--字符或字符串指针
出口参数:无
说 明:用户可通过以下方式来调用:
1)lcd1602_Display("Hello,world!");
2) INT8U 存储类型 txt[]="要显示的字符串";
或者 INT8U 存储类型 txt[]={'t','x','t',,'\0'};
INT8U ptr;
ptr=&txt;
lcd1602_Display(ptr);
或 lcd1602_Display(txt);
或 lcd1602_Display(&txt);
/
void lcd1602_Display(const INT8U ptr)
{
INT8U data i=0;
INT8U data q;
q=ptr;
lcd1602_WriteCmd(0x80);
while(q!=NULL && (q!='\0') && i<16)
{
lcd1602_WriteData(q);
q++;
i++;
}
lcd1602_WriteCmd(0xc0);
while(q!=NULL && (q!='\0') && i>=16 && i<32)
{
lcd1602_WriteData(q);
q++;
i++;
}
}
以上就是关于单片机液晶翻页显示的程序全部的内容,包括:单片机液晶翻页显示的程序、51单片机C语言1602液晶显示程序解析、谁有51单片机彩色液晶程序的详解啊等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)