基于AT89C52单片机的1602液晶显示程序
#include
#include "boardinit.h"
#include "keyscan.h"
#include "1602led.h"
#include "delay.h"
#include "74hc595.h"
#include "clock.h"
#define uchar unsigned char
#define uint unsigned int
uchar time=0;
uchar shi,fen,miao;
void write_data_160238(uchar data_1602);
void main()
{
TMOD=0x10;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
ET1=1;
TR1=1;
EA=1;
boardinit(); //板卡初始化
lcdinit_1602(); //1602初始化
Disp_1602(1,1," 2019-05-20 ",16);
Disp_1602(1,2," 00:00:00 ",16);
while(1)
{
keyscan();
clock();
}
}
void zd() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
time++;
}
##### keyscan.c
#include
#include "keyscan.h"
#include "74hc595.h"
#include "1602led.h"
#include "delay.h"
sbit s1 = P3^7; //设置按键
sbit s2 = P3^4; //时间- 按键
sbit s3 = P3^5; //时间+ 按键
sbit s4 = P3^0;
uchar num,moshi;
void keyscan()
{
s4=0;
if(s1==0)
{
delay(1);
if(s1==0)
{
while(!s1);
moshi++;
if(moshi==1)
{
write_order_1602(0x80+0x40+0x0b);
write_order_1602(0x0f);
TR1=0;
}
if(moshi==2)
{
write_order_1602(0x0f);
write_order_1602(0x80+0x40+0x08);
TR1=0;
}
if(moshi==3)
{
write_order_1602(0x0f);
write_order_1602(0x80+0x40+0x05);
TR1=0;
}
if(moshi==4)
{
write_order_1602(0x0c);
TR1=1;
if(moshi==4)
{
moshi=0;
}
}
}
}
if (moshi==1)
{
if(s2==0)
{
delay(1);
if(s2==0)
{
while(!s2);
miao++;
if(miao==60)
{
miao=0;
}
write_twoline_1602(11,miao);
write_order_1602(0x80+0x40+0x0b);
}
}
if(s3==0)
{
delay(1);
if(s3==0)
{
while(!s3);
miao--;
if(miao==(-1))
{
miao=59;
}
write_twoline_1602(11,miao);
write_order_1602(0x80+0x40+0x0b);
}
}
}
if (moshi==2)
{
if(s2==0)
{
delay(1);
if(s2==0)
{
while(!s2);
fen++;
if(fen==60)
{
fen=0;
}
write_twoline_1602(8,fen);
write_order_1602(0x80+0x40+0x08);
}
}
if(s3==0)
{
delay(1);
if(s3==0)
{
while(!s3);
fen--;
if(fen==(-1))
{
fen=59;
}
write_twoline_1602(8,fen);
write_order_1602(0x80+0x40+0x08);
}
}
}
if (moshi==3)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
shi++;
if(shi==24)
{
shi=0;
}
write_twoline_1602(5,shi);
write_order_1602(0x80+0x40+0x05);
}
}
if(s3==0)
{
delay(1);
if(s3==0)
{
while(!s3);
shi--;
if(shi==(-1))
{
shi=24;
}
write_twoline_1602(5,shi);
write_order_1602(0x80+0x40+0x05);
}
}
}
}
##### boardinit.c
/*晶振11.0592MHz
*/
#include
#include "74hc595.h"
#include "boardinit.h"
sbit duanxuan=P2^5; // 数码管,的段选使能,1 通 0关
sbit weixuan=P2^6; // 数码管,的位选使能,1 通 0关
void boardinit()
{
duanxuan=1; // 数码管,的段选使能,1 通 0关
weixuan=1; //数码管,的位选使能,1 通 0关
P0=0x00; //P0口送清零,关LED数码管的必要数据准备。
duanxuan=0; // 数码管,的段选使能,1 通 0关
weixuan=0; //数码管,的位选使能,1 通 0关
write_byte_74hc595(0x40); //选通8位发光二极管控制芯片u6(74HC573)锁存器的使能端
P1=0xff; //P1口送全1,关8位发光二极管的必要数据准备。//写完此句理论上8个发光二级管都会熄灭,因74HC595数据口复用了P1.0故P1.0的二极管可能不能被熄灭。
write_byte_74hc595(0x00); //关闭8位发光二极管控制芯片u6(74HC573)锁存器的使能端,把P1口数据保存(既关发光二极管)。
}
##### delay.c
#include "delay.h"
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/*
void delay_ds18b20(uint time)
{
uint i,j;
for(i=0;i
QQ:1678957377