我现在用的是16脚蓝光的YM1602 我一接通电源 就只看到32个黑 {MOD}的长方体,跪求专业人士 找错 先谢谢各位i。。
电路图如下:
(原文件名:YM1602.JPG)
程序是:
#include<at89x52.h>
#include<intrins.h>
#define rs P1_7
#define rw P1_6
#define ep P1_5
unsigned char str1[]={"successful"};
void delay(unsigned char n)
{
unsigned char m;
for(n;n>0;n--)
for(m=0;m<110;m++);
}
void lcd_busy()
{
delay(10);
ep=0;
rs=0;
rw=1;
ep=1;
while(P3&0x80);
delay(5);
ep=0;
}
void lcd_write_command(unsigned char command)
{
lcd_busy();
rs=0;
rw=0;
ep=0;
P3=command;
ep=1;
delay(5);
ep=0;
}
void lcd_write_data(unsigned char dat)
{
lcd_busy();
rs=1;
rw=0;
ep=1;
P3=dat;
delay(5);
ep=0;
}
void lcd_init()
{
delay(15);
lcd_write_command(0x38);
delay(2);
lcd_busy();
lcd_write_command(0x0c);
delay(2);
lcd_busy();
lcd_write_command(0x06);
delay(2);
lcd_busy();
lcd_write_command(0x01);
delay(2);
}
void lcd_postion(unsigned char x,unsigned char y)
{
if(y<2)
{
y&=0x01;
x&=0x0f;
if(y==1)
x=x+0x40;
x=x+0x80;
lcd_write_command(x);
}
}
void display(unsigned char x,unsigned char y,unsigned char *s)
{
lcd_postion(x,y);
while((*s)!=' ')
{
lcd_write_data(*s);
s++;
}
}
void main()
{
lcd_init();
lcd_write_command(0x82);
lcd_write_data(0x30);
display(0,1,"hello");
while(1);
}
{
lcd_init();
lcd_write_command(0xc0);
lcd_write_data(0x41);
while(1);
}
不知道你这个主程序是什么意思 还是按你上面的那个写吧 我给个调过的程序给你 参考下吧
/*1-VSS 2-VDD 3-V0 4-RS 5-R/W 6-E 7-14 DB0-DB7 15-BLA 16-BLK*/
/*-----------------------------------------------
内容:通过标准程序静态显示2行字符 请调节LCD1602对比度开关 LCD1602 不保修,请注意保管好配件
------------------------------------------------*/
#include <AT89x51.h>
#include <intrins.h>
#include <math.h> //Keil library
#include <stdio.h> //Keil library
#define LCD_DB P0
sbit LCD_RS=P2^4;
sbit LCD_RW=P2^5;
sbit LCD_E=P2^6;
void LCD_init(void) /*初始化函数*/
{
delay_n10us(10);
LCD_write_command(0x38);//设置8位格式,2行,5x7
delay_n10us(10);
LCD_write_command(0x0c);//整体显示,关光标,不闪烁
delay_n10us(10);
LCD_write_command(0x06);//设定输入方式,增量不移位
delay_n10us(10);
LCD_write_command(0x01);//清除屏幕显示
delay_n10us(100); //延时清屏,延时函数,延时约n个10us
}
void LCD_write_command(uchar dat) /*写指令函数*/
{
delay_n10us(10);
LCD_RS=0; //指令
LCD_RW=0; //写入
LCD_E=1; //允许
LCD_DB=dat;
delay_n10us(10);
LCD_E=0;
delay_n10us(10);
}
void LCD_write_data(uchar dat) /*写数据函数*/
{
delay_n10us(10);
LCD_RS=1; //数据
LCD_RW=0; //写入
LCD_E=1; //允许
LCD_DB=dat;
delay_n10us(10);
LCD_E=0;
delay_n10us(10);
}
void LCD_disp_char(uchar x,uchar y,uchar dat) /*在某个屏幕位置上显示一个字符,X(0-15),y(1-2)*/
{
uchar address;
if(y==1)
address=0x80+x;
else
address=0xc0+x;
LCD_write_command(address);
LCD_write_data(dat);
}
void LCD_disp_str(uchar x,uchar y,uchar *str) /*LCD1602显示字符串函数*/
{
uchar address;
if(y==1)
address=0x80+x;
else
address=0xc0+x;
LCD_write_command(address);
while(*str!=' ')
{
LCD_write_data(*str);
str++;
}
}
void delay_n10us(uint n) /*延时函数*/
{
uint i;
for(i=n;i>0;i--)
{
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); //延时10us@12M晶振
}
}
/******************************************************************/
/* 主函数 */
/******************************************************************/
void main(void)
{
LCD_init();
LCD_disp_str(0,1,"WELCOME TO SIKO!");
delay_n10us(1000000);
LCD_write_command(0x01);
LCD_disp_str(0,1,"TEST OK!");
LCD_disp_str(0,2,"021-12345678");
while(1);
}
一周热门 更多>