1602液晶
不显示怎么回事啊求指点#include<avr/io.h>
#include <util/delay.h>
#define uchar unsigned char
#define uintunsigned int
#define uchar unsigned char
#define uintunsigned int
#define RS_0PORTC &= ~(1 << PC0)
#define RS_1PORTC |= (1 << PC0)
#define RS_OUTDDRC |= (1 << PC0)
#define RW_0PORTC &= ~(1 << PC1)
#define RW_1PORTC |= (1 << PC1)
#define RW_OUTDDRC |= (1 << PC1)
#define EN_0PORTC &= ~(1 << PC2)
#define EN_1PORTC |= (1 << PC2)
#define EN_OUTDDRC |= (1 << PC2)
#define P6_OUTDDRC |= (1 << PC6)
#define P6_1PORTC |= (1 << PC6)
unsigned char table1="0123456789876543";
unsigned char table2="9876543210123456";
void lcd_cmd(uchar cmd)
{
RS_0;
RW_0;
EN_0;
//RS_0;
RW_0;
PORTA=cmd;
_delay_ms(1);
EN_1;
_delay_ms(1);
EN_0;
}
void lcd_dat(uchar dat)
{
RS_1;
RW_0;
EN_0;
RS_1;
//RW_0;
PORTA=dat;
_delay_ms(1);
EN_1;
_delay_ms(1);
EN_0;
}
void int_lcd(void)
{
DDRA=0XFF;
PORTA=0Xff;
P6_OUT;
P6_1;
RS_OUT;
RW_OUT;
EN_OUT;
_delay_ms(20);
lcd_cmd(0x38);
_delay_ms(5);
lcd_cmd(0x38);
_delay_ms(10);
lcd_cmd(0x38);
lcd_cmd(0x38);
_delay_ms(10);
lcd_cmd(0x0c);
_delay_ms(10);
lcd_cmd(0x06);
_delay_ms(10);
lcd_cmd(0x01);
_delay_ms(10);
//lcd_cmd(0x0F);
}
void main(void)
{
uchar i;
int_lcd();
lcd_cmd(0x80);
for(i=0;i<16;i++)
{
lcd_dat(table1);
_delay_ms(2);
}
lcd_cmd(0x80+40);
for(i=0;i<16;i++)
{
lcd_dat(table2);
_delay_ms(2);
}
while(1);
}
这个图。。。。。。 #include"lcd.h"
//#include"key.h"
#include"control.h"
#include"instr_code.h"
/***************************************
函数功能:595 SPI写数据
传入参数:udata
芯片型号:为595,ATMEGE8
时钟 :8M
****************************************/
void write_595(U8 udata)
{U8 i;
CS595_L;
OE595_H;
for(i=0;i<8;i++)
{SCK595_L;
if(udata&0x80)MOSI595_H
else MOSI595_L;
SCK595_H;
udata<<=1;
}
OE595_L;
CS595_H;
}
/***************************************
函数功能:LCD_1602 写命令
传入参数:udata
芯片型号:为595,ATMEGE8
时钟 :8M
****************************************/
void writecom_lcd(U8 udata)
{ delay_ms(1);
LCDRS_L;
LCDEN_H;
write_595(udata);
LCDEN_L;
write_595(0);
}
/***************************************
函数功能:LCD_1602 写数据
传入参数:udata
芯片型号:为595,ATMEGE8
时钟 :8M
****************************************/
void writedata_lcd(U8 udata)
{ delay_ms(1);
LCDRS_H;
LCDEN_H;
write_595(udata);
LCDEN_L;
write_595(0);
}
/***************************************
函数功能:LCD_1602 写字符串
传入参数:udata
芯片型号:为595,ATMEGE8
时钟 :8M
****************************************/
void lcd_wrstring(U8 adder,U8 *s)
{ U8 n;
writecom_lcd(adder);
for(n=0;*s!='\0';n++)
{writedata_lcd(*s);
delay_ms(5);
s++;}
}
/***************************************
函数功能:LCDInt
传入参数:
芯片型号:ATMEGE8
时钟 :8M
****************************************/
void lcd_1602Int(void)
{ U8 i=15;
CS_in;
OE_in;
SCK_in;
MOSI_in;
LCDRS_in;
LCDEN_in;
LCD_ledH;
// lcdled_biao=1;
delay_ms(10);
writecom_lcd(0x38);//16*2显示,5*7点阵,8位数据
delay_ms(10);
writecom_lcd(0x80); //显示开,关光标
delay_ms(10);
writecom_lcd(0x06);//移动光标
delay_ms(10);
writecom_lcd(0x01);//清除LCD的显示内容
delay_ms(10);
lcd_wrstring(0x90,"Control System");
lcd_wrstring(0xd3,"Welcome!");
writecom_lcd(0x0c);//显示开,关光标
while(i)
{writecom_lcd(0x18);
delay_ms(200);
delay_ms(200);
i--;
}
delay_ms(200);
writecom_lcd(0x01);//清除LCD的显示内容
}
自己对一下
tanguicaicai 发表于 2013-5-25 17:59 static/image/common/back.gif
#include"lcd.h"
//#include"key.h"
#include"control.h"
不大明白 帮忙看看我写的不胜感激 你的初始化成功不,能显示光标不? tanguicaicai 发表于 2013-5-27 09:22 static/image/common/back.gif
你的初始化成功不,能显示光标不?
不能不知道咋回事 求指点 笑。h 发表于 2013-5-28 16:18 static/image/common/back.gif
不能不知道咋回事 求指点
先看硬件连接有没有问题?然后看每一个IO的输出电平有没有问题,比如 RS_0 你去量量是不 是真的是为0 ,都量一下 都没问题,那就是你的写函数有问题 谢谢。。。。。
页:
[1]