GLCD interface with 8051 C code

GLCD ROUTINE :

#include <REG51.h>

#include <math.h>

#include “font.h”

#include “ds1820.c”

#include <string.h>

// pin allogation for Display (samsung)

//=====================================

// p0 for data port sbit Rs = P2^7; sbit Rw = P2^6 ;                                                sbit En =P2^5;                                                 sbit Cs1= P3^3; sbit Cs2= P3^4; sbit Rst= P3^5; // Declaration unsigned char aa[15],gp,gd; unsigned char i,Tmp,Crc,V,send_data,j,row,column,dr,ddr,count,k,pr;  unsigned int t,te,fa; unsigned char MyTemp[9]; bit g; // function for lcd void writecommand(void); void writedata(void); void cleardisplay(void); void clearram();

void cleardisplay(void); void display_str(void);

void display_graph(void); void display_point(void); void display_graph_xy(void); void main(void) {

for(t=0;t<50;t++);  //delay for 1 ms

Cs2=1; send_data=0×3F; writecommand(); clearram(); cleardisplay(); // to display char  display_graph_xy(); dr = 0; strcpy(aa,”TEMP\0″); display_str(); display_graph(); gp=1; gd=1; while (1)

{

ReadTemp(&MyTemp[0]);

Tmp = MyTemp[0] & 1 ; if (Tmp == 1)

{

MyTemp[0]=MyTemp[0]-1;

}

t =  MyTemp[0]  +  (MyTemp[1] * 256); t=t*50;

t=t-25; te= MyTemp[7]- MyTemp[6]; te=te * 100; te=te/ MyTemp[7]; t=t+te;

t=t/10; te=t; k = t / 100;

aa[0] = k + 48;      t = t % 100;            k = t / 10;                aa[1] = k + 48;       t = t % 10;              aa[3] = t + 48;

aa[2] = ‘.’; aa[4]=0×80; aa[5]=’C'; aa[6] = ‘\0′;

dr = 2;

display_str(); // faren

fa=te * 18; fa=fa/10; fa=fa+320; t=fa; k = t / 1000;

aa[0] = k + 48;      t = t % 1000;

k = t / 100;            aa[1] = k + 48;       t = t % 100;

k=t/10;

aa[2] = k + 48;

aa[3] = ‘.’; t=t%10;

aa[4] = t + 48;

aa[5]=0×80; aa[6]=’F'; aa[7] = ‘\0′;

dr = 4;

display_str();

DelayMs(500); gd++; if(gd==2) {

display_point(); gd=0; }

if (gp==64) {

display_graph(); gp=1;

}

}

}

void writecommand(void) {

Rs=0;

P0 = send_data;

for(t=0;t<500;t++);  //delay for 5 ms

void writedata(void) {

Rs=1;

P0 = send_data; for(t=0;t<500;t++);  //delay for 5 ms En=0;

En=1;

En=0;

}

void cleardisplay(void) {

for(j=0;j<8;j++) {

send_data = 192;

writecommand();                 send_data = 0xB8 + j;          writecommand();                  send_data = 0×40;                writecommand();                    for(i=0;i<64;i++)                  {

send_data = 0;

writedata();

}

}

}

void clearram(void) {

for(j=0;j<8;j++) {

send_data = 192;                writecommand();                  send_data = 0xB8 + j;          writecommand();                  send_data = 0×40;       writecommand();

for(i=0;i<64;i++) {

send_data = 0;     writedata();

}

}

for(j=0;j<8;j++) {

send_data = 192;

writecommand();     send_data = 0xB8 + j;      writecommand();                  send_data = 0×40;                writecommand();

for(i=0;i<64;i++) {

send_data = 255;

writedata();

}

}

}




void display_str() {

ddr=0; for(i=0;aa[i]!=’\0′;i++)

{

send_data = 0xC0;         writecommand();         send_data = 0xB8 + dr;         writecommand();         k = ddr * 6;

k = ddr – 60;         send_data = 0×40 + k;

writecommand(); }

if (g==1)

{

Cs1=0;

Cs2=1;

Cs1=1;

Cs2=0;

send_data = 0xC0;

writecommand();           send_data = 0xB8 + dr;           writecommand();           k = ddr * 6;           send_data = 0×40 + k;           writecommand();

}

j=aa[i]-32; for(k=0;k<5;k++) {

send_data=font[j][k]; writedata();

}

send_data=0; writedata(); ddr++;

}

g=0;

}

void display_graph(void) {

Cs2=1;

Cs1=0; for(j=0;j<8;j++) {

send_data = 192;

writecommand();                 send_data = 0xB8 + j;          writecommand();                  send_data = 0×40;                    writecommand();

for(i=0;i<64;i++)                  {

send_data = 0;

writedata();

}

}

for (dr=0;dr<7;dr++) {

send_data = 0xC0;     writecommand();     send_data = 0xB8 + dr;     writecommand();     send_data = 0×40;     writecommand();

if (dr==6) {

send_data=31;

}

else {

send_data=255;

}

writedata();

}

for(dr=1;dr<64;dr++) {

send_data=16; writedata();

}

strcpy(aa,”   Time\0″); dr=7;

g=1;

display_str();

}

