write_nyr(3,nian);
temp=(nian)/10*16+(nian)%10; //Convert decimal into DCB code required by DS1302
write_1302(0x8e,0x00); //Allow writing, disable write protection
write_1302(0x8c,temp); //Write the adjusted year data BCD code to the year register 8cH in DS1302
write_1302(0x8e,0x80); //Open write protection
write_1602com(yh+4);//Because the LCD mode is set to write data, the pointer automatically increases by one, so the cursor needs to return to its original position
break;
}
}
}
}
if((setNZn!=0)&&(setn==0))
{
if(add==0) //up key
{
delay(10);
if(add==0)
{
led1=0;
collection=0;
buzzer=0; //The buzzer beeps once
delay(20);
buzzer=1;
while(!add);
switch(setNZn)
{
case 3:
nz_miao++; //Press the setting key once to adjust the seconds
if(nz_miao==60)
nz_miao=0; //When the seconds exceed 59, add 1 and return to zero
write_sfm(14,nz_miao); //Let LCD display "plus" the set seconds in the correct position
write_1602com(er+15);//Because the LCD mode is set to write data, the cursor automatically moves to the right, so you need to specify the return
break;
case 2:
nz_fen++;
if(nz_fen==60)
nz_fen=0;
write_sfm(11,nz_fen); //Let LCD display the set "plus" data in the correct position
write_1602com(er+12); //Because the LCD mode is set to write data, the pointer automatically increases by one, so here it is written back to the original position
break;
case 1:
nz_shi++;
if(nz_shi==24)
nz_shi=0;
write_sfm(8,nz_shi); //Let LCD display the set hour data in the correct position
write_1602com(er+9); //Because the LCD mode is set to write data, the pointer automatically increases by one, so the cursor needs to return to its original position
break;
}
}
}
//------------------Decrease key dec, refer to the 'add key' comment for each sentence function---------------
if(dec==0)
{
delay(10); //Adjust delay to eliminate jitter
if(dec==0)
{
led1=0;
collection=0;
buzzer=0; //The buzzer beeps once
delay(20);
buzzer=1;
while(!dec);
switch(setNZn)
{
case 3:
nz_miao--;
if(nz_miao==-1)
nz_miao=59; //When the second data is reduced to -1, it will automatically become 59
write_sfm(14,nz_miao); //Display the new seconds after the change in the correct position of the LCD
write_1602com(er+15);
break;
case 2:
nz_fen--;
if(nz_fen==-1)
nz_fen=59;
write_sfm(11,nz_fen);
write_1602com(er+12); //Because the LCD mode is set to write data, the pointer automatically increases by one, so here it is written back to the original position
break;
case 1:
nz_shi--;
if(nz_shi==-1)
nz_shi=23;
write_sfm(8,nz_shi);
write_1602com(er+9); //Because the LCD mode is set to write data, the pointer automatically increases by one, so the cursor needs to return to its original position
break;
}
}
}
}
}
//-------------------------------
void init(void) //Timer and counter setting function
{
TMOD=0x11; //Specify the working mode of the timer/counter as 3
TH0=0; //The high four bits of timer T0 = 0
TL0=0; //The lower four bits of timer T0 = 0
TH1=0x3C;
TL1=0xB0;
EA=1; //The system allows open interrupts
ET0=1; //Enable T0 interrupt
ET1=1;
// IT1=1;
// IT0=0;
PT1=1;
PT0=0;
TR0=1; // Enable interrupt and start timer
TR1=0;
}
void InitialTimer2(void)
{
T2CON = 0x00; //16 Bit Auto-Reload Mode
TH2 = RCAP2H = 0x3C; //Reload value, initial value TL2 = RCAP2L = 0x18;
TL2 = RCAP2L = 0xB0;
ET2=1; //Timer 2 interrupt enabled
TR2 = 0; //Timer 2 starts
}
//*******************Main function***************************
//***************************************************
void main()
{
ds1302_init(); //Call the DS1302 clock initialization subfunction
init(); //Call the sub-function to set the timing counter
lcd_init(); //Call the LCD screen initialization subfunction
InitialTimer2();
led=1; //Turn off the LCD backlight power
while(1) //Infinite loop of the following statements:
{
keyscan(); //Call the keyboard scan subfunction
led=led1;
}
}
void timer0() interrupt 1 //Get and display calendar and time
{
//Init_DS18B20(); //Temperature sensor DS18b2 initialization subfunction, in the header file
// flag = ReadTemperature(); // Send the function result returned by running the 18b2 header file to the variable FLAG for display
//Read the seven data of seconds, hours, minutes, days, months and years (the read register and write register of DS1302 are different):
miao = BCD_Decimal(read_1302(0x81));
fen = BCD_Decimal(read_1302(0x83));
shi = BCD_Decimal(read_1302(0x85));
ri = BCD_Decimal(read_1302(0x87));
yue = BCD_Decimal(read_1302(0x89));
nian=BCD_Decimal(read_1302(0x8d));
if(NZK==1)
{
if((shi==nz_shi)&&(fen==nz_fen)&&(miao==0)) //Alarm time is up
{
TR2=1;
timeron=1;
}
if((shi==nz_shi)&&(fen==(nz_fen+1)))
{
TR2=0;
buzzer=1;
timeron=0;
}
}
if(ZDK==1)
{
if((fen==0x00)&&(miao==0x00)&&(timeron==0))
{
TR1=1;
shi = BCD_Decimal(read_1302(0x85));
……………………
Previous article:51 MCU Proteus simulation 320x240TFT color screen
Next article:Microcontroller breathing light program and waveform demonstration
- 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
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- What will happen if the servo motor inertia is insufficient?
- How to select parameters for servo motor inertia size
- The difference between the servo motor moment of inertia and the load moment of inertia
- How to calculate the inertia of servo motor and reducer
- What is the difference between a servo press and a normal press?
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Kill TPS54340
- Why is the voltage ringing spike of MOSFET different in boost and buck mode?
- The circuit for discharging the PFC output capacitor is shown in Figure 2.
- Basic syntax of Verilog HDL
- Found a method to import Altium Designer into SIwave
- Thanks to okhxyyo for searching and fish001 for sharing
- Please advise, is it easy to pass the postgraduate examination and graduate, and how useful is the degree certificate?
- About the LAUNCHXL-F28379D Development Kit
- Limited time 1 yuan patch! Save up to 10,000 yuan!
- Let me try this feature