The following is the 51 single-chip digital clock program:
#include #define DSbus P0 #define LCDbus P1 //Define the control lines of DS12C887 and LCD sbit DS_CS = P2^7; //Pin 13, chip select signal input, low level is valid. sbit DS_AS = P2^4; //Pin 14, address select input. sbit DS_RW = P2^5; //Pin 15, read/write input. sbit DS_DS = P2^6; //Pin 17, data select or read input. sbit LCD_RS=P2^0; sbit LCD_EN=P2^2; //Time variable definition unsigned char Counter; unsigned char Hour,Min,Sec,Year,Month,Date,Week; /*DS12CR887 driver--------------------------------------------------------------------------*/ //Function to write data to DS12CR887 void DS12887write(unsigned char add,unsigned char Date) { DS_CS=0; DS_DS=1; DS_RW=1; DS_AS=1; DSbus=add; DS_AS=0; DS_RW=0; DSbus=Date; DS_RW=1; DS_AS=1; DS_CS=1; } //Read DS12CR887 data function unsigned char DS12887read(unsigned char add) { unsigned char z; DS_CS=0; DS_RW=1; DS_DS=1; DS_AS=1; DSbus=add; DS_AS=0; DS_DS=0; DSbus=0xff; z=DSbus; DS_DS=1; DS_AS=1; DS_CS=1; return z; } //DS12CR887 initialization function void DS12887LCDinit() { DS_AS=0; DS_DS=0; DS_RW=0; DS12887write(0x0a,0x20); //DS12CR887 register A function setting, turn on the clock oscillator DS12887write(0x0b,0x06); //Register B function setting, alarm interrupt enable is not enabled, data mode is binary, 24-hour mode. //DS12887write(4,0x8);DS12887write(2,0x00);DS12887write(0,0x00); //Assign the hours, minutes, and seconds to DS12CR887, and it will display 8:00:00 after booting } void Delay(unsigned int z) { unsigned int x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void LCDwritecom(unsigned char com) { LCD_RS=0; LCDbus=com; Delay(5); LCD_EN=1; Delay(5); LCD_EN=0; } void LCDwritecomdata(unsigned char dat) { LCD_RS=1; LCDbus=dat; Delay(5); LCD_EN=1; Delay(5); LCD_EN=0; } void LCDinit() { LCD_EN=0; LCDwritecom(0x38); LCDwritecom(0x0c); LCDwritecom(0x06); LCDwritecom(0x01); LCDwritecom(0x80); } void Timedisplay(void) { //LCDwritecom(1); LCDwritecom(0x80); //Fill in the "hour" data on the LCD screen----------------------------------------------- Hour=DS12887read(4); //Read the hour data of DS12CR887 if((Hour/10)==0)LCDwritecomdata(0); else LCDwritecomdata(Hour/10+0x30); //Tens of hours LCDwritecomdata(Hour%10+0x30); //Hour digit LCDwritecomdata(':'); //clock separator:" //Fill in the "minute" data on the LCD screen----------------------------------------------- Min=DS12887read(2); //Read the sub-data of DS12CR887 LCDwritecomdata(Min/10+0x30); LCDwritecomdata(Min%10+0x30); LCDwritecomdata(':'); //clock separator:" //Fill in the "seconds" data on the LCD screen------------------------------------------------- Sec=DS12887read(0); //Read the second data of DS12CR887 LCDwritecomdata(Sec/10+0x30); LCDwritecomdata(Sec%10+0x30); Delay(100); } void Datedisplay(void) { //LCDwritecom(1); LCDwritecom(0xc0); //Fill in the "year" data on the LCD screen----------------------------------------------- LCDwritecomdata('2'); LCDwritecomdata('0'); Year=DS12887read(9); //Read the year data of DS12CR887 LCDwritecomdata(Year/10+0x30); //Year 10 digits LCDwritecomdata(Year%10+0x30); //Year digit LCDwritecomdata('/'); //clock separator:" //Fill in the "month" data on the LCD screen----------------------------------------------- Month=DS12887read(8); //Read the monthly data of DS12CR887 LCDwritecomdata(Month/10+0x30); LCDwritecomdata(Month%10+0x30); LCDwritecomdata('/'); //clock separator:" //Fill in the "day" data on the LCD screen------------------------------------------------- Date=DS12887read(7); //Read the daily data of DS12CR887 LCDwritecomdata(Date/10+0x30); LCDwritecomdata(Date%10+0x30); //Fill in the "week" data on the LCD screen------------------------------------------------- Week=DS12887read(6); //Read daily data from DS12CR887 LCDwritecomdata(0); LCDwritecomdata(Week-1+0x30); Delay(100); } void main() { // unsigned char i; LCDinit(); DS12887LCDinit(); DS12887write(0x0a,0x00); //Start timing, DS12CR887 turns off the clock oscillator DS12887write(0,55); //seconds DS12887write(2,59); DS12887write(4,23); DS12887write(6,5); //week DS12887write(7,22); //日 DS12887write(8,9); // DS12887write(9,12); // //display_Date(); while(1) { Timedisplay(); Datedisplay(); Delay(100); } }
Previous article:51 MCU software SPI initialization ILI9488-DPI mode program
Next article:51 single chip electronic calendar (adjustable with temperature) DS1302 clock + 12864 LCD display
- 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
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- 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
- MSP430G2553 programming problem: two lights flash alternately
- Teaching flowchart template sharing
- Does anyone know why bluenrg_2 adds +2 to the feature value when subscribing to it?
- In the 51 MCU serial communication mode 1, what kind of clock does timer 1 provide to the serial port module?
- Why does the Ethernet interface circuit need to be connected to GND through resistors and capacitors?
- Features and main applications of TI wireless connectivity products
- Read the good book "Operational Amplifier Parameter Analysis and LTspice Application Simulation" 05 Offset Voltage Case Analysis
- Automotive External Amplifiers
- Award-winning live broadcast | Firmware upgrade solution for Renesas MCU
- Into space: Solid-state power amplifiers aid space exploration