Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/15/04 09:17
Read: times


 
#83123 - c code for lcd
Responding to: ???'s previous message
#include <89c51rd2.H>
#include <stdio.h>
#include <string.h>
#define DISPLAY_ON 0XC
#define RETURN_HOME 0X2
#define FUNCTION_SET 0X38
#define ENTRY_MODE1 0X6
#define ENTRY_MODE2 0X6
#define CLEAR_DISPLAY 0X1
#define DISPLAY_OFF 0X8


sbit rs=P3^0;
sbit rw=P3^1;
sbit ena=P3^2;


void msec(int delay)
{
int i,j;
for (j=0;j<delay;j++)
for (i=0;i<500;i++);
}

void lcd_cmdwr(unsigned char zz)
{
rs=0;
msec(1);
ena=1;
msec(2);
P2=zz;
msec(2);
ena=0;
msec(5);
}

void initialize(void)
{
msec(15);
rs=0;
rw=0;
msec(1);
P2=0;
lcd_cmdwr(FUNCTION_SET);
lcd_cmdwr(FUNCTION_SET);
lcd_cmdwr(FUNCTION_SET);
lcd_cmdwr(CLEAR_DISPLAY);
lcd_cmdwr(DISPLAY_OFF);
lcd_cmdwr(DISPLAY_ON);
lcd_cmdwr(CLEAR_DISPLAY);
lcd_cmdwr(ENTRY_MODE1);
lcd_cmdwr(CLEAR_DISPLAY);
lcd_cmdwr(RETURN_HOME);
}

void lcd_dwr(unsigned char zz)
{
rs=1;
msec(1);
ena=1;
msec(2);
P2=zz;
ena=0;
msec(5);
}


void main(void)
{

unsigned char a1[]={"0123456789"};
unsigned char a2[]={"0123456789"};
int i;
initialize();

for(i=0;i<strlen(a1);i++)
{msec(10);lcd_dwr(a1[i]);}

for(i=0;i<(64-strlen(a1));i++)
lcd_dwr(' ');

for(i=0;i<strlen(a2);i++)
{msec(10);lcd_dwr(a2[i]);}

/* lcd_cmdwr(CLEAR_DISPLAY);}*/





}


List of 22 messages in thread
TopicAuthorDate
Help LCD--89C51 using KEIL            01/01/70 00:00      
   RE            01/01/70 00:00      
   Keil?            01/01/70 00:00      
      Keil App Notes            01/01/70 00:00      
   Assembler programmer learning C?            01/01/70 00:00      
   So what happened to the USB, then?            01/01/70 00:00      
   The wanted code...            01/01/70 00:00      
      code            01/01/70 00:00      
         Tips and Tricks.....Andy            01/01/70 00:00      
            volatile.            01/01/70 00:00      
               Not so volatile ?            01/01/70 00:00      
                  optimiser            01/01/70 00:00      
                     Volatile warning?            01/01/70 00:00      
                        not here            01/01/70 00:00      
                        re: volatile            01/01/70 00:00      
                           volatile            01/01/70 00:00      
      Another comment - symbolic names            01/01/70 00:00      
   c code for lcd            01/01/70 00:00      
      code            01/01/70 00:00      
         symbolic Port names            01/01/70 00:00      
   There's Gratitude for you! :-(            01/01/70 00:00      
   A better method in C            01/01/70 00:00      

Back to Subject List