单片机C语言程序文档格式.docx
- 文档编号:21319988
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:16
- 大小:17.24KB
单片机C语言程序文档格式.docx
《单片机C语言程序文档格式.docx》由会员分享,可在线阅读,更多相关《单片机C语言程序文档格式.docx(16页珍藏版)》请在冰豆网上搜索。
sbitP1_0=P1^0;
unsignedcharcount;
voiddely500(void)
unsignedchari;
for(i=500;
_nop_();
voidmain(void)
if(P1_7==0)
for(count=200;
count>
count--)
P1_0=~P1_0;
dely500();
采用定时器/计数器工作方式,同时采用中断服务程序来实现闪烁功能.
unsignedchari,j;
voiddelay1()
for(i=0;
i<
200;
i++)
for(j=0;
j<
248;
j++);
voiddelay2()
240;
TMOD=0x06;
TH0=246;
TL0=246;
IE=0x82;
P1_0=1;
TR0=1;
while
(1);
voidtimer0()interrupt1
unsignedchark;
for(k=0;
k<
=5;
k++)
{P1_0=0;
delay1();
delay2();
}}
独立式键盘电路设计1.
voiddelay10ms(void)
unsignedchari,j;
for(i=20;
for(j=248;
j--);
unsignedcharx;
P1=0xff;
x=1;
while(x==1)
x=P3;
x=~x;
delay10ms();
if(x==1)continue;
switch(x)
case0x3e:
P1=0xfe;
break;
case0x3d:
P1=0xfd;
case0x3c:
P1=0xfb;
case0x37:
P1=0xf7;
case0x2f:
P1=0xef;
case0x1f:
P1=0xdf;
default:
break;
独立式键盘电路设计2.
P3=0xff;
x=P1;
case0xfe:
P3=0xfe;
case0xfd:
P3=0xfd;
case0xfb:
P3=0xfb;
case0xf7:
P3=0xf7;
case0xef:
P3=0xef;
case0xdf:
P3=0xdf;
case0xbf:
P3=0xbf;
case0x7f:
P3=0x7f;
多个数码管动态显示程序设计.
\#include<
unsignedcharcodeTab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d};
unsignedcharcodeCol[]={0x01,0x02,0x04,0x08,0x10,0x20};
xdataunsignedcharOUTBIT_at_0x8002;
xdataunsignedcharOUTSEG_at_0x8004;
voiddelay()
unsignedcharj;
for(j=1;
7;
j++)
OUTSEG=Tab[j];
OUTBIT=Col[j-1];
delay();
OUTBIT=0x00;
霓虹灯控制系统程序设计
unsignedchari10,i8,i6;
unsignedcharmod1,mod2;
bitF;
i10=10;
i8=8;
i6=6;
mod1=0x01;
mod2=0xAA;
F=0;
TMOD=0x10;
TH1=0x3C;
TL1=0xB0;
IE=0x8A;
TR1=1;
}
voidtimer0()interrupt3using1
i10--;
if(i10==0)
if(F==0)
P1=mod1;
mod1=mod1<
<
1;
i8--;
if(i8==0)
F=1;
else
P1=mod2;
mod2=~mod2;
i6--;
if(i6==0)
一键多功能按键识别程序设计
unsignedcharID;
sbitP3_0=P3^0;
sbitP1_3=P1^3;
sbitP1_1=P1^1;
sbitP1_2=P1^2;
sbitP1_0=P1^0;
{delay10ms();
voidmain(void)
{while
(1)
{if(P3_0==0)
if(P3_0==0)
ID++;
if(ID==0)
ID=0;
while(P3_0==0);
switch(ID)
{case0:
P1=P1|0xfe;
case1:
P1=P1|0xfd;
P1_1=~P1_1;
case2:
P1=P1|0xfb;
P1_2=~P1_2;
case3:
P1=P1|0xf7;
P1_3=~P1_3;
电子时钟.其中包括整点报时,时间调整.
#defineLEDLen6
#definePB12//164时钟位
#definePB01//164数据位
//位控制口
//段控制口
xdataunsignedcharIN_at_0x8001;
//键盘读入口
unsignedcharLEDBuf[LEDLen];
//显示缓冲
unsignedcharx,y;
codeunsignedcharLEDMAP[]={//八段管显示码
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
};
sbitP1_5=P1^5;
//整点报时
//延时子程序:
voidDelay(unsignedcharCNT)
while(CNT--!
=0)
for(i=100;
i!
=0;
i--);
voidDisplayLED()
unsignedcharPos;
unsignedcharLED;
Pos=0x20;
//从左边开始显示
for(i=0;
i<
LEDLen;
i++){
OUTBIT=0;
//关所有八段管
LED=LEDBuf[i];
OUTSEG=LED;
OUTBIT=Pos;
//显示一位八段管
Delay
(1);
Pos>
>
=1;
//显示下一位
codeunsignedcharKeyTable[]={//键码定义
0x16,0x15,0x14,0xff,
0x13,0x12,0x11,0x10,
0x0d,0x0c,0x0b,0x0a,
0x0e,0x03,0x06,0x09,
0x0f,0x02,0x05,0x08,
0x00,0x01,0x04,0x07
unsignedcharTestKey()
//输出线置为0
return(~IN&
0x0f);
//读入键状态(高四位不用)
unsignedcharGetKey()
i=6;
//找出键所在列
do{
OUTBIT=~Pos;
k=~IN&
0x0f;
}while((--i!
=0)&
&
(k==0));
//键值=列x4+行
if(k!
=0)
i*=4;
if(k&
2)
i+=1;
elseif(k&
4)
i+=2;
8)
i+=3;
doDelay(10);
while(TestKey());
//等键释放
return(KeyTable[i]);
//取出键码
elsereturn(0xff);
//===========================================================
#defineTick10000//10000x100us=1s
#defineT100us(256-50)//100us时间常数(6M)
unsignedcharHour,Minute,Second;
unsignedintC100us;
//100us记数单元
//主程序
TMOD=0x02;
//方式2,定时器
TH0=T100us;
TL0=T100us;
IE=0x82;
//EA=1,IT0=1
Hour=0;
Minute=0;
Second=0;
C100us=Tick;
TR0=1;
//启动定时器0
while
(1)
LEDBuf[0]=LEDMAP[Hour/10];
LEDBuf[1]=LEDMAP[Hour%10]|0x80;
LEDBuf[2]=LEDMAP[Minute/10];
LEDBuf[3]=LEDMAP[Minute%10]|0x80;
LEDBuf[4]=LEDMAP[Second/10];
LEDBuf[5]=LEDMAP[Second%10];
DisplayLED();
if(TestKey())
{x=GetKey();
case0x00:
Second=Second+1;
if(Second>
59)Second=0;
case0x0f:
Minute=Minute+1;
if(Minute>
59)Minute=0;
case0x0e:
Hour=Hour+1;
if(Hour>
23)Hour=0;
case0x01:
if(Second==0)Second=59;
Second=Second-1;
case0x02:
if(Minute==0)Minute=59;
Minute=Minute-1;
case0x03:
if(Hour==0)Hour=23;
Hour=Hour-1;
if((Second==0)&
(Minute==0))//整点报时
{
for(y=Hour;
y>
y--)
P1_5=~P1_5;
Delay(100);
//中断程序
voidT0Int()interrupt1
C100us--;
if(C100us==0){
//100us记数器为0,重置记数器
Second++;
if(Second==60){
Minute++;
if(Minute==60)
Hour++;
if(Hour==24)Hour=0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 语言 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)