/////////////////Clock//////////////////////
#include
#include
typedef unsigned char uchar;
typedef unsigned int uint;
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
#define lcd_port P0
#define begin_pos 2
uchar ss,mm,hh,n;
void delayms(uchar ms)
{ // Delay subroutine
uchar i,j;
for(;ms>0;ms--)
for(i=6;i>0;i--)
for(j=82;j>0;j--);
}
bit lcd_bz()
{ // Test LCD busy status
bit result;
rs=0;
rw=1;
e=1;
_nop_();
_nop_();
_nop_();
_nop_();
result=(bit)(P0&0x80);
e=0;
return result;
}
void lcd_w_cmd(uchar cmd)
{ // Write command data to LCD
while(lcd_bz());
rs=0;
rw=0;
e=0;
_nop_();
_nop_();
lcd_port=cmd;
_nop_();
_nop_();
_nop_();
_nop_();
e=1;
_nop_();
_nop_();
_nop_();
_nop_();
e=0;
}
void lcd_pos(uchar pos)
{ //Set display position
lcd_w_cmd(pos|0x80);
}
void lcd_w_dat(uchar dat)
{ //Write character display data to LCD
while(lcd_bz());
rs=1;
rw=0;
e=0;
lcd_port=dat;
_nop_();
_nop_();
_nop_();
_nop_();
e=1;
_nop_();
_nop_();
_nop_();
_nop_();
e=0;
}
void lcd_init() //LCD initialization settings
{
lcd_w_cmd(0x01); //Clear screen and reset cursor
delayms(1);
lcd_w_cmd(0x38); //Setting mode: 8-bit 2-line 5x7 dot matrix display mode
delayms(1);
lcd_w_cmd(0x0c); //Display on, cursor off, and cursor is not allowed to flicker
delayms(1);
lcd_w_cmd(0x06); //The text does not move, and the cursor automatically moves right
delayms(1);
}
void lcd_w_str(uchar *str)
{
while(*str>0)
{
lcd_w_dat(*str);
str++;
}
}
void display()
{
lcd_pos(4+begin_pos);//Display hours
delayms(1);
lcd_w_dat(hh/10+0x30);
delayms(1);
lcd_w_dat(hh%10+0x30);
delayms(1);
lcd_pos(7+begin_pos);//Display minutes
delayms(1);
lcd_w_dat(mm/10+0x30);
delayms(1);
lcd_w_dat(mm%10+0x30);
delayms(1);
lcd_pos(0x0a+begin_pos);//Display seconds
delayms(1);
lcd_w_dat(ss/10+0x30);
delayms(1);
lcd_w_dat(ss%10+0x30);
}
void main()
{
TMOD=0X01;
IE=0X82;
TL0=-50000%256;
TH0=-50000/256;
TR0=1;
lcd_init();
lcd_pos
(6+begin_pos);//Display:
delayms(1);
lcd_w_str(":");
delayms(1);
lcd_pos(9+begin_pos);//Display:
delayms(1);
lcd_w_str(":");
display();
delayms(10);
lcd_pos(begin_pos-1); //
lcd_w_str("TIME");
while(1)
{
display();
delayms(20);
}
}
void t0() interrupt 1
{
TL0=-50000%256;
TH0=-50000/256;
n++;
if(!(n%10))
{
lcd_pos(6+begin_pos);//Let: not display
delayms(1);
lcd_w_dat(0X20);
delayms(1);
lcd_pos(9+begin_pos);//Let: not display
delayms(1);
lcd_w_dat(0X20);
}
if(!(n%20))
{
ss++;
if(ss==60)ss=0,mm++;
if(mm==60)mm=0,hh++;
if(hh==24)hh=0;
lcd_pos(6+begin_pos);//Let: display
delayms(1);
lcd_w_str(":");
delayms(1);
lcd_pos(9+begin_pos); //Let: display
delayms(2);
lcd_w_str(":");
}
}
Previous article:c51 74ls164--165--595
Next article:1602 Scroll up and down
Recommended ReadingLatest update time:2024-11-23 08:05
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Coding and decoding of MSP430 infrared remote control
- Graduation project help
- It is found that domestic manufacturers like to polish the logo and model outside the chip.
- Registration for the 2021 STM32 Summit and Fan Carnival online live broadcast has begun!
- BleuNRG-1 one master and multiple slaves master module search interval setting
- How to use iic to make LCD screen display
- Design of MSP430 and MMC/SD card interface
- An Engineer's Guide to Temperature Sensing
- Analysis of Rectification Circuit and Filter Circuit
- Learn more about logic analyzers