51 단편기 - LCD12864 LCD

2088 단어 51 노트
lcd12864 액정스크린은 좀 복잡하고 기본적인 디스플레이만 있습니다.

#include 
#include 
#define uint  unsigned int
#define uchar unsigned char
	

sbit LCD12864_READ = P0^7;
sbit LCD12864_RS = P3^5;
sbit LCD12864_RW = P3^6;
sbit LCD12864_EN = P3^4;
sbit LCD12864_RD = P3^7;

//
void Delay_Ms(uchar z)
{
	uchar x,y;
	for(x=z;x>0;x--)
	   for(y=120;y>0;y--);
}
/*******************LCD12864LCD   *********************/
void LCD12864_busy()
{                         
	LCD12864_RS = 0;
	LCD12864_RW = 1;
	LCD12864_EN = 1;
	Delay_Ms(1);
	P0 = 0xff;
	while(1)
	{
		LCD12864_EN = 1;
		if(LCD12864_READ == 0) break;
	}
	LCD12864_EN = 0;
}
/*******LCD12864WriteCommand      ********************/
void LCD12864_Write_Cmd(unsigned char Cmd)
{	
	LCD12864_busy();
	LCD12864_RS = 0;
	LCD12864_RW = 0;
	LCD12864_EN = 0;
	Delay_Ms(1);
	P0 = Cmd;
	Delay_Ms(1);
	LCD12864_EN = 1;
	Delay_Ms(1);
	LCD12864_EN = 0; 
}
 
/**************LCD12864WriteByte      *************/
void LCD12864_Write_Date(unsigned char date)
{
	LCD12864_busy();
	LCD12864_RS = 1;	
	LCD12864_RW = 0;
	LCD12864_EN = 0;
	P0 = date;
	Delay_Ms(1);
	LCD12864_EN = 1;
	Delay_Ms(1);
	LCD12864_EN = 0;
}
// *******************
void LCD12864_init()
{
    LCD12864_RD = 1;               //       
    LCD12864_Write_Cmd(0x34);      //      
    LCD12864_Write_Cmd(0x30);      //      
    LCD12864_Write_Cmd(0x0C);      //   ,   
    LCD12864_Write_Cmd(0x01);      //  LCD     
}
//
void gotoxy(uchar x,uchar y)
{
	     if(x==1) {LCD12864_Write_Cmd(0x80+y-1);}
	else if(x==2) {LCD12864_Write_Cmd(0x90+y-1);}
	else if(x==3) {LCD12864_Write_Cmd(0x88+y-1);}
	else if(x==4) {LCD12864_Write_Cmd(0x98+y-1);}
}
//
void LCD_write_zifu(uchar *p)
{
	while(*p!=0)
	{
		LCD12864_Write_Date(*p);
		p++;
	}
}
/*****   *****************************/
void  main()
{
	LCD12864_init();
	gotoxy(1,1);
	LCD_write_zifu("LCD   ,   ");
	gotoxy(2,1);
	LCD_write_zifu("LCD   ,   ");
	gotoxy(3,1);
	LCD_write_zifu("LCD   ,   ");
	gotoxy(4,1);
	LCD_write_zifu("LCD   ,   ");
	while(1);
}

좋은 웹페이지 즐겨찾기