找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

lcd1602 C程序及lcd1602中文资料(调试过,有图)

[复制链接]
admin 发表于 2012-9-2 10:49:34 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
单片机型号:AVR ATMEGA16



显示:
5_3_47963b80f92077f.jpg


#include <iom16v.h>
#include <macros.h>

#define RS_0 PORTD &= ~(1 << PD3)
#define RS_1 PORTD |= (1 << PD3)

#define RW_0 PORTD &= ~(1 << PD4)
#define RW_1 PORTD |= (1 << PD4)

#define EN_0 PORTD &= ~(1 << PD6)
#define EN_1 PORTD |= (1 << PD6)

//微秒级延时程序晶振8MHZ
void delay_us(int time)
{
do
{
time--;
}
while (time>1);
}

//毫秒级延时程序晶振8MHZ
void delay_ms(unsigned int time)
{
while(time!=0)
{
delay_us(1000);
time--;
}
}

/*显示屏命令写入函数*/
void LCD_write_com(unsigned char com)
{

RS_0;
RW_0;
PORTB = com;
EN_1;
delay_us(20);
EN_0;
}

/*显示屏命令写入函数*/
void LCD_write_data(unsigned char data) {

RS_1;
RW_0;
PORTB = data;
EN_1;
delay_us(200);
EN_0;
}

/*显示屏清空显示*/
void LCD_clear(void) {

LCD_write_com(0x01);
delay_ms(5);
}

/*显示屏字符串写入函数*/
void LCD_write_str(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) {

DDRB = 0xFF; /*I/O口方向设置*/
DDRD |= (1 << PD3) | (1 << PD4) | (1 << PD6);
LCD_write_com(0x38); /*显示模式设置*/
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);

LCD_write_com(0x08); /*显示关闭*/
LCD_write_com(0x01); /*显示清屏*/
LCD_write_com(0x06); /*显示光标移动设置*/
delay_ms(5);
LCD_write_com(0x0C); /*显示开及光标设置*/
}



void main(void) {

unsigned char i;
unsigned char *p;

PORTA = 0xFF; /*打开上拉*/
DDRA = 0x00; /*方向输入*/
PORTB = 0xFF; /*电平设置*/
DDRB = 0xFF; /*方向输出*/
PORTC = 0x7F;
DDRC = 0x80;
PORTD = 0xFF;
DDRD = 0x00;

delay_ms(100);
LCD_init();

while (1)
{
i = 1;
p = "yixiangongren";
//LCD_clear();
LCD_write_str(1,0,"www.eehome.cn");
delay_ms(50);

while (*p)
{
LCD_write_char(i,1,*p);
i ++;
p ++;
//delay_ms(50);
}
delay_ms(500);
}
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 17:20 , Processed in 0.056891 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表