The key controls the character string to move and display on the digital tube

Publisher:真情相伴Latest update time:2016-09-23 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//---------------------------------

//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  for(y=0;y<112;y++);

}
//=
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);
 }
 }

Reference address:The key controls the character string to move and display on the digital tube

Previous article:Simple addition calculator single chip c programming
Next article:Write the current time to 24C02

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号