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

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.