⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 atmega32对ch375的读写程序
💻 C
字号:
#include <avr/io.h>


#define  uchar  unsigned  char
#define  uint  unsigned  int


#define EN_H PORTC |= 0x40
#define EN_L PORTC &= 0xBF

#define RS_H (PORTC|= 0X80)  
#define RS_L  (PORTC&= 0X7F) 

//#define RW_H PORTC |= 0x40
#define RW_L PORTC |= 0x40
//---------------------------------------------------
//--------------------------------------------------


//;----------------------------------------------------
//;设定汉字的显示行:       第一行开始地址为00H~07H  
//;每行可以显示8个汉字:    第二行开始地址为10H~17H
//;                        第三行开始地址为08H~0FH
//;                        第四行开始地址为18H~1FH
//;-----------------------------------------------------
//-----------------------------------------------------
//主程序
//----------------------------------------------------
void LCD_portinit(void);
void initial_GLCD(void);
void command_GLCD(uchar ord);
void chkbusy_GLCD(void);
void write_GLCD(uchar dat);
void delay12(uint);


/* 延时指定毫秒时间,根据单片机主频调整,不精确 */
void	delay_1ms12( uint ms )
{
	uint	i;
	while ( ms -- ) for ( i = 10; i != 0; i -- );
//	while ( ms -- ); 
//	 mDelay1uS( );
}

void	delay12( uint ms )
{
//	uint	i;
//	while ( ms -- ) for ( i = 100; i != 0; i -- );
		while ( ms -- ); 
}

void lcd(uchar tempa1[],uchar tempa2[],uchar tempa3[],uchar  tempa4[])
{
uchar i=0;
  	uchar j;
	
    initial_GLCD();        //初始化LCD
	
   //---------------------------------------------------------

  //temp=0x00;                      //line 1
  // command_GLCD(0x80|temp);
command_GLCD(0x80);

		   for(j=0;j<8;j++)
		   { 
		   write_GLCD(tempa1[i]);
		   i++;
		   write_GLCD(tempa1[i]);
		  i++;
		 //  
		
		  // write_GLCD(0x30+j);
		  // i++;
		   }
	  i=0;

   //---------------------------------------------------------
 //   temp=0x10;                      //line2
 //  command_GLCD(temp|0x80);
//command_GLCD(0x88);
		   for(j=0;j<8;j++)
		   {
		   write_GLCD(tempa3[i]);
		   
		   i++;
		
		   write_GLCD(tempa3[i]);
		   i++;
		   }
		   i=0;
   //---------------------------------------------------------
 // temp=0x08;                       //line3
 //  command_GLCD(temp|0x80);
//command_GLCD(0x90);
		   for(j=0;j<8;j++)
		   {
		   write_GLCD(tempa2[i]);
		  
		  i++;
		
		   write_GLCD(tempa2[i]);
		   i++;
		   }
		 i=0;
   //---------------------------------------------------------
//   temp=0x18;                      //line4
 //  command_GLCD(temp|0x80);
//command_GLCD(0x98);
		   for(j=0;j<8;j++)
		   {
		   write_GLCD(tempa4[i]);
		   
		   i++;
		
		   write_GLCD(tempa4[i]);
		   i++;
		   }
		   i=0;
		   
  }

void dis_str(uchar line , uchar *pstr)
{
	uchar j;
    initial_GLCD();        //初始化LCD	
	command_GLCD(0x80);
	for(j=0;j<16&&(*pstr!='\0');j++)
	{ 
		   write_GLCD(*(pstr+j));	  
	}
}

void initial_GLCD()
{ 
command_GLCD(0x30);
delay_1ms12(2000);
command_GLCD(0x30);
delay_1ms12(2000);
command_GLCD(0x30);
delay_1ms12(2000);
//command_GLCD(0x06);    //显示器控制:游标不显示;
delay_1ms12(2000);
command_GLCD(0x01);    //清屏幕
delay_1ms12(3000);
delay_1ms12(3000);
delay_1ms12(3000);
delay_1ms12(3000);
command_GLCD(0x0c);    
delay_1ms12(2000);//进入模式设定
command_GLCD(0x02);    //清屏幕
delay_1ms12(3000);
delay_1ms12(3000);
delay_1ms12(3000);
delay_1ms12(3000);
delay_1ms12(3000);	
}