void display_point() {

send_data = 0xC0;

writecommand(); t=te-250;

t=t/5; te=dp[t][1]; send_data = dp[t][0]; writecommand(); send_data = 0×40 +gp; writecommand(); send_data=te; writedata(); gp++;

}

void display_graph_xy(void) {

send_data = 192;

writecommand();                 send_data = 0xB8 +1;          writecommand();                  send_data = 0×72;                writecommand();

send_data=’T';

j=send_data-32; for(k=0;k<5;k++) {

send_data=font[j][k]; writedata();

}

send_data = 192;

writecommand();                 send_data = 0xB8 +2;          writecommand();                  send_data = 0×72;                writecommand();

send_data=’e'; j=send_data-32; for(k=0;k<5;k++) {

send_data=font[j][k]; writedata();

}

send_data = 192;

writecommand();                 send_data = 0xB8 +3;          writecommand();                  send_data = 0×72;                writecommand();

send_data=’m'; j=send_data-32; for(k=0;k<5;k++) {

send_data=font[j][k]; writedata();

}

send_data = 192;

writecommand();                 send_data = 0xB8 +4;          writecommand();                  send_data = 0×72;                writecommand();

send_data=’p'; j=send_data-32; for(k=0;k<5;k++) {

send_data=font[j][k]; writedata();

}

}

DS1820 ROUTINE :

sbit DQ  =  P2^4;                  // connect with DS1820 Data pin extern void DelayMs(unsigned int count); extern void DelayUs(int us); extern bit ResetDS1820(void); extern bit ReadBit(void); extern void WriteBit(bit Dbit); extern unsigned char ReadByte(void); extern void WriteByte(char Dout); extern void ReadTemp(unsigned char * buff);

//—————————————

// Delay mS function

//—————————————

void DelayMs(unsigned int count)  {  // mSec Delay 11.0592 Mhz      unsigned int i;                                                                                               // Keil v7.5a      while(count) {         i = 115;

while(i>0) i–;

count–;

}

}

//—————————————-

// DELAY at 11.0592MHz crystal.

// Calling the routine takes about 22us, and then

// each count takes another 17us.

// test with KEIL C51 V7.5

//—————————————- void DelayUs(int us) {

int i; for (i=0; i<us; i++);

}

//—————————————-

// Reset DS1820

//—————————————- bit ResetDS1820(void) {

bit presence; DQ = 0;         //pull DQ line low DelayUs(29); // leave it low for about 490us DQ = 1;     // allow line to return high DelayUs(3);  // wait for presence 55 uS presence = DQ;         // get presence signal

DelayUs(25); // wait for end of timeslot 316 uS  return(presence); // presence signal returned

}              // 0=presence, 1 = no part //—————————————–

// Read one bit from DS1820

//—————————————– bit ReadBit(void) {

unsigned char i=0; DQ = 0;               // pull DQ low to start timeslot DQ=1;

for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ); // return value of DQ line

}

//—————————————–

// Write one bit to DS1820

//—————————————– void WriteBit(bit Dbit) {

unsigned char i=0;

DQ=0;

DQ = Dbit ? 1:0;

DelayUs(5);                                          // delay about 39 uS

DQ = 1;

}

//—————————————–

// Read 1 byte from DS1820

//—————————————– unsigned char ReadByte(void) {

unsigned char i;

unsigned char Din = 0; for (i=0;i<8;i++) {

Din|=ReadBit()? 0×01<<i:Din;

DelayUs(6);

}

return(Din);

}

//—————————————–

// Write 1 byte

//—————————————– void WriteByte(unsigned char Dout) {

unsigned char i; for (i=0; i<8; i++) // writes byte, one bit at a time {

WriteBit((bit)(Dout & 0×1));                                             // write bit in temp into

Dout = Dout >> 1;

}

DelayUs(5);

}

//—————————————–

// Read temperature

//—————————————– void ReadTemp(unsigned char * buff) {

unsigned char n; EA=0;// disable all interrupt

ResetDS1820();

WriteByte(0xcc);  // skip ROM

WriteByte(0×44);  // perform temperature conversion     while (ReadByte()==0xff); // wait for conversion complete     ResetDS1820();

WriteByte(0xcc);  // skip ROM

WriteByte(0xbe);  // read the result

for (n=0; n<9; n++)     // read 9 bytes but, use only one byte     {        buff[n]=ReadByte();  // read DS1820     }

EA=1;

}

8051 interface with GLCD

Tags: , , , , , , , , , , ,

8 Responses to “GLCD interface with 8051 C code”

  1. Kicker Says:

    Interesting, did you plan to continue this article?
    Kicker

  2. Piera Says:

    This post some good! Keep up the remarkable work!

  3. Ciecherella Says:

    Super post! I liked Waiting for new records

  4. exchangecards Says:

    Yes I too saw something similar already. Though to esteem very interestingly

  5. Shanta Mariya Says:

    Very nice text. I think it is useful for most clients. Thank you for this ideas.

  6. Drennadeada Says:

    There are many differents mind. But I thk auther is right

  7. NimSwaks Says:

    I Remarkably

  8. NimSwaks Says:

    Very liked this post

Leave a Reply