|
本帖最后由 leizhihao13 于 2019-6-21 22:36 编辑
电路图比较简单,只用到了单片机最小系统的复位电路和晶振电路,然后接上排阻和1602液晶屏就OK了!自己画图,PCB图,有点不够完美是用到了一条飞线
部分代码:
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar KeyCount=0;
sbit S2 = P3^0;
sbit S3 = P3^1;
uchar code cdis1[ ] = {" STOPWATCH 0 "};
uchar code cdis2[ ] = {" WYU-2864 "};
uchar code cdis3[ ] = {"TIME "};
uchar code cdis4[ ] = {" BEGIN COUNT 1 "};
uchar code cdis5[ ] = {" PAUSE COUNT 2 "};
uchar code cdis6[ ] = {" BEGIN COUNT 3 "};
uchar code cdis7[ ] = {" PAUSE COUNT 4 "};
uchar code cdis8[ ] = {" "};
sbit LCD_RS = P3^5;
sbit LCD_RW = P3^6;
sbit LCD_EN = P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
uchar display[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar display2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/*********************************************************
延时函数
*********************************************************/
void Delay(uint num)//延时函数
{
while( --num );
}
/*********************************************************
延时函数1
*********************************************************/
void delay1(int ms)
{
unsigned char n;
while(ms--)
{
for(n = 0; n<250; n++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
/**********************************************************
* *
*写指令数据到LCD *
*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 *
* *
**********************************************************/
void lcd_wcmd(uchar cmd)
{
// while(lcd_busy());
LCD_RS = 0;
// LCD_RW = 0;
LCD_EN = 0;
_nop_();
_nop_();
P0 = cmd;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
Delay(10);
}
/**********************************************************
* *
*写显示数据到LCD *
*RS=H,RW=L,E=高脉冲,D0-D7=数据。 *
* *
**********************************************************/
void lcd_wdat(uchar dat)
{
// while(lcd_busy());
LCD_RS = 1;
// LCD_RW = 0;
LCD_EN = 0;
P0 = dat;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
Delay(10);
}
/**********************************************************
* *
* LCD初始化设定 *
* *
**********************************************************/
void lcd_init()
{
LCD_RW = 0;
dula=0;
wela=0;
delay1(15);
lcd_wcmd(0x01); //清除LCD的显示内容
lcd_wcmd(0x38); //16*2显示,5*7点阵,8位数据
delay1(5);
lcd_wcmd(0x38);
delay1(5);
lcd_wcmd(0x38);
delay1(5);
lcd_wcmd(0x0c); //开显示,不显示光标
delay1(5);
lcd_wcmd(0x01); //清除LCD的显示内容
delay1(5);
}
|
评分
-
查看全部评分
|