1602 Clock

Publisher:谁与争锋1Latest update time:2016-11-24 Source: eefocusKeywords:Clock Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/////////////////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(":");
 }
}


Keywords:Clock Reference address:1602 Clock

Previous article:c51 74ls164--165--595
Next article:1602 Scroll up and down

Recommended ReadingLatest update time:2024-11-23 08:05

About S3C2440 RTC real-time clock driver configuration and modification under Linux
  The support for S3C2440 RTC under Linux is very complete. We only need to make simple modifications to use RTC        1. vi arch/arm/mach-s3c2440/mach-smdk2440.c        static struct platform_device *smdk2440_devices __initdata = {        &s3c_device_usb,        &s3c_device_lcd,        &s3c_device_wdt,    
[Microcontroller]
s3c2410 ARM clock and settings
OSC uses a passive crystal oscillator, EXT uses an active crystal oscillator or an external clock. The 12M of 2440 is an Oscillator, which is active! 12M of 2440 is Oscillator   Crystal Passive Crystal         Oscillator Active crystal (contains active devices)   The passive crystal oscillator contains only
[Microcontroller]
Question about the clock source of STM32 common timer (TIM2-7)
【question】 The maximum bus clock of APB1 of STM32F103 is 1/2 of the AHB bus clock, which is 36MHz at most. When using ST's library function (v2.0), the clock frequency of TIM2 (normal timer) is 72MHz. I don't know why? 【problem analysis】 There are up to 8 timers in STM32, of which TIM1 and TIM8 are advanced timers tha
[Microcontroller]
Question about the clock source of STM32 common timer (TIM2-7)
LCD1602 liquid crystal display can display the clock and modify the time
CODE: /*************************************** Program function: The LCD display screen displays the clock and can modify the time ****************************************/ #include reg52.h #define uint unsigned int #define uchar unsigned char sbit K1=P1^0;//Set up three independent keyboards sbit K2=P1^3; s
[Microcontroller]
STM32 driver 1602 program
    Note: PD_0-7 is used for PO port ( LCD data port of MCU board), PA0_2;     They have been configured as registers in the function. Note that when reconfiguring PD     These ports should not be configured;     PD and PA need to be enabled in the main function.     Header function: #include "1602.h"     Function: li
[Microcontroller]
Introduction to 51 MCU - (New) Simple Digital Clock
Design requirements The hours (two digits), minutes (two digits), and seconds (two digits) should be displayed correctly and stably, and the digital tube should not flicker. The hour and minute information can be adjusted by pressing buttons, making it convenient for users to calibrate the time. Add an alarm funct
[Microcontroller]
Introduction to 51 MCU - (New) Simple Digital Clock
Analysis of MCU Clock
Clock cycle        The clock cycle is also called the oscillation period, which is defined as the reciprocal of the clock pulse (the clock cycle is the reciprocal of the crystal oscillator external to the microcontroller, for example, the clock cycle of a 12M crystal oscillator is 1/12us). It is the most basic and sma
[Microcontroller]
Analysis of MCU Clock
MCU Programming Skills - Clock Interrupt
Powerful clock interrupts In the design of single-chip microcomputer programs, setting a good clock interrupt will enable one CPU to play the role of two CPUs, greatly facilitate and simplify the compilation of programs, and improve the efficiency and operability of the system. We can put some routine programs t
[Microcontroller]
Latest Microcontroller Articles
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号