//--------------------------------------
//写命令到GLCD
//--------------------------------------
void command_GLCD(uchar ord)
{
 	 delay12(2000);
 	 EN_H; 
	 EN_L;
	 RS_L;//RS_L;
	 RW_L;
	 EN_H; 
	 PORTB = ord;
	 EN_L;	
}

//----------------------------------
//写数据到GLCD
//----------------------------------
void write_GLCD(uchar dat)
{
	 delay12(2000);	
	 EN_L;
	 RS_H;
	 RW_L;
	 EN_H; 
	 PORTB = dat;
	 EN_L;
}


     
void tishi(void)
{
	uchar   DHZTAB1[]="      CUGB      ";
	uchar   DHZTAB2[]="  STORE SYSTEM  ";
	uchar   DHZTAB3[]={"Insert U Disk ."};
	uchar   DHZTAB4[]={"..............."};
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}
void tishi1(void)
{
	uchar   DHZTAB1[]="      CUGB1     ";
	uchar   DHZTAB2[]="  STORE SYSTEM  ";
	uchar   DHZTAB3[]={"Inset U Disk .."};
	uchar   DHZTAB4[]={"..............."};
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}
void tishi2(void)
{
	uchar   DHZTAB1[]="      CUGB2     ";
	uchar   DHZTAB2[]="  STORE SYSTEM  ";
	uchar   DHZTAB3[]={"Inset U Disk .."};
	uchar   DHZTAB4[]={"..............."};
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}

void tishi3(void)
{
	uchar   DHZTAB1[]="      CUGB3     ";
	uchar   DHZTAB2[]="  STORE SYSTEM  ";
	uchar   DHZTAB3[]={"Inset U Disk .."};
	uchar   DHZTAB4[]={"..............."};
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}

void tishi4(void)
{
	uchar   DHZTAB1[]="      CUGB4     ";
	uchar   DHZTAB2[]="  STORE SYSTEM  ";
	uchar   DHZTAB3[]={"Inset U Disk .."};
	uchar   DHZTAB4[]={"..............."};
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}
void display_syatem(void)
{
	uchar   DHZTAB1[]="Name            ";
	uchar   DHZTAB2[]="Total Memory    ";
	uchar   DHZTAB3[]="Leave Memory    ";
	uchar   DHZTAB4[]="................";
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}

void Start1(void)
{
	uchar   DHZTAB1[]="      CUGB      ";
	uchar   DHZTAB2[]="Connecting .....";
	uchar   DHZTAB3[]="...             ";
	uchar   DHZTAB4[]="................";
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}
void Start2(void)
{
	uchar   DHZTAB1[]="      CUGB      ";
	uchar   DHZTAB2[]="Connecting .....";
	uchar   DHZTAB3[]="   ...          ";
	uchar   DHZTAB4[]="................";
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}
void Start3(void)
{
	uchar   DHZTAB1[]="      CUGB      ";
	uchar   DHZTAB2[]="Connecting .....";
	uchar   DHZTAB3[]="     ...        ";
	uchar   DHZTAB4[]="................";
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}
void Start4(void)
{
	uchar   DHZTAB1[]="      CUGB      ";
	uchar   DHZTAB2[]="Connecting .....";
	uchar   DHZTAB3[]="       ...      ";
	uchar   DHZTAB4[]="................";
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}
void Start5(void)
{
	uchar   DHZTAB1[]="      CUGB      ";
	uchar   DHZTAB2[]="Connecting .....";
	uchar   DHZTAB3[]="         ...    ";
	uchar   DHZTAB4[]="................";
	lcd(DHZTAB1,DHZTAB2,DHZTAB3,DHZTAB4);
}

void  Connect(void)
{
Start1();Start2();Start3();Start4();Start5();
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -