51单片机用12864显示唐诗.docx

上传人:b****8 文档编号:10082743 上传时间:2023-02-08 格式:DOCX 页数:9 大小:15.86KB
下载 相关 举报
51单片机用12864显示唐诗.docx_第1页
第1页 / 共9页
51单片机用12864显示唐诗.docx_第2页
第2页 / 共9页
51单片机用12864显示唐诗.docx_第3页
第3页 / 共9页
51单片机用12864显示唐诗.docx_第4页
第4页 / 共9页
51单片机用12864显示唐诗.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

51单片机用12864显示唐诗.docx

《51单片机用12864显示唐诗.docx》由会员分享,可在线阅读,更多相关《51单片机用12864显示唐诗.docx(9页珍藏版)》请在冰豆网上搜索。

51单片机用12864显示唐诗.docx

51单片机用12864显示唐诗

51单片机用12864显示唐诗

51单片机用12864显示唐诗

#include

#include

#include

#include"nn.h"

#defineucharunsignedchar

#defineuintint

#defineLCD_databusP0//LCD12864的8位数据口

sbitRS=P2^2;//RS为0---命令;1----数据

sbitRW=P2^1;//RW为1---写;0---读

sbitEN=P2^0;//使能端

sbitCS1=P2^4;//片选1低电平有效,控制左半屏

sbitCS2=P2^3;//片选1低电平有效,控制右半屏

sbitkey1=P3^0;

sbitkey2=P3^1;

voiddelay_ms(uintz)

{

uintx,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

 

voiddelay(uinti)

{

while(--i);

}

voidRead_busy()//读“忙”函数-----数据线的最高位DB71则busy

{

P0=0x00;

RS=0;

RW=1;

EN=1;

while(P0&0x80);

EN=0;

}

voidwrite_LCD_command(ucharvalue)//写命令函数

{

Read_busy();//对LCD的每次读写都要读忙

RS=0;//选择命令

RW=0;//读操作

LCD_databus=value;

EN=1;//EN由1----0锁存有效数据

_nop_();

_nop_();

EN=0;

}

voidwrite_LCD_data(ucharvalue)//写数据函数

{

Read_busy();

RS=1;//选择数据

RW=0;

LCD_databus=value;

EN=1;//EN由1----0锁存有效数据

_nop_();

_nop_();

EN=0;

}

voidSet_page(ucharpage)//设置“页”LCD12864共8页,一页是8行点阵点

{

page=0xb8|page;//页的首地址为0xB8

write_LCD_command(page);

}

voidSet_line(ucharstartline)//设置显示的起始行

{

startline=0xC0|startline;//起始行地址为0xC0

write_LCD_command(startline);//设置从哪行开始:

共0--63;一般从0行开始显示

}

voidSet_column(ucharcolumn)//设置显示的列

{

column=column&0x3f;//列的最大值为64

column=0x40|column;//列的首地址为0x40

write_LCD_command(column);//规定显示的列的位置

}

voidSetOnOff(ucharonoff)//显示开关函数:

0x3E是关显示,0x3F是开显示

{

onoff=0x3e|onoff;//onoff:

1---开显示;0---关显示

write_LCD_command(onoff);

}

voidSelectScreen(ucharscreen)//选择屏幕

{

switch(screen)

{

case0:

CS1=0;CS2=0;break;//全屏

case1:

CS1=0;CS2=1;break;//左半屏

case2:

CS1=1;CS2=0;break;//右半屏

default:

break;

}

}

voidClearScreen(ucharscreen)//清屏函数

{

uchari,j;

SelectScreen(screen);//0--全屏;1---左半屏;2---右半屏

for(i=0;i<8;i++)//控制页数0-7,共8页

{

Set_page(i);

Set_column(0);

for(j=0;j<64;j++)//控制列数0-63,共64列

{

write_LCD_data(0x00);//写入0,地址指针自加1

}

}

}

voidinit_LCD()//LCD的初始化

{

SetOnOff

(1);//开显示

SelectScreen(0);

ClearScreen(0);//清屏

Set_line(0);//开始行:

0

}

 

voidDisplay_HZ(ucharscreen,ucharpage,ucharcolumn,uchar*p)

{

uchari;

SelectScreen(screen);

Set_page(page);//写上半页:

16*8

Set_column(column*16);//控制列

for(i=0;i<16;i++)//控制16列的数据输出

{

write_LCD_data(p[i]);//汉字的上半部分

}

Set_page(page+1);//写下半页:

16*8

Set_column(column*16);//控制列

for(i=0;i<16;i++)//控制16列的数据输出

{

write_LCD_data(p[i+16]);//汉字的下半部分

}

}

 

voiddisp1()

{ClearScreen(0);

Display_HZ(1,0,0,zi);//guanjianzhizheng

Display_HZ(1,0,1,yun);//guanjianzhizheng

Display_HZ(1,0,2,san);//guanjianzhizheng

Display_HZ(1,0,3,hao);//guanjianzhizheng

 

Display_HZ(1,2,0,sheng);//guanjianzhizheng

Display_HZ(1,2,1,dang);//guanjianzhizheng

Display_HZ(1,2,2,zuo);//guanjianzhizheng

Display_HZ(1,2,3,ren);//guanjianzhizheng

Display_HZ(2,2,0,jie);//guanjianzhizheng

Display_HZ(1,4,0,si);//guanjianzhizheng

Display_HZ(1,4,1,yi);//guanjianzhizheng

Display_HZ(1,4,2,wei);//guanjianzhizheng

Display_HZ(1,4,3,gui);//guanjianzhizheng

Display_HZ(2,4,0,xiong);//guanjianzhizheng

Display_HZ(1,6,0,zhi);//guanjianzhizheng

Display_HZ(1,6,1,jin);//guanjianzhizheng

Display_HZ(1,6,2,sii);//guanjianzhizheng

Display_HZ(1,6,3,xiang);//guanjianzhizheng

Display_HZ(2,6,0,yu);

//while

(1);

}

voiddisp2()

{ClearScreen(0);

Display_HZ(1,0,0,bu);//guanjianzhizheng

Display_HZ(1,0,1,ken);//guanjianzhizheng

Display_HZ(1,0,2,guo);//guanjianzhizheng

Display_HZ(1,0,3,jiang);//guanjianzhizheng

Display_HZ(2,0,0,dong);//guanjianzhizheng

}

voidKey1()

{

if(key1==0)

{

delay_ms(10);

if(key1==0)

{

while(!

key1)

{

while(!

key1)

{

disp2();

}

}

}

}

}

voidKey2()

{

if(key2==0)

{

delay_ms(10);

if(key2==0)

{

while(!

key2)

{

while(!

key2)

{

disp1();

}

}

}

}

}

voidmain()

{

init_LCD();//初始12864

ClearScreen(0);//清屏

Set_line(0);//显示开始行

disp1();

while

(1)

{

Key1();

Key2();

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1