找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2995|回复: 0
收起左侧

51单片机12864程序

[复制链接]
ID:88234 发表于 2015-8-12 23:36 | 显示全部楼层 |阅读模式
//本程序为最简单的显示汉字程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int

sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;

//sbit  rst=P1^5;
uchar code table1[]="好好学习单片机!" ;
uchar code table2[]=123456" ;
/*****************延时***************/
void delayms(uint z) //延时子程序
{
  uint x,y;
  for(x=z;x>0;x--)
     for(y=110;y>0;y--);
}

void delay50us(uint z) //延时子程序
{
  uint x,y;
  for(x=z;x>0;x--)
     for(y=19;y>0;y--);
}



/***********写命令**********************/

void write_12864com(uchar com)
{
e=0;//为后面做准备
rw=0;//为低时写有效
rs=0;//为为是写命令,为1是写数据
delay50us(1);
P0=com;
e=1;//一个高脉冲,命令写入
delay50us(10);
e=0;//拉低为下一个准备
delay50us(10);
}


/***********写数据**********************/

void write_12864dat(uchar dat)
{
e=0;//为后面做准备
rw=0;//为低时写有效
rs=1;//为为是写命令,为1是写数据
delay50us(1);
P0=dat;
e=1;//一个高脉冲,命令写入
delay50us(10);
e=0;//拉低为下一个准备
delay50us(10);
}

void init_12864()
{
delayms(100);
// rst=1;//rst为1是使用8位并行数据传送
write_12864com(0x30);
delay50us(5);
write_12864com(0x30);
delay50us(5);
write_12864com(0x0e);//打开所有显示
delay50us(5);
write_12864com(0x0c);//不显示光标
  delay50us(5);
write_12864com(0x01);//清除显示
delayms(20);
write_12864com(0x06); //模示设置
delay50us(5);
}


void hanzi(uchar *ch)
{
        while(*ch!=0)
        write_12864dat(*ch++);
        delayms(200);        
}


void display3()
{
uchar i;
write_12864com(0x90);
for(i=0;i<16;i++)
     {
         write_12864dat(table1[ i]);
         delay50us(5);
         }
}

void display4()
{
uchar i;
write_12864com(0x98);
for(i=0;i<16;i++)
     {
         write_12864dat(table2[ i]);
         delay50us(5);
         }
}

void display5()
{
write_12864com(0x80);
//hanzi("白日依山尽,  唐");

hanzi("欢迎来到——");
delay50us(5);
write_12864com(0x90);
hanzi(单片机");
//hanzi("黄河入海流。王");
delay50us(5);
write_12864com(0x88);
//hanzi("欲穷千里目,之");
hanzi("单片机人人能学好");
delay50us(5);
write_12864com(0x98);
//hanzi("更上一层楼。涣");
hanzi("我棒,我很行!!");
delay50us(5);                        
}

void main()
{
init_12864();

//display3();
//display4();
display5();
P2=0x00;
while(1);
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表