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

📄 1602b_lcd.c

📁 1302+lcd时钟显示C语言程序
💻 C
字号:
#include <iom16v.h>
#include <macros.h>
#include "delay.c"
#define LCD_EN_PORT    PORTC
#define LCD_RS_PORT    PORTC
#define LCD_DATA_PORT  PORTC
#define LCD_DATA_DDR   DDRC

#define LCD_EN         BIT(PC3)   //portC5         out
#define LCD_RS         BIT(PC2)   //portC4         out
#define LCD_DATA       0xF0  //portC7/6/5/4   out
unsigned  data_temp;


/*-----------------------------------------------------------------------
LCD_write_char    : 英文字符串显示函数

输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置,X:0-15,Y:0-1
                    LCD第一行显示寄存器地址:0X80-0X8F
                    LCD第一行显示寄存器地址:0XC0-0XCF

编写日期          :2003-11-19 
最后修改日期      :2004-8-19 	
-----------------------------------------------------------------------*/	
/*---------写高4bit到LCD----*/
void LCD_Write_half_char(void)
  {
   	 PORTC &= 0x0F; //portc0~3=0 
   	 PORTC |= (data_temp<<4)&0xF0; //send LOW 4bit
	 PORTC |= LCD_EN; //EN端产生一个由低电平变高电平,写LCD
	 delay(2);
     PORTC &= ~LCD_EN; //EN端产生一个由高电平变低电平,写LCD
   	 PORTC &= 0X0F; 
	 delay(2); 
   }

void LCD_write_char(uint command,uint data)
  {  
    PORTC &= ~LCD_EN;     
    if (command == 0)
   	PORTC &=~LCD_RS;   //RS=0  发送命令
	else
    PORTC |=LCD_RS;    //RS=1  发送数据
	
    data_temp = data;
	data_temp=data_temp >>4;
    LCD_Write_half_char();
	data_temp = data;
    LCD_Write_half_char();
	delay(1);
  }


/*-----------------------------------------------------------------------
LCD_set_xy        : 设置LCD显示的起始位置

输入参数:x、y    : 显示字符串的位置,X:0-15,Y:0-1
                    LCD第一行显示寄存器地址:0X80-0X8F
                    LCD第一行显示寄存器地址:0XC0-0XCF

编写日期          :2004-8-19 
最后修改日期      :2004-8-19 		
-----------------------------------------------------------------------*/

void LCD_set_xy( unsigned char address )
  { 
       LCD_write_char(0,address);
  }  

/*-----------------------------------------------------------------------
LCD_write_string  : 英文字符串显示函数

输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置

编写日期          :2004-8-19 
最后修改日期      :2004-8-19 		
-----------------------------------------------------------------------*/
/*void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
  {
    LCD_set_xy( X, Y );
    
    while (*s) 
      {
        LCD_write_char(1,*s);
	s ++;
      }
  }*/
  void LCD_write_string(unsigned char address,unsigned char *s)
  {
   LCD_set_xy(address);
    while (*s) 
      {
        LCD_write_char(1,*s);
	s ++;
      }
  }
  
/*---------------------------------------------------------
显示单个字符函数
输入参数:data    :'w'或字符型数据0x37(数字7的ascii码)
          X、Y    : 显示字符串的位置
---------------------------------------------------------*/
/*void LCD_write_onechar(unsigned char X,unsigned char Y,unsigned char data)
{
 LCD_set_xy( X, Y );
 LCD_write_char( 1, data );

} */

void LCD_write_onechar(unsigned char address,unsigned char data)
{
 LCD_set_xy( address );
 LCD_write_char( 1, data );
}


void LCD_init(void)
{
  LCD_write_char(0,0x38);         
  delay(1);  
  LCD_write_char(0,0x02);                
  delay(1);  
  LCD_write_char(0,0x28);     // 显示模式设置(不检测忙信号)  
  delay(1);   
  LCD_write_char(0,0x08);   // 显示关闭  
  delay(1);  
  LCD_write_char(0,0x01);    // 显示清屏  
  delay(1);  
  LCD_write_char(0,0x06);   // 显示光标移动设置  
  delay(1);  
  LCD_write_char(0,0x0c);   // 显示开及光标设置  
  delay(5);  
}

⌨️ 快捷键说明

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