1602显示屏的使用

1602是一款简单实用的显示设备。


整个工程下载:http://download.csdn.net/detail/c1194758555/9596486

电路连接:

                                                                                        


使用的头文件:

#ifndef _1602_H_
#define _1602_H_

#define SysDate P4
#define RS      P55
#define RW      P54
#define E       P53


void init_1602(void);                                       /*初始化显示屏*/
unsigned char buy(void);                                    /*是否可以读写数据*/
void write_date(char date);                                 /*写数据*/
void write_cmd(unsigned char cmd);                          /*写命令*/ 
void setxy(unsigned char x,unsigned char y);                /*设置字体显示的位置*/
void write_string(unsigned char x,unsigned char y,char *s); /*显示字符串*/


#endif

1602的初始化,命令,数据的写入,显示。

#include <STC15W4K58S4.h>
#include "1602.h"

  /*
  ***********************************************
  *   RS:命令数据选择端,低电平指令,高电平数据    *
  *   RW:读写选择,低电平写,高电平读             *
  *   E :使能信号,1禁止,0允许                   *
  ***********************************************
	*/

unsigned char buy(void)   //检查数据高位是否为0,是否可读写
{
	unsigned char temp;
	
	SysDate = 0xff;
	RS = 0;
	RW = 1;
	
	temp = SysDate;
	E = 0;
	E = 1;
	
	if(temp & 0x80)
		return 0;
	
	return 1;
}

void write_cmd(unsigned char cmd) //写命令
{
	while(!buy());
	
	RS = 0;
	RW = 0;
	SysDate = cmd;
	E = 0;
	E = 1;
}

void write_date(char date)     //写数据
{
	while(!buy());
	
	RS = 1;
	RW = 0;
	SysDate = date;
	E = 0;
	E = 1;
}

void setxy(unsigned char x,unsigned char y) //获得坐标
{
	unsigned char ardd;
	
	if(!y)
		ardd = x;
	else
		ardd = 0x40 + x;
	write_cmd(ardd | 0x80);
}

void init_1602(void)    //初始化屏幕
{
	write_cmd(0x38);
	write_cmd(0x0c);
	write_cmd(0x06);
	write_cmd(0x01);
}

void write_string(unsigned char x,unsigned char y,char *s) //显示数据
{
	setxy(x,y);
	while(*s)
	{
		write_date(*s++);
	}
}


mian函数:

#include <STC15W4K58S4.h>
#include "1602.h"

int main()
{
	P4M0 = 0x00;
	P4M1 = 0x00;
	
	init_1602();
	
	while(1)
	{
	  write_string(0,0,"hello word!");
	}
}


  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值