Key Control Motor display speed

Source: Internet
Author: User



Program flowchart


Code

# Include <reg52.h>
# Define uchar unsigned char
Sbit Dula = P2 ^ 6;
Sbit wela = P2 ^ 7;
Sbit jia_key = P3 ^ 6;
Sbit jian_key = P3 ^ 7;
Sbit zf_key = P3 ^ 5;
Bit Flag = 0;
Uchar num = 0, show_num = 2, maichong = 4, table_begin = 0;
Uchar code Table1 [] = {0x01,0x02,0x04,0x08,0x08,0x04,0x02,0x01 };
Uchar code table [] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79,0x71 };
Void delay (uchar I)
{
Uchar J, K;
For (j = I; j> 0; j --)
For (k = 125; k> 0; k --);
}
Void display ()
{
Dula = 0;
P0 = table [show_num];
Dula = 1;
Dula = 0;
Wela = 0;
P0 = 0xfe;
Wela = 1;
Wela = 0;
Delay (5 );
P0 = table [0];
Dula = 1;
Dula = 0;
P0 = 0xfd;
Wela = 1;
Wela = 0;
Delay (5 );
}
Void key ()
{
If (jia_key = 0)
{
Delay (5 );
If (jia_key = 0)
{
Num ++;
If (num = 4)
Num = 3;
While (jia_key = 0 );
}
}
If (jian_key = 0)
{
Delay (5 );
If (jian_key = 0)
{
If (num! = 0)
Num --;
Else
Num = 0;
While (jian_key = 0 );
}
}
If (zf_key = 0)
{
Delay (5 );
If (zf_key = 0)
{
Flag = ~ Flag;
While (zf_key = 0 );
}
}
}


Void dispose ()
{
Switch (Num)
{
Case 0:
Show_num = 2;
Maichong = 5;
Break;
Case 1:
Show_num = 4;
Maichong = 4;
Break;
Case 2:
Show_num = 6;
Maichong = 6;
Break;
Case 3:
Show_num = 8;
Maichong = 2;
Break;
}
If (flag = 0)
{
Table_begin = 0;
}
Else
Table_begin = 4;
}


Void qudong ()
{
Uchar I, J;
For (j = 0 + table_begin; j <4 + table_begin; j ++)
{
P1 = Table1 [J];
For (I = 0; I <maichong; I ++)
{
Display ();
}
}
}


Void main ()
{
While (1)
{
Key ();
Dispose ();
Qudong ();
}
}


Http://download.csdn.net/my/uploads/1

Key Control Motor display speed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.