LCD12864 C language driver

Publisher:bdwhscLatest update time:2016-11-16 Source: eefocusKeywords:LCD12864 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

sbit RS=P2^0;

sbit RW=P2^1;

sbit EN=P2^2;

sbit CS1=P2^3;

sbit CS2=P2^4;

sbit RST=P2^5;

#define databus P0

#define uchar unsigned char

#define startline 0xc0

#define displayon 0x3f

#define startcolumn 0x40

#define page 0xb8

void init();

void clearscreen(uchar);

void readbusy();

void writecmd(uchar);

void writedata(vol);

//fly readdata();

void main()

flying i,j;

/*-- Text: Meng --*/

/*-- Songti 12; The corresponding dot matrix under this font is: width x height = 16x16 --*/

uchar code str[][16]={

0x00,0x10,0x10,0x10,0x11,0x11,0x91,0x11,0xF9,0x15,0x13,0x11,0x10,0x10,0x10,0x00,

0x40,0x40,0x40,0x7E,0x42,0x42,0x7E,0x43,0x42,0x7E,0x42,0x42,0x7E,0x40,0x40,0x00};

heat();

CS1=0;

CS2=1;

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

{

 writecmd(i|page);

 writecmd(startcolumn);

 for(j=0;j<16;j++)

 {

  writedata(str[i][j]);

 }

}

while(1);

}

void init()

{

RST=0;

RST=1;

CS1=0;

CS2=0;

writecmd(displayon);

writecmd(startline);

clearscreen(0);

}

void clearscreen(uchar select)

{

flying i,j;

switch(select)

{

 case 0:CS1=0;CS2=0;break;

 case 1:CS1=0;CS2=1;break;

 case 2:CS1=1;CS2=0;break;

 default:CS1=1;CS2=1;

}

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

{

 writecmd(i|page);

 writecmd(startcolumn);

 for(j=0;j<64;j++)

 {

  writedata(0);

 }

}

}

void readbusy()

{

RS=0;

RW=1;

do{

 databus=0xff;

 EN=1;

 ACC=databus;

 EN=0;

}while(ACC&0X80);

 }

 

void writecmd(uchar cmd)

{

readbusy();

RS=0;

RW=0;

databus=cmd;

EN=1;

EN=0;

}

void writedata(uchar dat)

{

readbusy();

RS=1;

RW=0;

databus=that;

EN=1;

EN=0;

}

/*

fly readdata()

{

flying tempo;

readbusy();

RS=1;

RW=1;

databus=0xff;

EN=1;

temp=databus;

EN=0;

readbusy();

RS=1;

RW=1;

databus=0xff;

EN=1;

temp=databus;

EN=0;

return temp;

}

*/

LCD12864 C language driver - Xiao Meng - Huanhuake's blog

Pay special attention to the busy read subroutine. If this is not handled properly, the screen will be completely black.

I have wasted a lot of time on this. The Keil c51 compiler supports the use of the accumulator ACC in C code.

This is very good. Because I have written an assembly driver for 12864 before, and it can run normally on both simulation and actual hardware.

But after switching to C language and trying to write them one by one, I got stuck on the use of ACC.

READBUSY: CLR  RS

             SETB RW                          

BUSY_0: MOV DATABUS,#0FFH; When P0 port is used as a general input port to read data, 1 should be written first.

  SETB EN

  MOV  A,DATABUS

  CLR EN; When reading data continuously, you don’t need to write 1.

  JB   ACC.7,BUSY_0              

  RIGHT

Because MOV A, DATABUS is not easy to translate directly into C, and now the C code written after using ACC is disassembled and the assembly code is

Same, and the drive is working fine.


Keywords:LCD12864 Reference address:LCD12864 C language driver

Previous article:C51 non-blocking time-delayed water lamp
Next article:C51 Simple Electronic Clock

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号