//////////////////Include header files and macro definitions//////////////////////////////////////
#include
#include
unsigned char #define uint
unsigned
int
///
... int0_ok=P3^2;
sbit int1_ok=P3^3;
///////////////////Digital tube segment latch////////////////////////////////////////
sbit duan=P0^0;
sbit wei=P0^1;
uchar bit1,bit2,bit3,bit4,bit5,bit6;///////////////Hour, minute, and second display codeuchar
fen=0;// Minute cacheuchar
miao=0;//Second cacheuchar
shi=0;//Hour cacheuchar
key_temp;/////Key temporary storage
//uchar key_old;
uchar key_count;//Key countuchar
key_back;/////Key backupuchar
key_data;//////Key
valueuchar key_con;////
uchar key_ok;
uchar int0_function=0;///Function 0, for adjustment
uchar int1_function=0;///Function 1, for operation and stop
uchar time;////Timing constant
uchar t2time;
#define KEYDELAY 25 /*First key delay times*/
#define KEYLOOP 10 /*Continuous key interval times, must be less than KEYDELAY*/
void shanshuo(uchar aa,uchar ii);
void init();
void sign(uchar i);
/////////////////Millisecond delay///////////////////////////////////////////////////////////
void delayms(uint i) //Error 0us
{
uint c;
unsigned char a,b;
for(c=i;c>0;c--)
for(b=142;b>0;b--)
for
(
a
=2;a>0;
a--
)
;
}
///
... tablewei[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//bit code
uchar code welcom[]={0xbf,0xbf,0xc0,0x8c,0x86,0xc8,0xbf,0xbf};//--OPEN-- 1
uchar code on[]={0x bf,0xbf,0xbf,0xc0,0xc8,0xbf,0xbf,0xbf};//---on--- 2
uchar code off[]={0xbf,0xbf,0xc0,0x8e,0x8e,0xbf,0xbf,0xbf};//--off--- 3
uchar code closed[]={0xbf,0xc6,0xc7,0xc0,0x92,0x86,0xf8,0xbf};//-closed- 4
/////////////////////////////////////////Digital tube display program////////////////////////////////////////////
void display(uchar duan1,uchar wei1)
{
P2=0xff;
duan=0;
wei=0;
P2=tableduan[duan1];
duan=1;
duan=0;
P2=tablewei[wei1];
wei=1;
wei=0;
delayms(1);
}
////////////////////////////////////Digital tube display program/////////////////////////////////////////////////////Digital tube display
bit calculation/////////////////////////////////////////
void jisuan()
{
bit1=shi/10;
bit2=shi%10;
bit3=fen/10;
bit4=fen%10;
bit5=miao/10;
bit6=miao%10;
/*
display(bit1,0);
display(bit2,1);
display(10,2);
display(bit3,3);
display(bit4,4);
display
(10,5);
display(bit5,6);
display
(
bit6,7)
;
*
/
}
///
... 0xfb:key=1;break;
case 0xf7:key=2;break;
case 0xef:key=3;break;
case 0xdf:key=4;break;
case 0xbf:key=5;break;
case 0x7f:key=6;break;
default:key=0;break;
}
return key;
}
////////////////////////////// /////Long press key value table///////////////////////////////////////////////////////
/*uchar key_data_con_jisuan(uchar dat)
{
uchar key;
switch(dat)
{
case 0xef:key=5;break;
case 0xdf:key=6;break;
default:key=0;break;
}
return key;
}
*/
////////////////////////////////////////////////Keyboard scan///////////////////////////////////////////////////////////////////////
void key_scan()
{
P3=0xff;
if((P3&0xff)!=0xff)
{
delayms(10);
key_temp=P3;
if(key_temp==key_back)
{
delayms(10);
key_count++;
if (key_count==KEYDELAY) //Continuous keys, if not, shield this if
{
key_ok=0;
key_data=key_data_jisuan(key_temp); //Key*
key_count=KEYDELAY-KEYLOOP;
}
}
else
{
key_count=0;
key_back=key_temp;
}
//key_ok=1;
}
else
{
if(key_count)
{
key_count=0;
key_data=key_data_jisuan(key_temp);
}
key_temp=0;
key_ok=1;
}
}[page]
//////////////////Initialization of Timer 0/////////////////////////////
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x3C;
TL0 = 0x0B0;
ET0 = 1;
//TR0 = 1;
//EA = 1;
}
void InitTimer1(void)
{
TMOD = 0x10;
TH1 = 0x3C;
TL1 = 0x0B0;
EA = 1;
// ET1 = 1;
// TR1 = 1;
}
////////////////////////////////Main function starts//////////////////////////////
void main()
{
uchar ss;
InitTimer0();
// InitTimer1();
while(1)
{
key_scan();
if(key_data==1)
{
key_data=0;
int0_function++;
if(int0_function==5)
{
int1_function=0;
ss=0;
int0_function=1;
}
}
if(key_data==2)
{
key_data=0;
int1_function++;
if(int1_function>=3) int1_function=1;
}
if(int0_function==0)
{
sign(1);
}
/////////////////////Hour setting//////////////////////////////////////////
if(int0_function==1)
{
TR0 = 0;
EA = 0;
// ET1 = 1;
// TR1 = 1;
light=1;
// shanshuo(0,1);
if(key_data==3)
{
key_data=0;
shi++;if(shi==24)shi=0;
}
if(key_data==4)
{
key_data=0;
shi--;if(shi==0)shi=23;
}
jisuan();
shanshuo(0,1);
for(ss=10;ss>0;ss--)
{
display(bit1,0);
bit2,1);
display(10,2);
display(bit3,3);
display(bit4,4);
display(10,5);
display(bit5,6);
display(bit6,7);
}
for(ss=10;ss>0;ss--)
{
// display(bit1,0);
// display(bit2,1);
display(10,2);
display(bit3,3);
display(bit4,4);
display(10,5) ;
display(bit5,6);
display(bit6,7);
}
}
//////////////////Minute setting//////////////////////////
if(int0_function==2)
{
TR0 = 0;
EA = 0;
// ET1 = 1;
// TR1 = 1;
light=1;
if(key_data==3)
{
key_data=0;
fen++;if(fen==60)fen=0;
}
if(key_data==4)
{
key_data=0;
fen--;if(fen==0)fen=59;
}
jisuan();
// shanshuo(0,2);
for(ss=10;ss>0;ss--)
{
display(bit1,0);
display(bit2,1);
display(10,2);
display(bit3,3 );
display(bit4,4);
display(10,5);
display(bit5,6);
display(bit6,7);
}
for(ss=10;ss>0;ss--)
{
display(bit1, 0);
display(bit2,1);
display(10,2);
// display(bit3,3);
// display(bit4,4);
display(10,5);
display(bit5,6);
display (bit6,7);
}
}
///////////////////////Second setting////////////////////////// ////
if(int0_function==3)
{
TR0 = 0;
EA = 0;
// ET1 = 1;
// TR1 = 1;
light=1;
if(key_data==3)
{
key_data=0;
miao++; if(miao==60)miao=0;
}
if(key_data==4)
{
key_data=0;
miao--;if(miao==0)miao=59;
}
jisuan();
// shanshuo(0, 3);
for(ss=10;ss>0;ss--)
{
display(bit1,0);
display(bit2,1);
display(10,2);
display(bit3,3);
display(bit4, 4);
display(10,5);
display(bit5,6);
display(bit6,7);
}
for(ss=10;ss>0;ss--)
{
display(bit1,0);
display(bit2,1);
display(10,2) ;
display(bit3,3);
display(bit4,4);
display(10,5);
// display(bit5,6);
// display(bit6,7);
}
}
if(int0_function==4)
{
display(bit1,0);
display(bit2,1);
display(10,2);
display(bit3,3);
display(bit4,4);
display(10,5);
display(bit5,6);
display (bit6,7);
}
//if(int0_function==6)
//{
// sign(6);
//}
////////////////////// //////Timing starts///////////////////////
if(int1_function==1)
{
TR0 = 1;
EA = 1;
int0_function=4;
// ET1 = 0;
// TR1 = 0;
if((shi==0)&&(fen==0)&&(miao==0))
{
light= 0;
}
jisuan();
shanshuo(0,0);
}
/////////////////Timing is over, turn off the timer and relay/////////////////
if(int1_function==2)
{
TR0 = 0;
EA = 0;
// ET1 = 1;
// TR1 = 1;
light=1;
int0_function=0;
int1_function=0;
jisuan();
sign(4);
}
// jisuan();
//shanshuo(0,0);
}
}
//////////////////Timer 0 interrupt service///////// ///////////////////
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x3C;
TL0 = 0x0B0;
//add your code here!
time++;
if(time==20)
{
time=0;
if(miao>0)miao--;
if((miao==0)&&(fen>0)){miao=59;fen--;}
if((fen==0)&&( shi>0)){fen=59;shi--;}
}
}[page]
void Timer1Interrupt(void) interrupt 3
{
TH1 = 0x3C;
TL1 = 0x0B0;
//add your code here!
t2time++;
if(t2time==20)t2time=0;
}
void shanshuo(uchar aa,uchar i)///If i=1, it flashes in hours; if i=2, it flashes in minutes; if i=3, it flashes in seconds
{
//uchar i; //flash frequencyif
(aa==4|aa==0)
{
for(i;i>0;i--)
{
display(bit1,0);
display(bit2,1);
display(10,2);
display(bit3,3);
display(bit4,4);
display(10,5);
display(bit5,6);
display(bit6,7);
}
}
if(aa==1 )
{
for(i;i>0;i--)
{
// display(bit1,0);
// display(bit2,1);
display(10,2);
display(bit3,3);
display(bit4 ,4);
display(10,5);
display(bit5,6);
display(bit6,7);
}
}
if(aa==2)
{
for(i;i>0;i--)
{
display(bit1,0);
display(bit2,1);
display(10,2);
// display(bit3, 3);
// display(bit4,4);
display(10,5);
display(bit5,6);
display(bit6,7);
}
}
if(aa==3)
{
for(i;i>0 ;i--)
{
display(bit1,0);
display(bit2,1);
display(10,2);
display(bit3,3);
display(bit4,4);
display(10,5);
// display(bit5,6);
// display(bit6,7);
}
}
for(i;i>0;i--)
{
display(bit1,0);
display(bit2,1);
display(10,2 );
display(bit3,3);
display(bit4,4);
display(10,5);
display(bit5,6);
display(bit6,7);
}
}
////////////////////Blinking Program///////////////////////////////////////////////////////////////////////////////////////////
void sign(uchar i )// 1, display open, display on 3, display off 4, display closed
{
uchar bb;
if(i==0)
{
P2=0x00;
P0=0x03;
}
if(i==1)
{
for(bb=0;bb<8;bb++)
{
P2=0xff;
duan=0;
wei=0;
P2=welcom[bb];
duan=1;
//delayms(1);
duan=0;
P2=tablewei[bb];
wei=1;
//delayms(1);
wei=0;
delayms(1);
}
}
if(i==2)
{
for(bb=0;bb<8;bb++)
{
P2=0xff;
duan=0;
wei=0;
P2=on[bb];
duan=1;
//delayms(1);
duan=0;
P2=tablewei[bb];
wei=1;
//delayms(1);
wei=0;
1);
}
}
if(i==3)
{
for(bb=0;bb<8;bb++)
{
P2=0xff;
duan=0;
wei=0;
P2=off[bb];
duan=1;
//delayms(1);
duan=0;
P2=tablewei[bb];
wei=1;
//delayms(1);
wei=0;
delayms(1);
}
}
if(i==4|i==0)
{
for(bb=0;bb<8;bb++)
{
P2=0xff;
duan=0;
wei=0;
P2=closed[bb];
duan=1;
//delayms(1);
duan=0;
P2=tablewei[bb];
wei=1;
//delayms(1);
wei=0;
delayms(1);
}
}
}
Previous article:From lighting the first lamp to the running lamp
Next article:51 MCU-Interrupt Function Basics
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- What does DIN VDE V 0884-11:2017-01 mean for digital isolator certification?
- Do CAN and LIN in automotive BCM and ECU need to be isolated? Do switching quantities need to be isolated? How to design grounding?
- Let's take a look at how UWB compares to other standards
- 【Silicon Labs BG22-EK4108A Bluetooth Development Evaluation】+Connection Test Using Android APP
- How to encapsulate GPIO into nodes.
- [RVB2601 Creative Application Development] Simulating UART 3 to implement FIFO reception
- Please God save the child
- [AT-START-F403A Review] Part 2 F403 waveform output test and maximum frequency test
- [AT-START-F403A Evaluation] Part 5 - FreeRTOS system based on IAR environment security library (sLib) function evaluation
- Are you using Python? Be careful of being complained about infringement! [MicroPython Open Source Mutual Aid Alliance Established]