12864液晶並行方式顯示

來源:互聯網
上載者:User

標籤:style   blog   使用   os   for   art   ar   代碼   

12864液晶使用的16*16點陣、128個字元(8*16點陣)及64*256點陣顯示RAM(GDRAM).與外部CPU介面採用並行或串列兩種控制方式。


在12864上顯示0-9的隨機數 第二行顯示www.csdn.blog

第三行顯示“求是07的部落格”

第四行顯示“歡迎光臨”


下面是基本的代碼

#include <reg52.h>
#include <intrins.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_data=P0;
sbit rs=P3^5;
sbit wr=P3^6;
sbit en=P3^4;
sbit rd=P3^7;
sbit wela=P2^6;
sbit dula=P2^7;
uchar display1[10];
uchar code display2[]={"www.csdn.blog.com"};
uchar code display3[]={"求是07的部落格"};
uchar code display4[]={"歡迎光臨"};
void delay_1ms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<100;j++);
}


void write_cmd(uchar cmd)
{
rs=0;
wr=0;
en=0;
P0=cmd;
delay_1ms(5);
en=1;
delay_1ms(5);
en=0;
}


void write_data(uchar dat)
{
rs=1;
wr=0;
en=0;
P0=dat;
delay_1ms(5);
en=1;
delay_1ms(5);
en=0;
}


void lcd_pos(uchar X,uchar Y)
{
uchar pos;
if(X==0)
{X=0x80;}
if(X==1)
{
X=0x90;
}
if(X==2)
{
X=0x88;
}
if(X==3)
{
X=0x98;
}
pos=X+Y;
write_cmd(pos);
}


void makerand() //隨機函數
{
uint ran;
ran=rand();
display1[0]=ran/10000+0x30;
display1[1]=ran%10000/1000+0x30;
display1[2]=ran%1000/100+0x30;
display1[3]=ran%100/10+0x30;
display1[4]=ran%10+0x30;
ran=rand();
display1[5]=ran/10000+0x30;
display1[6]=ran%10000/1000+0x30;
display1[7]=ran%1000/100+0x30;
display1[8]=ran%100/10+0x30;
display1[9]=ran%10+0x30;
}


void lcd_init()
{
rd=1; //設定 並口方式
write_cmd(0x30);//這裡設定基本指令動作
delay_1ms(5);
write_cmd(0x0C);//顯示開,光游標
delay_1ms(5);
write_cmd(0x01);//清屏
delay_1ms(5);
}
main()
{
uchar i;
wela=0;
dula=0;
delay_1ms(5);
lcd_init();
lcd_pos(1,0);
i=0;
while(display2[i]!=‘\0‘)
{
write_data(display2[i]);
i++;
}
lcd_pos(2,0);
i=0;
while(display3[i]!=‘\0‘)
{
write_data(display3[i]);
i++;
}
lcd_pos(3,0);
i=0;
while(display4[i]!=‘\0‘)
{
write_data(display4[i]);
i++;
}
while(1)
{
lcd_pos(0,0);
makerand();
for(i=0;i<10;i++)
{
write_data(display1[i]);
}
}
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.