//Key control string moves and displays on digital tube
//1. P30 controls moving direction
//2. P31 acceleration
//3. P32 deceleration
//4. The buzzer sounds every time the movement is complete;
//
//
#include
#define uint unsigned int
#define uchar unsigned char
uchar code dula[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x00,0x40};
uchar wula[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0,0,0};
uchar table[6]={1,2,0,0,4,8};//string to be displayed
uchar temp[6]={10,10,10,10,10,10};//display buffer
sbit arrow=P3^0;//30 controls the moving direction
sbit jia=P3^1;//P31 acceleration
sbit jian=P3^2;//P32 deceleration
sbit beep=P1^5;//The buzzer sounds every time the movement is complete;
uchar num1,num2,miao,flag5ms,flag100ms,flag1s,i,N,flagbeep;
bit flagarrow;
void delay(uint z);
void display();
void tinic();
void main()
{ N=5;
tinic();
while(1)
{
if(arrow==0)
delay(100);
if(arrow==0)
{while(arrow==0);
flagarrow=~flagarrow; miao=0;
for(i=0;i<6;i++)//Press once to change the direction, clear the display buffer
temp[i]=10; //No display
}
if(jia==0)
delay(100);
if(jia==0)
{while(jia==0);if(N<2) N=1;else N--;}
if(jian==0)
delay(100);
if(jian==0)
{while(jian==0);N++;if(N>10) N=10;}
display();
if(flagbeep=1)
{flagbeep=0;
if(miao<1)
beep=0;
else beep=1;}
}
}
//-------------------
void timer0() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
num1++;
flag5ms=1;
if(num1==20)
{
num1=0;
num2++;
flag100ms=1;
if(num2==N)
{num2=0;
miao++;
if(miao>5)
{miao=0;flagbeep=1;
for(i=0;i<6;i++)//Clear the display buffer after moving once
temp[i]=10;}//Do not display
flag1s=1;}
}
}
//----------------------
void tinic()
{
TMOD=0x01;
ET0=1;
EA=1;
TH0=(65536-5000)/256 ;
TL0=(65536-5000)%256;
TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=0;x
}
//=
void display()
{
uchar j;
if(flagarrow==1)
switch(miao)
{
case 0:temp[0]=table[5];break;
case 1:temp[0]=table[4 ];
temp[1]=table[5];break;
case 2:temp[0]=table[3];
temp[1]=table[4];
temp[2]=table[5];break;
case 3:temp[0]=table[2];
temp[1]=table[3];
temp[2]=table[4];
temp[3]=table[5];break;
case 4:temp[0 ]=table[1];
temp[1]=table[2];
temp[2]=table[3];
temp[3]=table[4];
temp[4]=table[5];break;
case 5:temp[0]=table[0];
temp[1]=table[1];
temp[2]=table[2];
temp[3]=table[3];
temp[4]=table[4];
temp[5]=table[5];break;
}
if(flagarrow==0)
switch(miao)
{
case 0:temp[ 5]=table[0];break;
case 1:temp[4]=table[0];
temp[5]=table[1];break;
case 2:temp[3]=table[0];
temp[ 4]=table[1];
temp[5]=table[2];break;
case 3:temp[2]=table[0];
temp[3]=table[1];
temp[4]=table[ 2];
temp[5]=table[3];break;
case 4:temp[1]=table[0];
temp[2]=table[1];
temp[3]=table[2];
temp[ 4]=table[3];
temp[5]=table[4];break;
case 5:temp[0]=table[0];
temp[1]=table[1];
temp[2]=table[2];
temp[3]=table[3];
temp[4]=table[4];
temp[5]=table[5]; break;
}
for(j=0;j<6;j++)
{P0=dula[temp[j]];
P2=wula[j];
delay(5);
}
}
Previous article:Simple addition calculator single chip c programming
Next article:Write the current time to 24C02
- 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
- 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
- Capacitor charging time, MOS gate drive, TL431 reference, op amp followed by ADC sampling, composite tube and complementary push-pull advantages and disadvantages
- Serial communication can also communicate without sharing the same ground. What is the reason?
- C28x Software Tips: How to View Software Examples and Documentation
- CC2500 Migration Instructions
- [DWIN Serial Port Screen] Nucleic Acid Sampling Registration System 2: Prepare Background Image
- VIAVI's latest report shows: 5G services now cover 1,662 cities around the world. Have you felt it? ? ?
- Switching Power Supply Interest Group 11th Task
- The zigbee terminal sets the PAN ID by pressing a button to join the set ID network
- Far away, yet close at hand
- The power cord is too long and the power-on voltage is too high. Should I use a TVS tube?