#循循渐进学51单片机#指针基础与1602液晶的初步认识#not.11

1、把本节课的指针相关内容,反复学习3到5遍,彻底弄懂指针是怎么回事,即使是死记硬背也要记住,等到后边用的时候可以实现顿悟。学会指针,就是突破了C语言的一道壁垒。

#循循渐进学51单片机#指针基础与1602液晶的初步认识#not.11_第1张图片#循循渐进学51单片机#指针基础与1602液晶的初步认识#not.11_第2张图片

#循循渐进学51单片机#指针基础与1602液晶的初步认识#not.11_第3张图片#循循渐进学51单片机#指针基础与1602液晶的初步认识#not.11_第4张图片#循循渐进学51单片机#指针基础与1602液晶的初步认识#not.11_第5张图片

2,1602所有的指令功能都应用一遍,能够灵活使用1602液晶显示任意字符串。

#循循渐进学51单片机#指针基础与1602液晶的初步认识#not.11_第6张图片

#include 

#define LCD1602_DB  P0
sbit LCD1602_RS = P1^0;
sbit LCD1602_RW = P1^1;
sbit LCD1602_E  = P1^5;

void InitLcd1602();
void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str);

void main()
{
    unsigned char str[] = "Kingst Studio";

    InitLcd1602();
    LcdShowStr(2, 0, str);
    LcdShowStr(0, 1, "Welcome to KST51");
    while (1);
}
void LcdWaitReady()
{
  unsigned char sta;
  LCD1602_DB = 0xff;
	LCD1602_RS = 0;
	LCD1602_RW = 1;
	do{
	 LCD1602_E = 1;
	sta = LCD1602_DB; 	
		LCD1602_E = 0;
	}while (sta & 0x80); 
}
void LcdWriteCmd(unsigned char cmd)
{
    LcdWaitReady();
    LCD1602_RS = 0;
    LCD1602_RW = 0;
    LCD1602_DB = cmd;
    LCD1602_E  = 1;
    LCD1602_E  = 0;
}
void LcdWriteDat(unsigned char dat)
{
    LcdWaitReady();
    LCD1602_RS = 1;
    LCD1602_RW = 0;
    LCD1602_DB = dat;
    LCD1602_E  = 1;
    LCD1602_E  = 0;
}

void LcdSetCursor(unsigned char x, unsigned char y)
{
  unsigned char addr;
	if(y == 0)
    addr = 0x00 + x;
	else
		addr = 0x40 + x;
	LcdWriteCmd(addr | 0x80); 
}
void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str)
{
LcdSetCursor(x, y);
	while (*str != '\0')
		LcdWriteDat(*str++);
}
void InitLcd1602()
{
    LcdWriteCmd(0x38);  
    LcdWriteCmd(0x0C); 
    LcdWriteCmd(0x06);  
    LcdWriteCmd(0x01);  
}


3、尝试通过串口调试助手下发字符在1602液晶上显示出来。

你可能感兴趣的:(51学习记录,51单片机,嵌入式硬件,单片机,学习方法,笔记)