基于单片机STC12C5A60S2芯片的1602液晶显示,跳线按照要求连接
附上主程序
#include "stc12c5a60s2.h"
#include "intrins.h"
#include "onewire.h"
#define uchar unsigned char
#define uint unsigned int
uchar table[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
uint temp = 123;
void display_C()
{
write_com(0x80);
write_data('T');
write_data('e');
write_data('m');
write_data('p');
write_data(':');
write_data('1' );
write_data('2' );
write_data('3' );
write_data('4' );
write_data('C');
}
void display_L()
{
write_com(0xC0);
write_data('d');
write_data('i');
write_data('s');
write_data(':');
write_data( table[temp/100] );
write_data( table[temp/10%10] );
write_data( table[temp%10%10] );
}
void main()
{
LCD_init();
while(1)
{
display_C();
display_L();
}
}
在COM中的(0XC0),(0X80)负责液晶显示的第一行和第二行
以下附上.C文件
#include "stc12c5a60s2.h"
#include "intrins.h"
#define uint unsigned int
#define uchar unsigned char
sbit lcden=P2^5;
sbit lcdrw=P1^1;
sbit lcdrs=P1^0;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
lcdrw=0;
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void LCD_init()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
附上.H文件
#ifndef _LCD1602_H
#define _LCD1602_H
#define uint unsigned int
#define uchar unsigned char
void delay(uint z);
void write_com(uchar com);
void write_data(uchar date);
void LCD_init();
#endif
上面做了一个基础显示,如需继续写入,只用把date数据往后复制添加即可
|