欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AVR单片机4bit字符LCD1602显示

程序员文章站 2022-06-09 10:50:24
...

AVR单片机4bit字符LCD1602显示
main.c文件里面

#include<iom16v.h>
#include"LCD4BIT.h"
unsigned char str1[] = "0123456789ABCDEF" ;
unsigned char str2[] = "I LOVE AVR MCU!!";
void main (void)
{unsigned char i ;
DDRC=0xff;
LCD init() ;
while (1)
{
LCD_display_String(0,0,str1) ;
LCD_display_String(l,0, str2) ;
}
}

LCD4BIT_DRIVER.C文件

#include "LCD4BIT.h"
void LCD_sent_cmd (char cmd)
{
LCD_PORT = (cmd&0xF0) | LCD_EN;
LCD_PORT = cmd&0xF0;
LCD_PORT = ( (cmd<<4) &0xF0) |LCD_EN;
LCD_PORT =(cmd<<4) δ0xF0;
delayms (3) ;
}

void LCD_sent_data (unsigned char dat)
{
LCD_PORT = ((dat&0xF0) |LCD_EN|TCD_RS) ;
LCD_PORT = ( (dat&0xF0)|LCD_RS) ;
LCD_PORT = ( ( (dat<<4) &0xF0) |LCD_EN|LCD_RS) ;
LCD_PORT = ( ( (dat<<4) &0xF0) | LCD_RS) ;
delayms(3) ;
}

void LCD_display_String (unsigned char line, unsigned char row, unsigned char *s)
{
   unsigned char temp;
if (line==0) temp=0x80|row; //在0行|row列显示.
else
temp=0xc0+row; //在1行+row列显示
LCD_sent_cmd (temp) ;
while(*s)
{ LCD_sent_daLa(*s++) ;
dc1ayms(3) 
}
}

void LCD_reset (void)
{
dclayms(20) ;
LCD_PORT= 0x30+LCD_EN;
LCD_PORT =0X30;
delayms(10) ;
LCD_PORT = 0x30+LCD_EN;
LCD PORT=0x30;
delayms(3) ;
LCD_PORT = 0x30+LCD_EN;
LCD PORT=0x30;
delayms(3) ;
LCD_PORT = 0x20+LCD_EN;
LCD PORT=0x20;
delayms(3) ;
}

void LCD_init(void)
{
LCD_rosct();//复位
ICID_sent_cmd(0x02);
LCD_sent_cmd (0X28) ;// 4-bit模式, 2行,5x1分辨率.
LCD_sent_cmd (0x0C) ;//无光标,无闪烁
LCD_sent_cmd(0x06) ;//显示地址自增,无移位.
}

void delay(unsigned char L)
{
unsigned char i;
for(i-t;i;i ) ;
}

void de1ayms (unsigned char t)
{
unsigned int j ;
unsigned char i;
for(i-0;i<t;i++)
for(j=0; j<1140; j++) ;
}

下面为lcd4bit.h文件
AVR单片机4bit字符LCD1602显示

相关标签: avr 单片机