1602四线驱动不了,不知道什么原因
求大侠给 个1602四线驱动的代码!!我的驱动不 出来!!不知道什么原因!!
硬件没问题!!下面是我的代码
#include"1602.h"
#include"delay.h"
void main()
{
Init_Lcd();
Write_Lcd_Instruction(0x01);
Delay_Ms(5);
Write_Lcd_Instruction(0xc0);
Write_Lcd_Data(0x34);
while(1);
}
#include<reg51.h>
#include"1602.h"
#include"delay.h"
sbit E=P2^7;
sbit RS=P2^6;
sbit RW=P2^5;
void Write_Lcd_Data(unsigned char dat)
{
E=0;
RS=1;
RW=0;
P0&=0x0f; //清高四位
P0|=(dat&0xf0); //写高四位
E=1;
Delay_Ms(1);
E=0;
Delay_Ms(1);
dat<<=4;
P0&=0x0f; //清高四位
P0|=(dat&0xf0); //写低四位
E=1;
Delay_Ms(1);
E=0;
}
void Write_Lcd_Instruction(unsigned char command)
{
E=0;
RS=0;
RW=0;
P0&=0x0f; //清高四位
P0|=(command&0xf0); //写高四位
E=1;
Delay_Ms(1);
E=0;
Delay_Ms(1);
command<<=4;
P0&=0x0f; //清高四位
P0|=(command&0xf0); //写低四位
E=1;
Delay_Ms(1);
E=0;
}
void Init_Lcd()
{
Delay_Ms(15);
Write_Lcd_Instruction(0x28); //选择四线驱动的模式
Delay_Ms(5);
Write_Lcd_Instruction(0x28);
Delay_Ms(5);
Write_Lcd_Instruction(0x28);
Delay_Ms(5);
Write_Lcd_Instruction(0x28);
Write_Lcd_Instruction(0x08);
Write_Lcd_Instruction(0x01);
Write_Lcd_Instruction(0x04);
Write_Lcd_Instruction(0x0c);
}
可以参考哈小弟写的
http://www.amobbs.com/forum.php?mod=viewthread&tid=5503804&page=1
页:
[1]