连接12864的杜邦线
连接stc的杜邦线
大佬们,看看小弟这个怎么搞呀,串口可以显示,并口试过很多次都显示不了这是我的代码:
#include <STC15F2K60S2.H>
#include "intrins.h"
#include "string.h"
#define u8 unsigned char
#define u16 unsigned int
#define LCD12864_DATA P0
sbit LCD12864_PSB = P1^3;
sbit LCD12864_RS = P1^0;
sbit LCD12864_RW = P1^1;
sbit LCD12864_EN = P1^2;
//sbit LCD12864_RST = P5^4;
void Delay1us(u16 count) //@11.0592MHz
{
while(count-- != 0)
{
_nop_();
_nop_();
_nop_();
}
}
u8 lcd12864_check_busy()//检测是否空闲
{
u8 temp;
LCD12864_DATA = 0xff;
LCD12864_RS = 0;//并行的指令
LCD12864_RW = 1;//并行读写选择信号,1为读,0为写
LCD12864_EN = 1;//使能信号,1为有效
Delay1us(1000);
temp = LCD12864_DATA;
LCD12864_EN = 0;
return temp&0x80;
}
void lcd12864_write_command(u8 cmd)//写命令
{
while(lcd12864_check_busy());
LCD12864_RS = 0;
LCD12864_RW = 0;
LCD12864_EN = 1;
Delay1us(1000);
LCD12864_DATA = cmd;
LCD12864_EN = 0;
}
void lcd12864_write_data(u8 dat)//写数据
{
while(lcd12864_check_busy());
LCD12864_RS = 1;
LCD12864_RW = 0;
LCD12864_EN = 1;
Delay1us(1000);
LCD12864_DATA = dat;
LCD12864_EN = 0;
}
void lcd12864_init()
{
LCD12864_PSB = 1;
lcd12864_write_command(0x01);//1.清屏命令
Delay1us(1000);
lcd12864_write_command(0x02);//2.位址归位
Delay1us(1000);
lcd12864_write_command(0x0C);//4.显示状态 开
Delay1us(1000);
lcd12864_write_command(0x80);//8.设定DDRAM位址
Delay1us(1000);
lcd12864_write_command(0x34);//扩充功能设定——扩充指令集动作
Delay1us(1000);
lcd12864_write_command(0x30);//扩充功能设定——基本指令集动作
Delay1us(1000);
}
void lcd12864_display_pos(u8 X , u8 Y)//选择第几行Y;第几列X(则加上X)
{
u8 addr;
if(Y == 0)
{
addr = 0x80;
}
if(Y == 1)
{
addr = 0x90;
}
if(Y == 2)
{
addr = 0x88;
}
if(Y == 3)
{
addr = 0x98;
}
addr = addr+X;
lcd12864_write_command(addr);
}
void lcd12864_show_char(u8 X , u8 Y , char sign)//显示一个字符
{
lcd12864_display_pos(X,Y);
lcd12864_write_data(sign);
}
void lcd12864_show_string(u8 X , u8 Y , char string[])//显示一个字符串
{
lcd12864_display_pos(X,Y);
while(*string != '\0')
{
lcd12864_write_data(*string++);
}
}
void main()
{
P1M1 = 0; P1M0 = 0;
//P5M0 = 0;
lcd12864_init();
lcd12864_show_string(0,0,"某某某某大学");
lcd12864_show_string(0,1,"地球科学学院");
lcd12864_show_string(0,2,"21环境01班");
lcd12864_show_char(0,3,0x02);
lcd12864_show_string(1,3,"小明呀");
lcd12864_show_char(7,3,0x02);
while(1);
}
|