单片机程序大全毕业资料文档格式.docx

上传人:b****3 文档编号:13412377 上传时间:2022-10-10 格式:DOCX 页数:20 大小:18.87KB
下载 相关 举报
单片机程序大全毕业资料文档格式.docx_第1页
第1页 / 共20页
单片机程序大全毕业资料文档格式.docx_第2页
第2页 / 共20页
单片机程序大全毕业资料文档格式.docx_第3页
第3页 / 共20页
单片机程序大全毕业资料文档格式.docx_第4页
第4页 / 共20页
单片机程序大全毕业资料文档格式.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

单片机程序大全毕业资料文档格式.docx

《单片机程序大全毕业资料文档格式.docx》由会员分享,可在线阅读,更多相关《单片机程序大全毕业资料文档格式.docx(20页珍藏版)》请在冰豆网上搜索。

单片机程序大全毕业资料文档格式.docx

voiddelay500us()

unsignedcharj;

for(j=0;

57;

j++)//500us基准延时程序

}

voidmain()

{uchart;

P27=0;

while

(1){

if(K5==0){

delay1ms(15);

if(K5==0){

for(t=0;

t<

100;

t++)

{beep();

num=num+1;

if(num==16){

num=0;

}

while(!

K5);

//等待按键释放

P0=s8[num];

#defineucharunsignedchar//数据类型的宏定义

#defineuintunsignedint//数据类型的宏定义

unsignedcharcodetable[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xBF};

//共阳数码管显示字型码数组10111111"

-"

ucharj;

{

j++);

//1ms基准延时程序

voiddisplay(unsignedchari)

{

P27=0;

//选通最有端的数码管显示

P0=table[i];

//显示i参数传来的字型码

}

voidmain(void)

unsignedchartemp;

display(16);

//初始显示"

while

(1)

P1=0xff;

//先向P1口写1;

端口读状态

P1=0xf0;

temp=P1;

if(temp!

=0xf0)

{

=0xf0)

P1=0xfe;

temp=P1;

switch(temp)

case(0xee):

display(0);

break;

case(0xde):

display

(1);

case(0xbe):

display

(2);

case(0x7e):

display(3);

P1=0xfd;

temp=P1;

case(0xed):

display(4);

case(0xdd):

display(5);

case(0xbd):

display(6);

case(0x7d):

display(7);

P1=0xfb;

case(0xeb):

display(8);

case(0xdb):

display(9);

case(0xbb):

display(10);

case(0x7b):

display(11);

P1=0xf7;

case(0xe7):

display(12);

case(0xd7):

display(13);

case(0xb7):

display(14);

case(0x77):

display(15);

/*行线接P1.0-P1.3,列线接P1.4-P1.7。

根据线反转法扫描键盘返回的键值编码查键值编码表,从而得到键值并送数码管显示。

开机时,数码管显示“-”。

*/

#include<

intrins.h>

ucharkey;

unsignedcharcodedisp_code[]={

0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};

unsignedcharcodekey_code[]={

0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d,

0xeb,0xdb,0xbb,0x7b,0xe7,0xd7,0xb7,0x77};

{;

voidbeep()//产生1KHZ频率声音的函数

/**********************************************************

键盘扫描子函数

**********************************************************/

ucharkeyscan()

ucharscan1,scan2,keycode,j;

P1=0xf0;

scan1=P1;

if((scan1&

0xf0)!

=0xf0)//判键是否按下

delay1ms(20);

//延时20ms

=0xf0)//二次判键是否按下

P1=0x0f;

//线反转法的核心

scan2=P1;

keycode=scan1|scan2;

//组合成键编码

=15;

j++)

if(keycode==key_code[j])//查表得键值

key=j;

return(key);

else

P1=0xff;

//P1口写1输入状态

return(16);

//"

main()

uchartt;

P0=0xbf;

P27=0;

//数码管显示"

P1=0xff;

while

(1)

if((P1&

=0xf0){

keyscan();

P0=disp_code[key];

for(tt=0;

tt<

200;

tt++)

delay1ms(200);

中断

#defineuintunsignedint

#defineucharunsignedchar

sbitdula=P2^6;

sbitwela=P2^7;

sbitd1=P1^0;

ucharcodetable[]={

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

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

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

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

voiddelay(uintz);

EA=1;

//开总中断

EX0=1;

//开外部中断0

//IT0=1;

//TCON=0x01;

wela=1;

//11101010

P0=0xea;

wela=0;

for(num=0;

num<

16;

num++)

{

d1=1;

dula=1;

P0=table[num];

dula=0;

delay(1000);

}

voiddelay(uintz)

uintx,y;

for(x=z;

x>

0;

x--)

for(y=110;

y>

y--);

voidexter0()interrupt0

d1=0;

定时器

ucharaa,num;

aa=0;

//TMOD=0X00;

//设定定时器0为工作方式0

TMOD=0X01;

//设定定时器0为工作方式1

//TH0=(8192-5000)/32;

//TL0=(8192-5000)%32;

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

ET0=1;

//开定时器0中断

TR0=1;

//启动定时器0

P0=0x24;

dula=1;

P0=0x3f;

dula=0;

if(aa==20)

{

aa=0;

num++;

if(num==10)

num=0;

dula=1;

P0=table[num];

dula=0;

}

}

voidtimer0()interrupt1

//

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1