[Resource Download] The download address is as follows:
https://docs.qq.com/doc/DTlRSd01BZXNpRUxl
51 Intelligent Circuit Breaker Time Detection Design-KEY-LCD1602
This design is composed of STC89C52 single-chip circuit + LCD1602 liquid crystal display circuit + button circuit + power supply circuit.
1. The LCD displays the time difference between the first switch press and the second press in real time.
#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义
#include<stdio.h>
#include "1602.h"
#include "delay.h"
unsigned long time_20ms=0; //定时器计数
sbit key1 = P2^0;
sbit key2 = P2^1;
char dis0[16]; //显示更新暂存
bit disFlag = 0 ;//定时更新显示
unsigned long timeCount = 0;//计数
unsigned char startFlag = 0;//启动标志
void Init_Timer0(void); //函数声明
void main (void)
{
Init_Timer0(); //定时器0初始化
LCD_Init(); //初始化液晶
DelayMs(20); //延时有助于稳定
LCD_Clear(); //清屏
while (1) //主循环
{
if(key1 == 0)//按键触发 上端
{
timeCount = 0;
startFlag = 1;
}