液晶1602显示
显示1:字符“ABCDEFGHIJLMNOP"
“abcdefghijklmnop"
显示2:字符”come on eewp "
"come from nwnu"


#include "1602.h"
uchar code table1[]=" come on eewp ";
uchar code table2[]="come from nwnu ";
void main(void)
{
uchar i;
init();
for(i=0;i<16;i++)
{
LCD_disp_char(i,1,table1[i]);
//delay(20);
}
for(i=0;i<16;i++)
{
LCD_disp_char(i,2,table2[i]);
//delay(20);
}
while(1);
}
数字钟部分程序,代时间调整端
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit k1=P3^2;
sbit k2=P3^3;
sbit k3=P3^4;
int i,s,m,h;
uchar num,flag;
void delay(uint del)
{
uint x,y;
for(x=del;x>0;x--)
for(y=119;y>0;y--)
;
}
void t0_init(void)
{
flag=0;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
}
void display(int s,m,h)
{
。。。。。。。。
}
void main(void)
{
t0_init();
TR0=1;
while(1)
{
if(k1==0)
{
delay(50);
if(k1==0)
{
flag++;
if(flag==4) flag=0;
}while(k1==0);
}
switch(flag)
{
case 1:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
s++;
if(s>=60) s=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
s--;
if(s<=0) s=59;
}
}while(k3==0);
break;
case 2:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
m++;
if(m>=60) m=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
m--;
if(m<=0) m=59;
}
}while(k3==0);
break;
case 3:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
h++;
if(h>=23) h=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
h--;
if(h<=0) h=23;
}
}while(k3==0);
break;
default:
TR0=1;
break;
}
display(s,m,h);
}
}
void timer0() interrupt 1 using 0
{
num++;
if(num==20)
{
num=0;
s++;
if(s>=60)
{
s=0;
m++;
if(m>=60)
{
m=0;
h++;
if(h>=24)
{
h=0;
}
}
}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
数字钟部分程序,代时间调整端
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit k1=P3^2;
sbit k2=P3^3;
sbit k3=P3^4;
int i,s,m,h;
uchar num,flag;
void delay(uint del)
{
uint x,y;
for(x=del;x>0;x--)
for(y=119;y>0;y--)
;
}
void t0_init(void)
{
flag=0;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
}
void display(int s,m,h)
{
。。。。。。。。
}
void main(void)
{
t0_init();
TR0=1;
while(1)
{
if(k1==0)
{
delay(50);
if(k1==0)
{
flag++;
if(flag==4) flag=0;
}while(k1==0);
}
switch(flag)
{
case 1:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
s++;
if(s>=60) s=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
s--;
if(s<=0) s=59;
}
}while(k3==0);
break;
case 2:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
m++;
if(m>=60) m=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
m--;
if(m<=0) m=59;
}
}while(k3==0);
break;
case 3:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
h++;
if(h>=23) h=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
h--;
if(h<=0) h=23;
}
}while(k3==0);
break;
default:
TR0=1;
break;
}
display(s,m,h);
}
}
void timer0() interrupt 1 using 0
{
num++;
if(num==20)
{
num=0;
s++;
if(s>=60)
{
s=0;
m++;
if(m>=60)
{
m=0;
h++;
if(h>=24)
{
h=0;
}
}
}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
源程序
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
unsigned char LED;
void delay(uchar del)
{
int i,j;
for(i=0;i<del;i++)
for(j=0;j<119;j++)
;
}
void main(void)
{
uchar temp;
int i;
while(1)
{
P0=0xff;
P2=0xfe;
delay(3000);
temp=0xfe;
for(i=0;i<7;i++)
{
temp=_crol_(temp,1);
P2=temp;
delay(3000);
}
P0=0x01;
P2=0x00;
delay(3000);
temp=0x01;
for(i=0;i<7;i++)
{
temp=_crol_(temp,1);
P0=temp;
delay(3000);
}
}
}
2011-12-28 LCD1602数字钟
程序:
本程序由1602.c、1602.h 、main.c 三部分组成,分别如下:
/***********************************************************************
程序名称:T0定时器中断做数字LCD1602显示
编译环境:keil-uvsion4
操作系统:windows-xp
程序功能:T0定时器中断做数字钟1602显示
设计者: 岳文东
时间: 2011年11月16日
操作说明:
按P3.2键进入时间调整状态,按P3.3进行加法调整,按P3.4进行减法调整
当P3.2键累积按键到1次时,按P3.3键进行对时钟秒加,按P3.4键进行对时钟秒减
当P3.2键累积按键到2次时,按P3.3键进行对时钟分加,按P3.4键进行对时钟分减
当P3.2键累积按键到3次时,按P3.3键进行对时钟时加,按P3.4键进行对时钟时减
当P3.2键累积按键到4次时,退出时间调整,进行正常计数
*************************************************************************/
/************************************* 1602.h *****************************************/
#include<at89x51.h>
#ifndef __1602_H__
#define __1602_H__
#define uchar unsigned char
#define uint unsigned int
sbit LcdRs = P2^4;
sbit LcdRw = P2^5; //P2.1=1时写数据,P2.1=0时写地址
sbit LcdEn = P2^6; //P2.2=1时允许写数据
void init(void);//初始化函数
void LCD_disp_char(uchar x,uchar y,uchar dat);//在屏幕某个位置上显示一个字符,X(0--16),Y(1--2)
void L1602_string(uchar hang,uchar lie,uchar *p);
void delay(uint z);
#endif
/************************************** 1602.c **********************************************/
#include "1602.h"
//*****************延时函数****************
//*****************************************
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--)
;
}
//********************************
//********写指令函数************
void write_com(uchar com) //写指令
{
LcdRs=0;
// LcdRw=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 init(void) //初始化
{
LcdRw=0;
LcdEn=0;
delay(1);
write_com(0x38);//显示模式设置
write_com(0x0c);//光标设置,0x0c时不显示光标,0x0e时显示光标,0x0f时显示光标且闪烁
write_com(0x06);//设置光标的自动位置
write_com(0x01);//清屏
write_com(0x80+0x00);//定光标的位置 0x80+0x10
}
//*******显示一个字符函数*********
void LCD_disp_char(uchar x,uchar y,uchar dat)
{
uchar address;
if(y==1)
address=0x80+x;
else
address=0xc0+x;
write_com(address);
write_data(dat);
}
//*******显示字符串函数*********
void L1602_string(uchar hang,uchar lie,uchar *p)
{
uchar a;
if(hang == 1) a = 0x80;
if(hang == 2) a = 0xc0;
a = a + lie - 1;
write_com(a);
while(1)
{
if(*p == '\0') break;
write_data(*p);
p++;
}
}
/********************************* main.c *****************************************/
#include"1602.h"
char table[10]={'0','1','2','3','4','5','6','7','8','9'};
sbit k1=P3^1;
sbit k2=P3^2;
sbit k3=P3^3;
int s,m,h;
uchar num,flag;
void t0_init(void)
{
flag=0;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
}
void main(void)
{
t0_init();
init();
TR0=1;
while(1)
{
if(k1==0)
{
delay(50);
if(k1==0)
{
flag++;
if(flag==4) flag=0;
}while(k1==0);
}
switch(flag)
{
case 1:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
s++;
if(s>=60) s=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
s--;
if(s<=0) s=59;
}
}while(k3==0);
break;
case 2:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
m++;
if(m>=60) m=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
m--;
if(m<=0) m=59;
}
}while(k3==0);
break;
case 3:
TR0=0;
if(k2==0)
{
delay(50);
if(k2==0)
{
h++;
if(h>=23) h=0;
}
}while(k2==0);
if(k3==0)
{
delay(50);
if(k3==0)
{
h--;
if(h<=0) h=23;
}
}while(k3==0);
break;
default:
TR0=1;
break;
}
LCD_disp_char(3,1,table[h/10]);
LCD_disp_char(4,1,table[h%10]);
LCD_disp_char(5,1,'-');
LCD_disp_char(6,1,table[m/10]);
LCD_disp_char(7,1,table[m%10]);
LCD_disp_char(8,1,'-');
LCD_disp_char(9,1,table[s/10]);
LCD_disp_char(10,1,table[s%10]);
L1602_string(2,1,"design by YueWd");
// display(s,m,h);
}
}
void timer0() interrupt 1 using 0
{
num++;
if(num==20)
{
num=0;
s++;
if(s>=60)
{
s=0;
m++;
if(m>=60)
{
m=0;
h++;
if(h>=24)
{
h=0;
}
}
}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
/**************************************
程序名称: 编译环境:keil-uvsion4
操作系统:windows-xp
程序功能:流水灯
设计者: shunzhidui
时间: 2011年10月12日
**************************************/
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
unsigned char LED;
void delay(uchar del)
{
int i,j;
for(i=0;i<del;i++)
for(j=0;j<119;j++)
;
}
void main()
{
uchar i;
while(1)
{
LED=0X7F;
for(i=0;i<7;i++)
{
P0=LED;
delay(200);
LED=_crol_(LED,1);
P0=0xff;
delay(200);
}
}
}
/****利用定时器0工作方式0,在实验板上实现第3个发光管以1s亮灭闪烁。**/
#include <reg52.h>
#include <intrins.h>
#include <stdio.h>
#define uint unsigned int
#define uchar unsigned char
sbit led1=P1^2 ;
uchar num;
void main()
{
TMOD=0X00;
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(num==200)
{
num=0;
led1=~led1;
}
}
}
void T0_time() interrupt 1
{
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
num++;
}
有奖活动 | |
---|---|
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
“我踩过的那些坑”主题活动——第001期 | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【我踩过的那些坑】接线错误导致测试数据异常被打赏40分 | |
stm32f103驱动舵机被打赏20分 | |
汽车+汽车电子电阻解释与分析被打赏5分 | |
STM32F103的I2C驱动OLED动态显示被打赏30分 | |
分享汽车通信和多媒体总线结构被打赏20分 | |
【我踩过的那些坑】结构堵孔导致的喇叭无声问题被打赏50分 | |
NUCLEO-U083RC学习历程38+串口通过队列的方式输出两个字符串被打赏20分 | |
【我踩过的那些坑】分享一下调试一款AD芯片的遇到的“坑”被打赏50分 | |
电流检测模块MAX4080S被打赏10分 | |
【我踩过的那些坑】calloc和malloc错误使用导致跑飞问题排查被打赏50分 |