LCD1602 liquid crystal display DS1302 real-time clock Proteus simulation

Publisher:江上HZLatest update time:2016-09-05 Source: eefocusKeywords:LCD1602 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Proteus simulation diagram:
LCD1602 liquid crystal display DS1302 real-time clock Proteus simulation - Yanboheng - YanbohengLCD1602 liquid crystal display DS1302 real-time clock Proteus simulation - Yanboheng - Yanboheng

 

 

Simulation program:

 

#include

#include

#include

#define uint  unsigned int

#define uchar unsigned char

//*******LCD*******

sbit LCDRS=P2^0; //LCD data/command selection terminal

sbit LCDRW=P2^1;

sbit LCDEN=P2^2; //LCD enables the new terminal

//******DS1302******

sbit IO=P1^0; //1302 data line

sbit SCLK=P1^1; //1302 clock line

sbit RST=P1^2; //Reset

 

uint num=0;

//uchar week[]={"SUN","***","MON","TUS","WEN","THU","FRI","SAT"};

uchar Date[]={"Date: 2000-00-00 "};

uchar Time[]={"Time: *00:00-00* "};

uchar date_time[7]; //Current date and time read from ds1302

//=======Delay=======

void delay(uint z)

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

//********Write data to 1302*********

void write_ds1302(uchar dat)

{

flying i;

for(i=0;i<8;i++)

{

IO=dat & 0x01; //Keep the last bit as 1, read status

SCLK=1;

delay(1);

SCLK=0;

that >>= 1;

}

}

//************Read data from 1302*********

uchar read_ds1302()

{

fly i,b=0x00;

for(i=0;i<8;i++)

{

b |= _crol_((fly)IO,i);

SCLK=1;

delay(1);

SCLK=0;

}

return b/16*10+b%16; //Convert to BCD code

}

//************Read data from the specified location********

fly read_data(fly addr)

{

flying dat;

RST=0;

SCLK=0;

RST=1;

write_ds1302(addr);

dat=read_ds1302();

SCLK=1;

RST=0;

return that;

}

//************Read the current date and time*********

void read_date_time()

{

uchar i,addr=0x81;

for(i=0;i<7;i++)

{

date_time[i]=read_data(addr);

addr+=2;

}

}

//----------LCD write instruction----------

void lcd_write_com(uchar com)

{

LCDRS=0; //When RS is 0, write instruction, when RS is 1, write data

P0=com;

delay(5);

LCDEN=1;

delay(5);

LCDEN=0;

}

//----------LCD write data----------

void lcd_write_data(uchar dat)

{

LCDRS=1;

P0=that;

delay(5);

LCDEN=1;

delay(5);

LCDEN=0;

}

//-------LCD initialization-------

void lcd_init()

{

LCDEN=0;

lcd_write_com(0x38); //LCD display mode setting

lcd_write_com(0x0c); //LCD display on/off and cursor setting

lcd_write_com(0x06); //After writing a character, the address pointer increases by 1, and the cursor increases by 1

lcd_write_com(0x01); //Clear the screen

}

//---------Set LCD display position-----------

void set_lcd_pos(uchar p)

{

lcd_write_com(p | 0x80);

}

//---------LCD display program----------

void lcd_print(uchar p,uchar *s)

{

set_lcd_pos(p);

for(num=0;num<16;num++)

{

lcd_write_data(s[num]);

delay(10);

}

}

//----------Date time conversion-----------

void format_datetime(string d, string *p)

{

p[0]=d/10+'0';

p[1]=d%10+'0';

}

//---------Main program--------------

void main()

{

LCDRW=0;

lcd_init();

while(1)

{

read_date_time();

format_datetime(date_time[6],Date+8); // Date

format_datetime(date_time[4],Date+11);

format_datetime(date_time[3],Date+14);

// strcpy(Date+13,week[date_time[5]]);

format_datetime(date_time[2],Time+7); //Time conversion

format_datetime(date_time[1],Time+10);

format_datetime(date_time[0],Time+13);

lcd_print(0x00,Date);

lcd_print(0x40,Time);

}

}

Keywords:LCD1602 Reference address:LCD1602 liquid crystal display DS1302 real-time clock Proteus simulation

Previous article:51 single chip microcomputer c language --- delay
Next article:12864 LCD simple display program (with font library)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号