单片机实训报告课案Word格式文档下载.docx
《单片机实训报告课案Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《单片机实训报告课案Word格式文档下载.docx(43页珍藏版)》请在冰点文库上搜索。
![单片机实训报告课案Word格式文档下载.docx](https://file1.bingdoc.com/fileroot1/2023-5/6/0a5d32db-c3bf-4076-b650-0c23af6b54c3/0a5d32db-c3bf-4076-b650-0c23af6b54c31.gif)
®
时º
¡
À
voidDelayMS(uintx)
{
uchari;
while(x--)
for(i=0;
i<
120;
i++);
}
//主¡
Â
程¨
¬
序¨
°
voidmain()
P2=0x01;
while
(1)
7;
i++)
P2=_crol_(P2,1);
//P2的Ì
?
值¦
Ì
向¨
左Á
¨
循-环¡
¤
移°
动¡
¥
DelayMS(150);
P2=_cror_(P2,1);
右®
}
周三:
交通灯:
LED模拟交通灯
东西向绿灯亮若干秒,黄灯闪烁5次后红灯亮,红灯亮后,南北向由红灯变为绿灯,若干秒后南北向黄灯闪烁5此后变红灯,东西向变绿灯,如此重复。
交通灯C语言程序
sbitRED_A=P0^0;
//东?
西¡
灯Ì
sbitYELLOW_A=P0^1;
sbitGREEN_A=P0^2;
sbitRED_B=P0^3;
//南?
北À
sbitYELLOW_B=P0^4;
sbitGREEN_B=P0^5;
ucharFlash_Count=0,Operation_Type=1;
//闪¦
¢
烁?
次ä
数º
y,ê
操¨
´
作Á
类¤
型¨
ª
变À
量¢
while(x--)for(i=0;
//交?
通ª
§
切D换?
voidTraffic_Light()
switch(Operation_Type)
case1:
绿¨
与®
南?
红¨
亮¢
RED_A=1;
YELLOW_A=1;
GREEN_A=0;
RED_B=0;
YELLOW_B=1;
GREEN_B=1;
DelayMS(2000);
Operation_Type=2;
break;
case2:
黄?
闪¦
,ê
关?
闭À
DelayMS(300);
YELLOW_A=~YELLOW_A;
GREEN_A=1;
if(++Flash_Count!
=10)return;
5次ä
Flash_Count=0;
Operation_Type=3;
case3:
RED_A=0;
RED_B=1;
GREEN_B=0;
Operation_Type=4;
case4:
YELLOW_B=~YELLOW_B;
Operation_Type=1;
while
(1)Traffic_Light();
单只数码管:
单只数码管循环显示0~9
主程序中的循环语句反复将0~9的段码送至P0口,使数字0~9循环显示
单只数码管C语言程序
ucharcodeDSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
uchart;
while(x--)for(t=0;
t<
t++);
uchari=0;
P0=0x00;
P0=~DSY_CODE[i];
i=(i+1)%10;
霓虹灯:
花样流水灯
16只LED分两组按预设的多种花样变换显示
霓虹灯C语言程序
ucharcodePattern_P0[]=
0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff,
0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f,
0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,
0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff
};
ucharcodePattern_P2[]=
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,
0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
{//从ä
y组Á
¦
中D读¨
取¨
y据Y送¨
至¨
P0和¨
P2口¨
²
显?
示º
136;
P0=Pattern_P0[i];
P2=Pattern_P2[i];
DelayMS(100);
八只数码管单独滚动:
8只数码管滚动显示单个数字
数码管从左到右依次滚动显示0~7,程序通过每次仅循环选通一只数码管
八只数码管单独滚动
ucharcodeDSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
//延时
//主程序
uchari,wei=0x80;
8;
P2=0xff;
//关闭显示
wei=_crol_(wei,1);
P0=DSY_CODE[i];
//发送数字段码
P2=wei;
//发送位码
周四:
单只数码管A-F亮:
单只数码管循环显示A~F
主程序中的循环语句反复将A~F的段码送至P0口,使字母A~F循环显示
单只数码管A-F亮
ucharcodeDSY_CODE[]={0x88,0x83,0xc6,0xa1,0x86,0x8e};
150;
i=(i+1)%6;
点阵:
点阵屏循环显示A~F
点阵C语言程序
#include<
reg52.h>
#defineucharunsignedchar
#defineuintunsignedint
sbitK1=P3^7;
uchari,Second_Counts,Key_Flag_Idx;
bitKey_State;
ucharDSY_CODE[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
voidDelayMS(uintms)
uchart;
while(ms--)
{
for(t=0;
}
voidKey_Event_Handle()
if(Key_State==0)
Key_Flag_Idx=(Key_Flag_Idx+1)%3;
switch(Key_Flag_Idx)
{
case1:
EA=1;
ET0=1;
TR0=1;
case2:
EA=0;
ET0=0;
TR0=0;
case0:
P0=0x3f;
P2=0x3f;
i=0;
Second_Counts=0;
}
voidmain()
P0=0x3f;
P2=0x3f;
i=0;
Second_Counts=0;
Key_State=1;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
while
(1)
if(Key_State!
=K1)
DelayMS(16);
Key_State=K1;
Key_Event_Handle();
voidDSY_Refresh()interrupt1
TH0=(65535-50000)/256;
if(++i==2)
i=0;
++Second_Counts;
P0=DSY_CODE[Second_Counts/16];
P2=DSY_CODE[Second_Counts%16];
if(Second_Counts==256)Second_Counts=0;
滚动点阵:
两个点阵屏循环显示字母A~F
滚动点阵C语言程序
ucharcodeca[]=//存ä
放¤
字Á
符¤
A
0x00,0x1f,0x28,0x48,0x28,0x1f,0x00,0x00,//一°
下?
皆?
为aA字Á
滚?
的Ì
形?
态¬
0x1f,0x28,0x48,0x28,0x1f,0x00,0x00,0x00,//字Á
每?
一°
格?
0x28,0x48,0x28,0x1f,0x00,0x00,0x00,0x1f,
0x48,0x28,0x1f,0x00,0x00,0x00,0x1f,0x28,
0x28,0x1f,0x00,0x00,0x00,0x1f,0x28,0x48,
0x1f,0x00,0x00,0x00,0x1f,0x28,0x48,0x28,
0x00,0x00,0x00,0x1f,0x28,0x48,0x28,0x1f,
0x00,0x00,0x1f,0x28,0x48,0x28,0x1f,0x00,//因°
为a是º
8*8的Ì
点Ì
阵¨
所¨
以°
只?
用®
又®
该?
八ã
种?
一°
共264个?
y据Y
ucharcodecb[]=//存ä
B
0x00,0x00,0x7f,0x49,0x49,0x36,0x00,0x00,
0x00,0x7f,0x49,0x49,0x36,0x00,0x00,0x00,
0x7f,0x49,0x49,0x36,0x00,0x00,0x00,0x00,
0x49,0x49,0x36,0x00,0x00,0x00,0x00,0x7f,
0x49,0x36,0x00,0x00,0x00,0x00,0x7f,0x49,
0x36,0x00,0x00,0x00,0x00,0x7f,0x49,0x49,
0x00,0x00,0x00,0x00,0x7f,0x49,0x49,0x36,
0x00,0x00,0x00,0x7f,0x49,0x49,0x36,0x00,
ucharcodecc[]=//存ä
C
0x00,0x3e,0x41,0x41,0x41,0x41,0x22,0x00,
0x3e,0x41,0x41,0x41,0x41,0x22,0x00,0x00,
0x41,0x41,0x41,0x41,0x22,0x00,0x00,0x3e,
0x41,0x41,0x41,0x22,0x00,0x00,0x3e,0x41,
0x41,0x41,0x22,0x00,0x00,0x3e,0x41,0x41,
0x41,0x22,0x00,0x00,0x3e,0x41,0x41,0x41,
0x22,0x00,0x00,0x3e,0x41,0x41,0x41,0x41,
0x00,0x00,0x3e,0x41,0x41,0x41,0x41,0x22,
ucharcodecd[]=//存ä
D
0x00,0x00,0x7e,0x42,0x42,0x3c,0x00,0x00,
0x00,0x7e,0x42,0x42,0x3c,0x00,0x00,0x00,
0x7e,0x42,0x42,0x3c,0x00,0x00,0x00,0x00,
0x42,0x42,0x3c,0x00,0x00,0x00,0x00,0x7e,
0x42,0x3c,0x00,0x00,0x00,0x00,0x7e,0x42,
0x3c,0x00,0x00,0x00,0x00,0x7e,0x42,0x42,
0x00,0x00,0x00,0x00,0x7e,0x42,0x42,0x3c,
0x00,0x00,0x00,0x7e,0x42,0x42,0x3c,0x00,
ucharcodece[]=//存ä
E
0x00,0x00,0x7f,0x49,0x49,0x49,0x41,0x00,
0x00,0x7f,0x49,0x49,0x49,0x41,0x00,0x00,
0x7f,0x49,0x49,0x49,0x41,0x00,0x00,0x00,
0x49,0x49,0x49,0x41,0x00,0x00,0x00,0x7f,
0x49,0x49,0x41,0x00,0x00,0x00,0x7f,0x49,
0x49,0x41,0x00,0x00,0x00,0x7f,0x49,0x49,
0x41,0x00,0x00,0x00,0x7f,0x49,0x49,0x49,
0x00,0x00,0x00,0x7f,0x49,0x49,0x49,0x41,
ucharcodecf[]=//存ä
F
0x00,0x00,0x7f,0x48,0x48,0x48,0x40,0x00,
0x00,0x7f,0x48,0x48,0x48,0x40,0x00,0x00,
0x7f,0x48,0x48,0x48,0x40,0x00,0x00,0x00,
0x48,0x48,0x48,0x40,0x00,0x00,0x00,0x7f,
0x48,0x48,0x40,0x00,0x00,0x00,0x7f,0x48,
0x48,0x40,0x00,0x00,0x00,0x7f,0x48,0x48,
0x40,0x00,0x00,0x00,0x7f,0x48,0x48,0x48,
0x00,0x00,0x00,0x7f,0x48,0x48,0x48,0x40,
uchari=0,t=0,Num_Index=0;
intc=0;
P3=0x80;
Num_In