The following is the simulation schematic:
The 51 single-chip microcomputer drives the DS12887 clock chip and uses the lcd1602 liquid crystal screen to display the perpetual calendar
The source program is as follows:
#include #define uchar unsigned char #define uint unsigned int sbit dula=P2^6; sbit wela=P2^7; sbit rs=P3^5; sbit lcden=P3^4; sbit s1=P3^0; sbit s2=P3^1; sbit s3=P3^2; sbit rd=P3^7; sbit s4=P3^3; sbit dsds=P1^7; sbit dsrw=P1^6; sbit dsas=P1^5; sbit dscs=P1^4; sbit dsirq=P3^3; uchar count,shi,fen,miao,s1num,week=0,i,day=1,yue=1,year1=0,year2,year3,year4; uchar code table1[]=" 0000-01-01 MON"; //initial display uchar code table2[]=" 00:00:00"; uchar code table3[7][3]={"MON","TUE","WED","THU","FRI","STA","SUN"}; //Day code //********Delay function void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } //****Write command function void write_com(uchar com) { rs=0; lcden=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; } //****Write data function void write_data(uchar date) { rs=1; lcden=0; P0=date; delay(5); lcden=1; delay(5); lcden=0; } //****initialization function void init() { uchar num; // year=year1+year2*10+year3*100+year4*1000; wela=0; dula=0; lcden=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); write_com(0x80); for(num=0;num<15;num++) { write_data(table1[num]); delay(20); } write_com(0x80+0x40); for(num=0;num<12;num++) { write_data(table2[num]); delay(20); } /* TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; */ } //********Display hours, minutes and seconds void write_sfm(uchar add,uchar date1) { uchar shi,ge; shi=date1/10; ge=date1%10; write_com(add+0x80+0x40); write_data(0x30+shi); write_data(0x30+ge); } //********Display year, month and day void write_sfm1(uchar add,uchar date1) { uchar shi,ge; shi=date1/10; ge=date1%10; write_com(add+0x80); write_data(0x30+shi); write_data(0x30+ge); } void key2(); void key3(); //******Keyboard scanning function void keyscan() { rd=0; if(s1==0) //The first key is pressed { delay(5); //************Remove jitter if(s1==0) { s1num++; //***If the first key is not pressed once, s1num will increase by 1 while(!s1); if(s1num==1) //When pressed once, the cursor stops at the second position and starts flashing, always stops { TR0=0; write_com(0x80+0x40+11); write_com(0x0f); } if(s1num==2) //pressed for the second time, the cursor stops at the digit { write_com(0x80+0x40+8); } if(s1num==3) //pressed for the third time, the cursor stops at the time position { write_com(0x80+0x40+5); } if(s1num==4) //pressed for the fourth time, the cursor stops at the position showing the day of the week { write_com(0x80+15); } if(s1num==5) //pressed for the fifth time, the cursor stops at the position showing the day { write_com(0x80+10); } if(s1num==6) //pressed for the sixth time, the cursor stops at the position showing the month { write_com(0x80+7); } if(s1num==7) //When pressed for the seventh time, the cursor stops at the unit digit of the year { write_com(0x80+4); } if(s1num==8) //pressed for the eighth time, the cursor stops at the tens place { write_com(0x80+3); } if(s1num==9) //pressed for the ninth time, the cursor stops at the hundreds place { write_com(0x80+2); } if(s1num==10) //pressed for the tenth time, the cursor stops at the thousandth place { write_com(0x80+1); } if(s1num==11) //pressed for the eleventh time, the clock starts from the set time { s1num=0; write_com(0x0c); TR0=1; } } } if(s4==0) //The fourth key is pressed and the clock restarts { s1num=0; write_com(0x0c); TR0=1; } if(s1num!=0) { key2(); key3(); } } void key2() //Adjust time plus { if(s2==0) { delay(5); if(s2==0) { while(!s2); if(s1num==1) { miao++; if(miao==60) miao=0; write_sfm(10,miao); write_com(0x80+0x40+11); } if(s1num==2) { fen++; if(fen==60) fen=0; write_sfm(7,fen); write_com(0x80+0x40+8); } if(s1num==3) { shi++; if(shi==24) shi=0; write_sfm(4,shi); write_com(0x80+0x40+5); } if(s1num==4) { week++; switch(week) { case 0:write_com(0x80+12); for(i=0;i<3;i++) write_data(table3[week][i]); break; case 1:write_com(0x80+12); for(i=0;i<3;i++) write_data(table3[week][i]); break; case 2:write_com(0x80+12); for(i=0;i<3;i++) write_data(table3[week][i]); break; case 3:write_com(0x80+12); for(i=0;i<3;i++) write_data(table3[week][i]); break; case 4:write_com(0x80+12); for(i=0;i<3;i++) write_data(table3[week][i]); break; case 5:write_com(0x80+12); for(i=0;i<3;i++) write_data(table3[week][i]); break; case 6:write_com(0x80+12); for(i=0;i<3;i++) write_data(table3[week][i]); break; case 7:write_com(0x80+12); week=0; for(i=0;i<3;i++) write_data(table3[week][i]); break; } } if(s1num==5) { if((yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||12)&&day==31) day=0; if((yue==2||yue==4||yue==6||yue==9||yue==11)&&day==30) day=0; day++; write_sfm1(9,day); write_com(0x80+10); } if(s1num==6)
Previous article:TM1637 four-digit digital tube module driver (TM1637.h header file) 51 single-chip C language
Next article:MCU + ADC0832 differential and single channel program and annotations
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- I recently saw the DJI Mech S1 and it’s very interesting. Is anyone using it?
- MicroPython common IO port simulates SPI communication, which may be used when porting to some boards
- Three-coordinate programming
- ADI reference design geber file import ad problem
- Beijing's well-known 5G chip developer is recruiting: digital front-end engineer (RISCv or CPU digital front-end direction)
- Bike modification series: solar energy and batteries
- 【AT-START-F403A Review】Part 3 F403A STOP Mode Current Test
- [Free book 100% gift] A book teaches you how to develop test systems and gain an in-depth understanding of data acquisition systems
- 【DIY Creative LED】Circuit Analysis
- [DIY Bing Dun Dun] + a simple small Dun Dun board