MCU source code:
/***************************************************************
Name: 16*64 dot matrix
Crystal: 22.1184M
time:
External device: 16*64 dot matrix, ds1302
Wiring: See DS1302.h, DS18B20.h and this main file
***************************************************************/
#include #include "DS1302.h" #include "DS18B20.h" #include "nongli.h" #include "zimo.h" #define H_PORT P0 //ABCD P1 sbit RData = P2^0; //RData=P2^0,GData=P2^1 sbit GData = P2^1; sbit L_CLK = P2^2; sbit L_STB = P2^3; sbit R_OE = P2^4; //R EN=P2^4,G EN=P2^5 sbit G_OE = P2^5; //sbit Data=P2^1; //RData=P2^0,GData=P2^1 //sbit OE=P2^6; //R EN=P2^5,G EN=P2^6 sbit key_add=P3^1; sbit key_dec=P3^2; sbit key_adj=P3^0; sbit key_esc=P3^3; /* //My own home wiring sbit H_CLK = P2^5; sbit H_D = P2^4; sbit L_CLK = P2^0; ** sbit L_D = P2^2; ** sbit L_STB = P2^1; ** sbit L_OE = P2^6; ** sbit key_add = P3^7; sbit key_dec = P3^5; sbit key_adj= P3^6; sbit key_esc = P3^4; */ #define FESTIVAL_MAX 9 //Define the number of lunar festivals #define KEY_VAL 5 //Define the key feel /*#define DISP_EN() { R_OE=1 //4094 high level output enable G_OE=1 } #define DISP_DIS() { R_OE=0; G_OE=0; } */ SYSTEMTIME CurrentTime; unsigned char status=0; //button status unsigned char disp_mode=0; //display status unsigned char offset=0; //Variable for moving display unsigned char disrow=0; //Current scan line unsigned char k=0; //words to be filled into buff unsigned int t_counter=0,stop_counter=0,stop_time=0; unsigned char f1=18,f2=18,f3=18,f4=18,f5=18,f6=18; //18 will not result in all pages turning at the beginning. bit switch_flag=0,stop_bit=0; bit one_sec_flag=0,half_sec_flag; bit nongli_flag=0,nongli_change_flag=0,festival_flag=0; unsigned char T_int,T_dec; //Calculate temperature unsigned char temp_time[6]; //Used for page turning clock unsigned char festival_num; //festival count bit add_flag=0; bit dec_flag=0; bit adj_flag=0; bit esc_flag=0; unsigned char ka=0,kb=0,kc=0,kd=0; //key press unsigned char alarm_hour,alarm_min; bit alarm_enable=0,alarm_flag=0; unsigned char code mode[4]={0,1,7,8}; //The arrangement of several display modes is as follows //0: Flowing display of year, month and day + fixed time page turning clock //1: Page turning clock //7: All flow display //8: Temperature unsigned char date[53]= { 10,10,10,10,10,10,10,10, //8 spaces at the beginning 2,0, //21st century 0,9, //Annual data No.10,11 49,50, //“year” 0,1, //Monthly data No.14,15 51,52, //"moon" 0,1, //Daily data No.18,19 53,54, //"day" 10, //space 55,56,57,58, //"week" 25,26, //Day of the week No.27,28 10, //space 0,0, //Hourly data No.30,31 11, // : No.32 0,0, //Minute data No.33,34 11, // : No.35 0,0, //Second data No.36,37 10, //space 10,10,12,10,13,14, //Temperature No.39,40,42 10,10,10,10,10,10,10,10, //MAX No.52 }; unsigned char code moon_date[48]= { 10,10,10,10,10,10,10,10, //8 spaces at the beginning 10,10, //No.8,9 10,10, //No.10,11 49,50, //“year” 10,10, //No.14,15 10,10, //No.16,17 51,52, //"moon" 10,10, //No.20,21 10,10, //No.22,23 10,10,10,10,10,10,10,10, //8 spaces at the beginning 10,10,10,10,10,10,10,10, //8 spaces at the beginning 10,10,10,10,10,10,10,10, //8 spaces at the beginning }; unsigned char code init_date[]= { 10,10,10,10,10,10,10,10, //8 spaces at the beginning 2,0, //21st century 0,9, //Annual data No.10,11 49,50, //“year” 0,1, //Monthly data No.14,15 51,52, //"moon" 0,1, //Daily data No.18,19 53,54, //"day" 10, //space 55,56,57,58, //"week" 25,26, //Day of the week No.27,28 10, //space 0,0, //Hourly data No.30,31 11, // : No.32 0,0, //Minute data No.33,34 11, // : No.35 0,0, //Second data No.36,37 10, //space 10,10,12,10,13,14, //Temperature No.39,40,42 10,10,10,10,10,10,10,10, //MAX No.52 }; unsigned char code week_data[]={00,25,27,29,31,33,35,53}; //Mon, Tue, Wed, Thu, Fri, Sat, Sun unsigned char code moon_data1[]={45,43,47,29}; //The 10th and 23rd day of the lunar month unsigned char code festival_table[][2]= { {1,1}, //0 Spring Festival {1,15}, //1 Lantern Festival {44,44}, //2 Qingming Festival The solar calendar is difficult to determine {5,5}, //3 Dragon Boat Festival {7,15}, //4 Zhongyuan {8,15}, //5 Mid-Autumn Festival {9,9}, //6 Double Ninth Festival {11,7}, //7 Winter Solstice {12,30}, //8 New Year's Eve }; unsigned char code qingming_table[6]= { 0x77, //2000~2007 0x33, //2008~2015 0x33, //2016~2023 0x33, //2024~2031 0x33, //2032~2039 0x33, //2040~2047 }; /*-----------Linear arrangement, no need to look up a table--------- unsigned char code festival_data[]= { } -------------------------------------*/ void delay_nms(unsigned int count); void set_row(unsigned char row); void sendRbyte(unsigned char wdata); void sendR2byte(unsigned char wdata,unsigned char n); void Timer_init(void); void time_to_buff(void); void time_to_buff_all(void); void update_buff(void); void key_scan(void); void display(unsigned char mode); void get_temp(void); void shutter_clock(void); void festival_check(void); void alarm_check(void); void alarm(void); void main(void) { Initial_DS1302(); time_to_buff_all(); Timer_init(); while(1) { update_buff(); for(disrow=0;disrow<16;disrow++) //disrow, the current scanned row { L_STB=0; set_row(disrow); //Output of row 595. Light up rows 1 to 16 in sequence. display(disp_mode); L_STB=0; L_STB=1; R_OE=0; //Column 595 output G_OE=0; delay_nms(1); //The delay here, please adjust it according to the flickering state of the dot matrix. The flickering cannot be simulated during simulation. The delay here can adjust the flow speed R_OE=1; G_OE=1; /******************************************************** Original code********************************************************/ /* display(disp_mode); DISP_DIS(); set_row(disrow); //Output of row 4094. Light up rows 1 to 16 in sequence. L_STB=1; DISP_EN(); delay_nms(1); //The delay here, please adjust it according to the flickering state of the dot matrix. The flickering cannot be simulated during simulation. /************************************************************ Original code**************************************************/ } if(stop_counter>stop_time) { disp_mode=0; offset++; stop_counter=0; stop_bit=0; } if(stop_bit==0) offset++; if(disp_mode==1) { if(f1<200) f1++; if(f2<200) f2++; if(f3<200) f3++; if(f4<200) f4++; if(f5<200) f5++; if(f6<200) f6++; } if(nongli_flag==0) key_scan(); //Errors may occur when adjusting the lunar calendar, so I will block it to save effort } } void Timer_init(void) //12.5ms interrupt once { EA=0; ET0=1; //Open timer interrupt TMOD=0x01; //Timer 0 mode 1 TH0=(65536-50000)/256; //22.1184M crystal oscillator uses this TL0=(65536-50000)%256; //TH0=(65536-46080)/256; //TL0=(65536-46080)%256; TR0=1; //Start the timer EA=1; } void T0_ISP(void) interrupt 1 using 3 //timer interrupt { TH0=(65536-50000)/256; TL0=(65536-50000)%256; //TH0=(65536-46080)/256; //22.1184M crystal oscillator uses this //TL0=(65536-46080)%256; t_counter++; if(t_counter==20) half_sec_flag=1; if(t_counter==40) {t_counter=0;one_sec_flag=1;} if(stop_bit==1) stop_counter++; if(ka!=0) { ka--; if(ka==0 && key_add==0) add_flag=1; } else if(key_add==0)ka=KEY_VAL; if(kb!=0) { kb--; if(kb==0 && key_dec==0) dec_flag=1; } else if(key_dec==0)kb=KEY_VAL; if(kc!=0) { kc--; if(kc==0 && key_adj==0) adj_flag=1; } else if(key_adj==0)kc=KEY_VAL; if(kd!=0) { kd--; if(kd==0 && key_esc==0) esc_flag=1; } else if(key_esc==0)kd=KEY_VAL; } void update_buff(void) { unsigned char i; if(nongli_change_flag==1) { if(nongli_flag==1) { for(i=0;i<46;i++) date[i]=moon_date[i]; DS1302_GetTime_ALL(&CurrentTime); nongliCONV(); date[8]= (CurrentTime.Year+100-84)%10*2+59; //Starting from "甲" date[9]= (CurrentTime.Year+100-84)%10*2+60; date[10]=(CurrentTime.Year+100-84)%12*2+79; //Start from "Zi"
Previous article:51 MCU NY3P035 voice broadcast source program
Next article:Single chip LCD12864 with font library can call display function can reverse display source program
- 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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Let's talk about DSP audio processing
- How to download STBLESensor?
- 【LSM6DSOX's MLC machine learning understanding】--Introduction to machine learning
- CPU card programming process
- Blind guess: How does the ESP32 “Piranha Plant” design achieve the opening and closing of its petals?
- The calculation problem of frequency count value
- 13.56MHz ultra-low power contactless card reader chip Si522_Provide technical support
- EEWORLD University Hall----Sharing the application solution of sensorless FOC portable refrigerator based on Lingdong MM32SPIN series MCU
- I was fired for refusing to bring my computer home during the holidays, but the result was comfortable!
- DIY crystal radio that does not require power