STC12C5A32S2单片机之1602渐入显示

来源:互联网 发布:句读知不知是什么意思 编辑:程序博客网 时间:2024/05/01 20:22

基本框架根据郭天祥Lesson8中的程序来编写,但是渐入显示的时候郭用的指令是write_com(0x18);

可我用的时候就是显示不出来,于是根据1602的说明书,用了另外一个指令write_com(0x07)    //当写一个字符,整屏显示左移

程序如下:

可直接运行,已调试OK


#include <reg51.h>


sbit LCD_rs=P1^0;
sbit LCD_rw=P1^1;
sbit LCD_en=P2^5;

unsigned char num;
unsigned char code table[]="I Love ZYN";
unsigned char code table1[]="0123456789";

void Delay(unsigned int i)   //注意,若此处用char声明,否则会看不到延时渐进的效果,疑问?
{
unsigned int j,k;
for(j=i;j>0;j--)
for(k=110;k>0;k--);
}

void LCD_Write_com(unsigned char a)
{
LCD_rs=0;
Delay(5);
LCD_rw=0;
Delay(5);
P0=a;
Delay(5);
LCD_en=1;
Delay(5);
LCD_en=0;
Delay(5);
}


void LCD_Write_data(unsigned char b)
{
LCD_rs=1;
Delay(5);
LCD_rw=0;
Delay(5);
P0=b;
LCD_en=1;
Delay(5);
LCD_en=0;
Delay(5);
 }


void LCD_init()
{
Delay(15);
LCD_Write_com(0x38);
Delay(5);
LCD_Write_com(0x08);
Delay(5);
LCD_Write_com(0x01);
Delay(5);
LCD_Write_com(0x07);  //当写一个字符,整屏显示左移
Delay(5);
LCD_Write_com(0x0e);
Delay(5);
}

void main()
{
LCD_init();

        LCD_Write_com(0x80+0x16);//此处0x16也可用十进制数22
Delay(5);

for(num=0;num<10;num++)
{
LCD_Write_data(table[num]);
Delay(3000);
   }

 
LCD_Write_com(0x80+0x59);//此处0x59也可用十进制数89表示
for(num=0;num<10;num++)
{
LCD_Write_data(table1[num]);
Delay(3000);
}
while(1);
}
实际效果如下:

























0 0
原创粉丝点击