Demo entry 6363556

py

   

Submitted by lu on May 14, 2017 at 04:57
Language: C. Code size: 1.9 kB.

#ifndef __LCD162_H
#define __LCD1602_H	

#include<reg52.h> 
#include<intrins.h>

#define uchar unsigned char
#define uint unsigned int


#define RS_CLR RS=0 
#define RS_SET RS=1

#define RW_CLR RW=0 
#define RW_SET RW=1 

#define EN_CLR EN=0
#define EN_SET EN=1

#define DataPort P0


sbit RS = P1^0;  
sbit RW = P1^1;
sbit EN = P1^2;

    

void DelayUs2x(unsigned char t)
{   
 while(--t);
}

void DelayMs(unsigned char t)
{
     
 while(t--)
 {
     DelayUs2x(245);
		DelayUs2x(245);
 }
}

 bit LCD_Check_Busy(void) 
 { 
 DataPort= 0xFF; 
 RS_CLR; 
 RW_SET; 
 EN_CLR; 
 _nop_(); 
 EN_SET;
 return (bit)(DataPort & 0x80);
 }
 
 void LCD_Write_Com(unsigned char com) 
 {  
 while(LCD_Check_Busy()); //????
 RS_CLR; 
 RW_CLR; 
 EN_SET; 
 DataPort= com; 
 _nop_(); 
 EN_CLR;
 }
 
 void LCD_Write_Data(unsigned char Data) 
 { 
 while(LCD_Check_Busy());
 RS_SET; 
 RW_CLR; 
 EN_SET; 
 DataPort= Data; 
 _nop_();
 EN_CLR;
 }
 
 void LCD_Clear(void) 
 { 
 LCD_Write_Com(0x01); 
 DelayMs(5);
 }
 
 void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s) 
 {     
 if (y == 0) 
 	{     
	 LCD_Write_Com(0x80 + x);  
 	}
 else 
 	{      
 	LCD_Write_Com(0xC0 + x);    
 	}        
 while (*s) 
 	{     
 LCD_Write_Data( *s);     
 s ++;     
 	}
 }
 
 void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data) 
 {     
 if (y == 0) 
 	{     
 	LCD_Write_Com(0x80 + x);     
 	}    
 else 
 	{     
 	LCD_Write_Com(0xC0 + x);     
 	}        
 LCD_Write_Data( Data);  
 }
 

 
 void LCD_Init(void) 
 {
   LCD_Write_Com(0x38); 
   DelayMs(5); 
   LCD_Write_Com(0x38); 
   DelayMs(5); 
   LCD_Write_Com(0x38); 
   DelayMs(5); 
   LCD_Write_Com(0x38);  
   LCD_Write_Com(0x08);   
   LCD_Write_Com(0x01);   
   LCD_Write_Com(0x06);  
   DelayMs(5); 
   LCD_Write_Com(0x0C);  
   }
 



#endif

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).