/***************The clock adopts the timed interrupt mode, 50MS once******Completely available, the hardware experiment passed**********************/
#include
#include
#include
/***********************************************************************/
#define uchar unsigned char
#define uint unsigned int
//common part
#define HIGH 1
#define LOW 0
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MSB 0x80
#define LSB 0x01
//max7219 part
#define REG_NO_OP 0x00 // Define no operation
#define DIG_1 0x01 // Define digital tube 1
#define DIG_2 0x02 // Define digital tube 2
#define DIG_3 0x03 // Define digital tube 3
#define // MAX7219 Load-Data Input: rising edge pin 12 sbit DIN=P2^5; //MAX7219 12bit LOAD = P2
^ 7 ; // MAX7219 Load - Data Input: rising edge pin 12 sbit DIN=P2^5; // MAX7219 Serial-Data Input: rising edge pin 1 sbit CLK=P2^6; //MAX7219 sbit TT=P1^4; sbit QQ=P3^6; sbit RR=P3^7; //function define /*****************************************************************/ void Write_Max7219_byte(unsigned char temp);//write max7219 a byte void Write_Max7219(unsigned char address,unsigned char dat);//write max7219 command and data void Init_Max7219(void);//Initize max7219 //test program display from 1~8 /****************************************************************************/ /***********************************************************************/ void Write_Max7219_byte(unsigned char temp) { unsigned char i; for (i=0;i<8;i++) { CLK=LOW; DIN=(bit)(temp&MSB); temp<<=1; CLK=HIGH; } } /**********************************************************************/ void Write_Max7219(unsigned char address,unsigned char dat) { LOAD=LOW; Write_Max7219_byte(address); Write_Max7219_byte( dat); LOAD=HIGH; }
/****************************************************** ************************/
void Init_Max7219(void)
{
Write_Max7219(SHUT_DOWN, 0x01); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
Write_Max7219(DISPLAY_TEST, 0x00)
; // Normal
Operation
, 0x04);
Write_Max7219(DIG_4,0x02); Write_Max7219(DIG_3,0x01);
Write_Max7219(DIG_6,0x07); Write_Max7219(DIG_5,0x05);
Write_Max7219(DIG_7,0x01);
}
/****************************** ******************************/
void init(void)
{
TMOD=0x01;
TH0=-(50000/256);
TL0=-( 50000%256);
ET0=1;
TR0=1;
EA=1;
TT=0;
QQ=0;
RR=0;
Init_Max7219();
}
/****************** ***************************/
void time0(void) interrupt 1
{
TH0=-(50000/256);
TL0=-(50000 %256);
deda++;
}
/******************************************/
void conv (void)
{
if(deda>=20){deda=0;sec++;Write_Max7219(DIG_8,sec%10); Write_Max7219(DIG_7,sec/10); }
if(sec>=60){sec=0;min++; Write_Max7219(DIG_6 ,min%10); Write_Max7219(DIG_5,min/10);}
if(min>=60){min=0;hour++; Write_Max7219(DIG_4,hour%10); Write_Max7219(DIG_3,hour/10);}
if (hour>=24){hour=0;week++; Write_Max7219(DIG_2,week%10);}
if(week>7){week=1;}
if(hour==3) TT=1;
}
/** ***************************************/
void delay(uint k)
{
uint data i,j;
for(i=0;i
{;}}
}
/**************** *********************************/
uchar scan_key(void)
{
uchar temp;
P3=0x3f;
temp=P3 ;
if(temp!=0x3f)
{delay(20);
temp=P3;
if(temp!=0x3f) return temp;
}
return 0x3f;
}
/**************** ****************************/
void main(void)
{uchar key_flag;
init();
while(1)
{
conv() ;
key_flag=scan_key();
switch(key_flag)
{
case 0x3b:if(++min>59)min=0; delay(300); Write_Max7219(DIG_6,min%10); Write_Max7219(DIG_5,min/10);break;
case 0x37:if(++hour>23)hour=0; delay(300);Write_Max7219(DIG_4,hour%10); Write_Max7219(DIG_3,hour/10);break ;
case 0x2f:if(++week>7 )week=1; delay(300); Write_Max7219(DIG_2,week%10);break;
default: break;
}
}
}
Previous article:Single chip electronic password lock with password change
Next article:Several Precise Delays of 51 Single Chip Microcomputer
- Popular Resources
- Popular amplifiers
- 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
- 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
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Has anyone researched tinyos and nesc?
- The sensor is connected via Bluetooth and then reads the data from the mpu
- EEWORLD University Hall----Project Production: Intelligent Access Control System
- Ask for advice
- Study on TMS570LS3137
- The quickest way to set the plug-in through-hole pin pad of a multi-layer board to appear on only one side in Altium Designer
- Can 'ice' be used as a semiconductor material?
- 【NUCLEO-L552ZE Review】- 8 : TrustZone
- 【Qinheng Trial】8. FlashROM
- The Agilent oscilloscope cannot be started and keeps stopping at the self-test position. What should I do?