古詩詞大全網 - 成語經典 - Proteus 12864液晶程序

Proteus 12864液晶程序

我不知道妳用的是哪壹種12864,我用的是沒有CS1和CS2的

#include <reg52.h>

#include <stdio.h>

#define uint unsigned int

#define uchar unsigned char

#define comm 0

#define dat 1

sbit RS = P3^0; //H=data; L="command";

sbit RW = P3^1; //H=read; L="write";

sbit E = P3^2; //input enable;

sbit PSB= P3^3; //H=並口; L="串口";

sbit RST= P3^5; //Reset Signal 低電平有效

sbit busy=P0^7; //lcd busy bit

void wr_lcd (uchar dat_comm,uchar content);

void chk_busy (void);

uchar code tab[]={

"需要顯示的字"

};

void init_lcd (void)

{

RST = 1;

PSB = 1;

wr_lcd(comm,0x30); /*30---基本指令動作*/

wr_lcd(comm,0x01); /*清屏,地址指針指向00H*/

wr_lcd(comm,0x06); /*光標的移動方向*/

wr_lcd(comm,0x0c); /*開顯示,關遊標*/

}

void clrram(void)

{

wr_lcd(comm,0x30);

wr_lcd(comm,0x01);

}

void wr_lcd(uchar dat_comm,uchar content)

{

chk_busy ();

if(dat_comm)

{

RS = 1; //data

RW = 0; //write

}

else

{

RS = 0; //command

RW = 0; //write

}

P0=content; //output data or comm

E = 1;

;

E = 0;

}

void chk_busy(void)

{

P0 = 0xff;

RS = 0;

RW = 1;

E = 1;

while(busy==1);

E = 0;

}

void main()

{

int i;

SP=0x5f;

init_lcd();

wr_lcd(comm,0x30);

wr_lcd(comm,0x80);

for(i=0;i<6;i++)

{

wr_lcd(dat,tab[i]);

}

while(1);

}