1. An electronic 1602 LCD electronic clock that can display the day of the week and time.
2. But there is no subroutine to adjust the time. Who knows how to adjust the subroutine? It can be improved.
3. The LCD port can be modified at will according to your own circuit. It is at the top of the program.
4. This program has been successfully tested on the 51hei single-chip development board. All codes and header files
Download address:
http://www.51hei.com/ziliao/51hei-5/电子时刻+1602LCD.rar
#include#include "51hei.h" #define uchar unsigned char sbit RW=P2^7; sbit RS=P3^5; sbit E=P3^4; sbit duan=P2^6; bit at=0; //sbit busy_bit=P1^7; uchar code shen[]={"I love you!!"}; uchar code word[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
0x39,0x3a,0x20,0x2d,0x00,0x01,0x02,0x03,0x03,0x04,0x05,0x06,0x07}; uchar code ri[]={0x1f,0x19,0x19,0x1f,0x19,0x19,0x1f,0x00}; //Custom symbol: Sunday uchar code yi[]={0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00};/*Custom symbol: Monday*/ uchar code er[]={0x00,0x00,0x0e,0x00,0x1f,0x00,0x00,0x00,0x00};/*Custom symbol: Tuesday 2*/ uchar code san[]={0x00,0x1f,0x00,0x0e,0x00,0x1f,0x00,0x00};/*Custom symbol: Wednesday 2*/ uchar code si[]={0x00,0x1f,0x1a,0x1a,0x11,0x11,0x00,0x00}; //Custom symbol: Thursday uchar code wu[]={0x00,0x1f,0x08,0x1f,0x09,0x1f,0x00,0x00}; //Custom symbol: Friday uchar code liu[]={0x08,0x04,0x1f,0x0a,0x11,0x10,0x00,0x00}; //Custom symbol: Friday uchar dispbuf[10],ri1,h,m,s,counter; void delay() { uchar i; for(i=0;i<255;i++); } /*******Write command**********/ void lcd_wmc(uchar i) { P0=i; RS=0; RW=0; E=0; delay(); E=1; } /*******Write data***********/ void lcd_wmd(uchar i) { P0=i; RS=1; RW=0; E=0; delay(); E=1; } /*******Initialize LCD*******/ void lcd_init() { uchar i; lcd_wmc(0x01); lcd_wmc(0x38); //Function setting command-5 Display mode setting: 16×2 display, 5×7 dot matrix,
8-bit data interface lcd_wmc(0x0c); // Display switch control instruction 0x0c--display function is on without cursor, that is, the cursor does not blink.
00x0f--Display function is on, cursor is flashing lcd_wmc(0x06); //Display mode setting: cursor moves right, characters do not move Input mode setting command -3 lcd_wmc(0x82); // 0xc9 =0x80 | 0x49 Set DDRAM address instruction--8
PPt 8 ox82=0x80|0x02 for(i=0;i<12;i++) lcd_wmd(shen[i]); //Display I love you!! string lcd_wmc(0xc0); } /*******Update buffer subroutine*******/ void newbuf() { dispbuf[0]=s%10; dispbuf[1]=s/10; dispbuf[3]=m%10; dispbuf[4]=m/10; dispbuf[6]=h%10; dispbuf[7]=h/10; dispbuf[9]=ri+13; } /*******Display subroutine**********/ void disp(uchar dispadd) { uchar tmp; //define a uchar variable lcd_wmc(dispadd); // Call the write instruction function to write the DDRAM address instruction into tmp=dispbuf[9]; //week//The same applies to the following tmp=word[tmp]; lcd_wmd(tmp); tmp=dispbuf[8]; tmp=word[tmp]; lcd_wmd(tmp); tmp=dispbuf[7]; //Line 2 assigns the value to tmp tmp=word[tmp]; //Give the number to be displayed to tmp lcd_wmd(tmp); //Write data function to display the number to be displayed on the display tmp=dispbuf[6]; //The same applies to the following tmp=word[tmp]; lcd_wmd(tmp); tmp=dispbuf[5]; tmp=word[tmp]; lcd_wmd(tmp); tmp=dispbuf[4]; tmp=word[tmp]; lcd_wmd(tmp); //minutes tmp=dispbuf[3]; tmp=word[tmp]; lcd_wmd(tmp); tmp=dispbuf[2]; //The display shows two dots flashing tmp=word[tmp]; lcd_wmd(tmp); tmp=dispbuf[1]; tmp=word[tmp]; //seconds lcd_wmd(tmp); tmp=dispbuf[0]; tmp=word[tmp]; lcd_wmd(tmp); } /*************************Initialization subroutine**********************/ void init() { TMOD=0x01; TH0=0x4c; TL0=0x00; EA=1; ET0=1; TR0=1; counter=0; h=23;m=59;s=0; ri1=6; dispbuf[2]=10; dispbuf[5]=10; dispbuf[8]=12; } /***************************Main program****************************/ void main(void) { guanled(); guandz(); init(); lcd_init(); while(1) { if(!at) { //Blink if(counter<10) { dispbuf[2]=10; dispbuf[5]=10; } else { dispbuf[2]=11; dispbuf[5]=11; } //Update the display buffer and call the display program if(counter==0) { newbuf(); disp(0xc4); } else if(counter==10) disp(0xc4); } } } /*****************************Timer 0 interrupt**********************/ void Time0() interrupt 1 using 2 //Again, the shorter the execution time of the interrupt subroutine, the better { TH0=(65536-46075)/256; TL0=(65536-46075)%256; counter++; if(counter==20) { s++; counter=0; if(s==60) { m++; s=0; if(m==60) { h++; m=0; if(h==24) h=0; ri1++; if(ri1==7) { ri1=0; } } } } }
Previous article:Infrared data communication experiment
Next article:4-bit common anode digital tube dynamic scanning display assembly program
Recommended ReadingLatest update time:2024-11-16 22:54
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- One picture to understand the chip series: Huawei Kirin super popular science - RF
- Research and development of supercapacitor urban public transportation electric vehicles
- [Raspberry Pi Pico Review] Serial communication function and its test
- How to choose the appropriate main circuit topology for power supply?
- The diameter of the four holes on the EK140 base plate
- This circuit is called a "lawn mower"
- In a single-chip computer, writing 1 clears it to 0, and writing 0 clears it to 0. What is the difference?
- How to monitor battery voltage with Arduino
- Image Algorithm Transplantation to DSP and Its Optimization Steps
- To advance in technology to a certain level, you just need to read more datasheets!