1602显示数字0-99循环,求例子啊,最好是51单片机的噢~~
1个回答
展开全部
给你写一个参考程序
/*****************************************
*
*
*
显示0-99
*
*
******************************************/
#include
"REG52.H"
sbit
LCD_RS
=
P2^0;sbit
LCD_EN
=
P2^1;
#define
LCD_DATA
P0
unsigned
char
INT_TEMP;
unsigned
char
INT_NUMQ;
unsigned
char
value_temp[2];
/*
*
带形参延时1ms延时子函数
**/
void
Delay_1ms(unsigned
int
Time)
{
unsigned
int
x,
y;
for(x
=
Time;
x
>
0;
x--)
for(y
=
120;
y
>
0;
y--);
}
/*
*
LCD1602液晶写指令子函数
**/
void
Write_LCDcrys_ByteCmd(unsigned
char
Date)
{
LCD_RS
=
0;
LCD_DATA
=
Date;
Delay_1ms(30);
LCD_EN
=
1;
Delay_1ms(30);
LCD_EN
=
0;
}
/*
*
LCD1602液晶写数据子函数
**/
void
Write_LCDcrys_DataCmd(unsigned
char
Data)
{
LCD_RS
=
1;
LCD_DATA
=
Data;
Delay_1ms(30);
LCD_EN
=
1;
Delay_1ms(30);
LCD_EN
=
0;
}
/*
*
LCD1602液晶写指令初始化子函数
**/
void
Init_LCDcrysRst(void)
{
Write_LCDcrys_ByteCmd(0x38);
Write_LCDcrys_ByteCmd(0x08);
Write_LCDcrys_ByteCmd(0x0C);
Write_LCDcrys_ByteCmd(0x06);
Write_LCDcrys_ByteCmd(0x01);
}
/*
*
定时器初始化
**/
void
Timer0_Init(void)
{
TMOD
=
0x01;
TH0
=
(65536
-
50000)
/
256;
TL0
=
(65536
-
50000)
%
256;
EA
=
1;
ET0
=
1;
TR0
=
1;
}
void
DISPLAY_LCD1602(void)
{
value_temp[0]
=
INT_NUMQ
/
10
+
0x30;
value_temp[1]
=
INT_NUMQ
%
10
+
0x30;
Write_LCDcrys_ByteCmd(0x80
+
4);
Write_LCDcrys_DataCmd(value_temp[0]);
Write_LCDcrys_DataCmd(value_temp[1]);
}
int
main(void)
{
Init_LCDcrysRst();
Timer0_Init();
while(1)
{
DISPLAY_LCD1602();
}
}
void
Timer0()interrupt
1
{
TH0
=
(65536
-
50000)
/
256;
TL0
=
(65536
-
50000)
%
256;
INT_TEMP++;
if(INT_TEMP
==
20)
{
INT_TEMP
=
0;
INT_NUMQ++;
if(INT_NUMQ
==
100)
{
INT_NUMQ
=
0;
}
}
}
/*****************************************
*
*
*
显示0-99
*
*
******************************************/
#include
"REG52.H"
sbit
LCD_RS
=
P2^0;sbit
LCD_EN
=
P2^1;
#define
LCD_DATA
P0
unsigned
char
INT_TEMP;
unsigned
char
INT_NUMQ;
unsigned
char
value_temp[2];
/*
*
带形参延时1ms延时子函数
**/
void
Delay_1ms(unsigned
int
Time)
{
unsigned
int
x,
y;
for(x
=
Time;
x
>
0;
x--)
for(y
=
120;
y
>
0;
y--);
}
/*
*
LCD1602液晶写指令子函数
**/
void
Write_LCDcrys_ByteCmd(unsigned
char
Date)
{
LCD_RS
=
0;
LCD_DATA
=
Date;
Delay_1ms(30);
LCD_EN
=
1;
Delay_1ms(30);
LCD_EN
=
0;
}
/*
*
LCD1602液晶写数据子函数
**/
void
Write_LCDcrys_DataCmd(unsigned
char
Data)
{
LCD_RS
=
1;
LCD_DATA
=
Data;
Delay_1ms(30);
LCD_EN
=
1;
Delay_1ms(30);
LCD_EN
=
0;
}
/*
*
LCD1602液晶写指令初始化子函数
**/
void
Init_LCDcrysRst(void)
{
Write_LCDcrys_ByteCmd(0x38);
Write_LCDcrys_ByteCmd(0x08);
Write_LCDcrys_ByteCmd(0x0C);
Write_LCDcrys_ByteCmd(0x06);
Write_LCDcrys_ByteCmd(0x01);
}
/*
*
定时器初始化
**/
void
Timer0_Init(void)
{
TMOD
=
0x01;
TH0
=
(65536
-
50000)
/
256;
TL0
=
(65536
-
50000)
%
256;
EA
=
1;
ET0
=
1;
TR0
=
1;
}
void
DISPLAY_LCD1602(void)
{
value_temp[0]
=
INT_NUMQ
/
10
+
0x30;
value_temp[1]
=
INT_NUMQ
%
10
+
0x30;
Write_LCDcrys_ByteCmd(0x80
+
4);
Write_LCDcrys_DataCmd(value_temp[0]);
Write_LCDcrys_DataCmd(value_temp[1]);
}
int
main(void)
{
Init_LCDcrysRst();
Timer0_Init();
while(1)
{
DISPLAY_LCD1602();
}
}
void
Timer0()interrupt
1
{
TH0
=
(65536
-
50000)
/
256;
TL0
=
(65536
-
50000)
%
256;
INT_TEMP++;
if(INT_TEMP
==
20)
{
INT_TEMP
=
0;
INT_NUMQ++;
if(INT_NUMQ
==
100)
{
INT_NUMQ
=
0;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询