看你的程序感觉很费劲,呵呵,我发一个我的程序给你吧!
#include<reg52h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit rs=P3^5;
sbit lcden=P3^4;
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
sbit rd=P3^7;
uchar count,s1num;
char miao,shi,fen;
uchar code table[]=" 2007-7-30 MON";
uchar code table1[]=" 00:00:00";
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)
{
rs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
uchar num;
dula=0;
wela=0;
lcden=0;
// fen=59;
// miao=53;
// shi=23;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void keyscan()
{
rd=0;
if(s1==0)
{
delay(5);
if(s1==0)
{ s1num++;
while(!s1);
if(s1num==1)
{
TR0=0;
write_com(0x80+0x40+10);
write_com(0x0f);
}
}
if(s1num==2)
{
write_com(0x80+0x40+7);
}
if(s1num==3)
{
write_com(0x80+0x40+4);
}
if(s1num==4)
{
s1num=0;
write_com(0x0c);
TR0=1;
}
}
if(s1num!=0)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
if(s1num==1)
{
miao++;
if(miao==60)
miao=0;
write_sfm(10,miao);
write_com(0x80+0x40+10);
}
if(s1num==2)
{
fen++;
if(fen==60)
fen=0;
write_sfm(7,fen);
write_com(0x80+0x40+7);
}
if(s1num==3)
{
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);
write_com(0x80+0x40+4);
}
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
if(s1num==1)
{
/ if(miao==0)
{
miao=59;
write_sfm(10,miao);
write_com(0x80+0x40+10);
}/
miao--;
if(miao==-1)
miao=59;
write_sfm(10,miao);
write_com(0x80+0x40+10);
}
if(s1num==2)
{
fen--;
if(fen==-1)
fen=59;
write_sfm(7,fen);
write_com(0x80+0x40+7);
}
if(s1num==3)
{
shi--;
if(shi==-1)
shi=23;
write_sfm(4,shi);
write_com(0x80+0x40+4);
}
}
}
}
}
void main()
{
init();
while(1)
{
keyscan();
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==18)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(4,shi);
}
write_sfm(7,fen);
}
write_sfm(10,miao);
}
}
希望能帮助你,呵呵
这个是1602内部结构决定的,你只需要在初始化的时候先设置三次显示,然后再设置你的其他要求。
芯片厂家推荐的用法:
INT:
MOV
A,#30H
MOV
DATR,#CW_ADD
MOV
R2,#03H
INT1:
MOVX
@DPTR,A
CALL
DELAY
DJNZ
R2,INT1
这上面就是1602对于51单片机推荐的初始化之前加的三次模式设置
简单!! 工作流程:(具体的看程序,但个人认为差不多是这样) 1、通过按键设置输出电压值,通过LCD1602显示电压值,然后单片机端口输出设定的数据,最后DAC将数字电压转换为模拟电流,电流通过运放转为电压,通过示波器测试电压。
给你推荐一本书《MCS51单片机应用设计》哈尔滨工业大学出版社,里面很详细的
#include "reg52h"
#include "intrinsh"
unsigned char text1[] = "TTT TTTT add:qhd" ;
unsigned char text2[] = "TEL:13333333333 " ;
sbit RS = P2^0;
sbit RW = P2^1;
sbit EN = P1^2;
void delay_ms(unsigned char t);
void init_1602(void);
void write_command(unsigned char cmd);
void write_data(unsigned char dat);
void dsp_onechar(unsigned char pos,unsigned char c);
void dsp_string(unsigned char line,unsigned char p,unsigned char length);
void main(void)
{
init_1602();
delay_ms(15);
dsp_string(0,text1,16);
dsp_string(1,text2,16);
while(1);
}
void delay_ms(unsigned char t)//毫秒延时大约延时1ms
{
unsigned char i;
while(t--)
{
for(i=0;i<112;i++);
}
}
void write_command(unsigned char cmd)//写指令函数(按规定RS=0,RW=0为写指令)
{
delay_ms(5); // check busy flag
EN = 0;
RS = 0;
RW = 0;
_nop_();
EN = 1;
P0 = cmd;
EN = 0;
}
void write_data(unsigned char dat)//往1602写数据
{
delay_ms(5); //busy flag check
EN = 0;
RS = 1;
RW = 0;
_nop_();
EN = 1;
P0 = dat;
EN = 0;
RS = 0;
}
void dsp_onechar(unsigned char pos,unsigned char c)//写一个字节函数
{
unsigned char p;
if (pos>=0x10)
p=pos+0xb0;
else
p=pos+0x80;
write_command(p);
write_data(c);
}
void dsp_string(unsigned char line,unsigned char p,unsigned char length)
{
unsigned char l,i;
l=line<<4;
for (i=0;i<length;i++)
dsp_onechar(l++,(p+i));
}
void init_1602(void)//1602初始化
{
delay_ms(15);
write_command(0x38);
write_command(0x38);
write_command(0x38);
write_command(0x06);
write_command(0x0c);
write_command(0x01);
}
这是为你量身制作的,希望你能喜欢,光标根据按键在数字下面闪烁,一定符合你的要求,给你截了一张效果图
#include<reg52h>
#include<intrinsh>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uchar code table[]="1602";
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
rw=0;
en=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
void write_dat(uchar dat)
{
rs=1;
rw=0;
en=0;
P0=dat;
delay(5);
en=1;
delay(5);
en=0;
}
void init()
{
uchar i;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x86);
for(i=0;i<4;i++)
{
write_dat(table[i]);
delay(5);
}
}
void main()
{
init();
while(1)
{
if(key1==0)
{
delay(10);
if(key1==0)
{
while(key1==0);
write_com(0x86);
write_com(0x0f);
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
while(key2==0);
write_com(0x87);
write_com(0x0f);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(key3==0);
write_com(0x88);
write_com(0x0f);
}
}
if(key4==0)
{
delay(10);
if(key4==0)
{
while(key4==0);
write_com(0x89);
write_com(0x0f);
}
}
}
}
以上就是关于1602液晶显示屏不按程序显示全部的内容,包括:1602液晶显示屏不按程序显示、51单片机C语言1602液晶显示程序解析、求助1602电压电流表电路图和程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)