#include
#include
#include<DS1302.h>
sbit p10=P1^0;
bit flag=0; //Adjust control flag
bit flagh=1; //Time and date switch mark
uchar temp[7]; //Time before adjustment
uchar curtime1[8],curtime2[8]; //Adjusted time display mode
uchar tab1[]={30,40,11,31,8,2,14}; //DS1302 initialization time
uchar xingqi; //Read the day of the week
uchar code tab2[]={0xff,0xf9,0xA4,0xb0,0x99,0x92,0x82,0xf8}; //Common cathode LED to display the day of the week
uchar tab4[11]={0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,0x01}; //LED digital tube display code for displaying time and date
void delay2(void)
{
int i,j;
for(i=0; i<=10; i++);
for(j=0; j<=2; j++);
}
void main(void)
{
fly i,temp0[8];
P3=0xff;
Init_7219(); //Initialize MAX7219
set_rtc(tab1); //Initialize DS1302
// init_DS1302();
temp0[2]=10; //Display the "-" symbol at a fixed position
temp0[5]=10;
while(1)
{
get_1302(); //Read the time and save it in temp
if(p10==0) //Judge whether the button is released or pressed
delay2();
if( p10==0 )
{
flagh=0;
}
if((flagh==1)) //Time and date display switch flag
{
temp0[0]=temp[0]/16;
temp0[1]=temp[0]%16;
temp0[3]=temp[1]/16;
temp0[4]=temp[1]%16;
temp0[6]=temp[2]/16;
temp0[7]=temp[2]%16;
}
else
{ flagh=1; //Normal display of time, press the p10 key to display the date
temp0[0]=temp[3]/16;
temp0[1]=temp[3]%16;
temp0[3]=temp[4]/16;
temp0[4]=temp[4]%16;
temp0[6]=temp[6]/16;
temp0[7]=temp[6]%16;
}
for(i=0;i<8;i++)
{
Write_7219(i+1,tab4[temp0[i]]);
}
}
}
#include
#include
/*-------------------------------------------------
This function is to write data to MAX7219 (operation word or display data)
address is the address of the internal register;
dat is the operation word or displayed data
-------------------------------------------------*/
void Write_7219(uchar address,uchar dat)
{ fly i;
ACC=address;
LOAD=0; //Pull down the chip select line to select the device
//sending address
for (i=0;i<8;i++) // shift loop 8 times
{
CLK=0; //Clear clock bus
DIN=A7; //Each time, take the highest bit and send it to max7219
CLK=1; //Clock rising edge, send address
address<<=1; //Shift left one bit
}
//send data
ACC=that;
for (i=0;i<8;i++)
{
CLK=0;
DIN=A7;
CLK=1; //Clock rising edge, send data
dat<<=1;
}
LOAD=1; //Sending is completed, rising edge latches data
}
/*-------------------------------------------------
This is the initialization program of MAX7219
DECODE_MODE 0x09 //Decoding control register
INTENSITY 0x0A //Brightness control register
SCAN_LIMIT 0x0B //Scan limit register
SHUT_DOWN 0x0C //Shutdown mode register
DISPLAY_TEST 0x0F //Test control register
-------------------------------------------------*/
void Init_7219(void)
{
Write_7219(SHUT_DOWN,0x01); //Start normal working mode (0xX1)
Write_7219(DISPLAY_TEST,0x00); //Select working mode (0xX0)
Write_7219(DECODE_MODE,0x00); //Select non-decoding mode
Write_7219(SCAN_LIMIT,0x07); //Use all 8 LEDs
Write_7219(INTENSITY,0x04); //Set the initial brightness
}
/*
void mul_write_7219( uchar *point) //write multiple data
{
flying i;
for (i=0;i<8;i++)
{
Write_7219(i+1,*point);
point++;
}
}
*/
void set_rtc(uchar tab[])
{ uchar ucaddr=0x80; //Write the initial address of the initial time to the time register
flying a,i;
write_1302(0x8e,0x00); //, write protection is removed during initialization
for(i=0;i<7;i++)
{ a=tab[i]/10; //Convert decimal number to BCD code
tab[i]=tab[i]%10;
tab[i]=tab[i]+a*16;
write_1302(ucaddr,tab[i]);
ucaddr+=2;
}
// write_1302(0x8e,0x80); //Add write protection
}
/*-------------------------------------------------
This function reads out the data in the 1302 time register in multiple bytes and puts them into the curtime array.
{0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
The initial address to read data from the time register
Put the read data into the array curtime
-------------------------------------------------*/
void get_1302() //Read multiple bytes of data from the 1302 time register and put them into the curtime array
{ uchar ucaddr=0x81; //The initial address to read data from the time register
fly i=0;
//for(i=0;i<7;i++)
while(i<7)
{
temp[i]=read_1302(ucaddr);
ucaddr+=2;
i++;
}
}
void init_DS1302(void) // Initialize separately, no loop statement
{
write_1302(0x80,0x30);
write_1302(0x82,0x25);
write_1302(0x84,0x01);
write_1302(0x86,0x25);
write_1302(0x88,0x02);
write_1302(0x8A,0x04);
write_1302(0x8c,0x14);
write_1302(0x8e,0x0); //Remove write protection
}
Previous article:51 MCU timestamp related functions
Next article:51 MCU Function Module Study Notes - Timer
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- ESP32 port adds support for ESP32-S3
- TMS320C6000 Pipeline Overview
- Will the GaN RF market become more and more popular?
- The embedded operating system I know - to use it or not, that is indeed a question
- What are the models of mobile phone charger power chips and what are the replaceable chips?
- Mbed OS 2020 release schedule
- How to use TCD1304 to realize the design of high-speed CCD drive circuit with automatic gain control?
- Friends who are familiar with the MSP430 series of microcontrollers, please take a look (Beijing)
- How many of you guys are engaged in the FPGA industry?
- Implementation of Embedded RTOS on MSP430 MCU