MCS51单片机数字电子钟设计
发布网友
发布时间:2022-05-01 05:47
我来回答
共1个回答
热心网友
时间:2022-06-25 04:57
看看这个,能不能看懂啊/*程序描述:M1602的控制芯片为HD44790,从DS1302读取万年历,进行显示 */
/* ***************************************************** */
#include <reg51.h>
#include "DS1302_0603.h"
#include <string.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define TwoLine_8bit 56 // 0x38
#define CLEAR 1 // 0b00000001
#define CURSOR_HOME 2 // 0b00000010
#define CURSOR_LEFT 4 // 0b00000100
#define CURSOR_RIGHT 6 // 0b00000110
#define CURSOR_OFF 12 // 0b00001101
//#define CURSOR_ON 14 // 0b00001110
//#define CURSOR_BLINK 15 // 0b00001101
#define GOTO_LINE_2 192
#define GOTO_LINE_1 128
/* LCD control lines */
#define ENABLE 1
#define DISABLE 0
#define READ 1
#define WRITE 0
#define COMMAND 0
#define DATA 1
sbit key1=P3^5;
sbit key2=P3^4;
sbit key3=P3^3;
sbit key4=P3^2;
uchar code cursor_y[]={0x07,0x0a,0x0d,0x05,0x08,0x0b,0x0e},cursor_x[]={1,1,1,2,2,2,2},value[]={0x8d,0x89,0x87,0x8b,0x85,0x83,0x81};
uchar key1_state,key2_state,key3_state,key4_state,key1_mode = 0,key4_mode = 0;
uchar DS1302_Time_1[9];
uchar DS1302_Time_2[3];
uchar DS1302_Time_3[8];
sfr change_12_24= 0xf8;
sbit rs=P2^2;
sbit rw=P2^1;
sbit enable=P2^0;
sbit change7 = change_12_24^7;
sbit change5 = change_12_24^5;
char code int2charLCD[]="0123456789";
void write_LCD_command(uchar command);
void init_LCD(void)
{
write_LCD_command(TwoLine_8bit); // 0x38
write_LCD_command(CURSOR_OFF); // 0x0C
write_LCD_command(CURSOR_RIGHT); // 0x06
}
void delay100us(uint n)
{
uchar j;
for(;n>0;n--)
{
for(j=0;j<100;j++);
}
}
void write_LCD_command(uchar command)
{
rw=WRITE;
rs=COMMAND;
enable=ENABLE;
P0=command;
delay100us(20);
enable=DISABLE;
rw=1;
}
void write_LCD_data(uchar LCDdata)
{
rw=WRITE;
rs=DATA;
enable=ENABLE;
P0=LCDdata;
delay100us(20);
enable=DISABLE;
rw=1;
}
void clear_LCD()
{
write_LCD_command(CLEAR);
write_LCD_command(CURSOR_HOME);
}
void display_LCD_string(uchar *p)
{
while(*p)
{
write_LCD_data(*p);
p++;
}
}
void display_LCD_number(uchar number)
{
uchar x,y;
x=number/10;
y=number%10;
write_LCD_data(int2charLCD[x]);
write_LCD_data(int2charLCD[y]);
}
void gotoxy(uchar x,uchar y)
{
if(x==1)
write_LCD_command(GOTO_LINE_1+y);
else
write_LCD_command(GOTO_LINE_2+y);
}
待续