c51单片机

更新时间:2023-03-04 06:22:05 阅读: 评论:0

吃阿胶的禁忌-每日一个养生知识

c51单片机
2023年3月4日发(作者:猪肉皮冻的做法)4个按键控制

#include

#define uchar unsigned char

#define uint unsigned int



sbit key1=P3^4;

sbit key2=P3^5;

sbit key3=P3^6;

sbit key4=P3^7;

sbit dula=P2^6;

sbit wela=P2^7;



uchar code table[]={

0x3f,0x06,0x5b,0x4f,

0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,

0x39,0x5e,0x79,0x71};



void delay(uint);

void display(uchar);

void Inital();

void keyscan();



uchar number,num,numt0;

void main()

{

Inital();

while(1)

{

keyscan();

display(num);

}

}





void Inital()

{

EA=1;

ET0=1;

TMOD=0X01;

TH0=(65535-45872)/256;

TL0=(65535-45872)%256;

}



void display(uchar number)

{

char shi,ge;

shi=number/10;

ge =number%10;



dula=1;

P0=table[shi];

dula=0;

P0=0xff;

wela=1;

P0=0xfe;

wela=0;

//delay(5);



dula=1;

P0=table[ge];

dula=0;

P0=0xff;

wela=1;

P0=0xfd;

wela=0;

//delay(5);



}



void delay(uint time)

{

uint i,j;

for(i=0;i
for(j=0;j<120;j++);



}





void keyscan()

{

if(key1==0)

{

delay(10);

if(key1==0)

{

num++;

if(num==60)

{

num=0;

while(!key1);

}

}

}



if(key2==0)

{

delay(10);

if(key2==0)

{

if(num==0)

{

num=60;



}

num--;

while(!key2);

}

}



if(key3==0)

{

delay(10);

if(key3==0)

{

num=0;

while(!key3);

}

}



if(key4==0)

{

delay(10);

if(key4==0)

{



while(!key4);

TR0=~TR0;

}

}

}





void T0_time() interrupt 1

{

TH0=(65535-45872)/256;

TL0=(65535-45872)%256;

numt0++;

if(numt0==20)

{

numt0=0;

num++;

if(num==60)

{

num=0;



}





}





}



























//4x4键盘控制

#include

#define uint unsigned int

#define uchar unsigned char



sbit dula=P2^6;

sbit wela=P2^7;



uchar code table[]={

0x3f,0x06,0x5b,0x4f,

0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,

0x39,0x5e,0x79,0x71};



void Inital();

void display(uchar );



uchar temp,num;

uchar keyscan();



void delay(uint time)

{

uint x,y;

for(x=0;x
for(y=0;y<110;y++);

}



void main(void)

{

Inital();

while(1)

{

display(keyscan());

}



}





void Inital()

{

P0=0x3e;

dula=1;

dula=0;



wela=1;

P0=0x00;

wela=0;



delay(1000);





wela=1;

P0=0x80;

wela=0;

delay(1000);



}



void display(uchar show)

{

dula=1;

P0=table[show];

dula=0;



}









uchar keyscan()

{

uchar temp,num;

P3=0xfe;

temp=P3;

temp=temp&0xfe;

if(temp!=0xfe)

{

//delay(10);

temp=P3;

temp=temp&0xfe;

if(temp!=0xfe)

{

temp=P3;

switch(temp)

{

ca 0xee:

num=0;

break;

ca 0xde:

num=1;

break;

ca 0xbe:

num=2;

break;

ca 0x7e:

num=3;

break;



}

while(temp!=0xf0)

{

temp=P3;

temp=temp&0xf0;tttt

}

}

}





P3=0xfd;

temp=P3;

temp=temp&0xf0;

if(temp!=0xf0)

{

delay(10);



temp=P3;

temp=temp&0xf0;

if(temp!=0xf0)

{

temp=P3;

switch(temp)

{

ca 0xed:

num=4;break;

ca 0xdd:

num=5;break;

ca 0xbd:

num=6;break;

ca 0x7d:

num=7;break;



}

while(temp!=0xf0)

{

temp=P3;

temp=temp&0xf0;tttt

}

}

}





P3=0xfb;

temp=P3;

temp=temp&0xf0;

if(temp!=0xf0)

{

delay(10);

temp=P3;

temp=temp&0xf0;

if(temp!=0xf0)

{

temp=P3;

switch(temp)

{

ca 0xeb:

num=8;break;

ca 0xdb:

num=9;break;

ca 0xbb:

num=10;break;

ca 0x7b:

num=11;break;



}

while(temp!=0xf0)

{

temp=P3;

temp=temp&0xf0;tttt

}

}

}





P3=0xf7;

temp=P3;

temp=temp&0xf0;

if(temp!=0xf0)

{

delay(10);

temp=P3;

temp=temp&0xf0;

if(temp!=0xf0)

{

temp=P3;

switch(temp)

{

ca 0xe7:

num=12;break;

ca 0xd7:

num=13;break;

ca 0xb7:

num=14;break;

ca 0x77:

num=15;break;



}

while(temp!=0xf0)

{

temp=P3;

temp=temp&0xf0;tttt

}

}

}









return num;







}











本文发布于:2023-03-04 06:22:04,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/zhishi/a/1677882125122498.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:c51单片机.doc

本文 PDF 下载地址:c51单片机.pdf

上一篇:自我鉴定50字
下一篇:返回列表
标签:c51单片机
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 实用文体写作网旗下知识大全大全栏目是一个全百科类宝库! 优秀范文|法律文书|专利查询|