单片机实验程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一
#include
#include
#define uchar unsigned char
sbit H1=P3^6;
sbit H2=P3^7;
sbit L1=P0^5;
sbit L2=P0^6;
sbit L3=P0^7;
tab1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xff,0xff,0xff}; tab2[]={0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3b,0x37,0x2f,0x1f}; tab3[]={0xff,0xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; tab4[]={0x1f,0x2f,0x37,0x3b,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f}; void Delay1s() //@11.0592MHz
{ unsigned char i,j,k;
for(i=10;i>0;i--)
for(j=200;j>0;j--)
for(k=250;k>0;k--)
}
void delay20ms()
{
unsigned char i,j;
for(i=100;i>0;i--)
for(j=60;j>0;j--);
}
void flick()
{
uchar d;
while(d<=2)
{
P2=0x00;
P3=0xc3;
Delay1s();
P2=0xff;
P3=0xff;
Delay1s();
d++;
}
}
void main()
{
uchar b,y,n;
flick();
while(1)
{
n=b;
y=(n%2);
if(y==1)
{
uchar x;
for(x=0;x<12;x++)
{
P2=tab3[x];
P3=tab4[x];
Delay1s();
H1=0;
H2=0;
L1=1;
L2=1;
L3=1;
if(!L1||!L2||!L3)
{
Delay20ms();
if(!L1||!L2||!L3)
b+=1;
while(!L1||!L2||!L3);
}
}
}
if(y==0)
{
uchar x;
for(x=0;x<12;x++)
{
P2=tab1[x];
P3=tab2[x];
Delay1s();
H1=0;
H2=0;
L1=1;
L2=1;
L3=1;
if(!L1||!L2||!L3)
{ delay20ms()
if(!L1||!L2||!L3)
b+=1;
while(!L1||!L2||!L3);
}
}
}
}
二
#include
#include
#define uchar unsigned char
sbit H1=P3^6;
sbit H2=P3^7;
sbit L1=P0^5;
sbit L2=P0^6;
sbit L3=P0^7;
tab1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xff,0xff,0xff}; tab2[]={0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3b,0x37,0x2f,0x1f}; tab3[]={0xff,0xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; tab4[]={0x1f,0x2f,0x37,0x3b,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f}; void Delay1s() //@11.0592MHz
{ unsigned char i,j,k;
for(i=10;i>0;i--)
for(j=200;j>0;j--)
for(k=250;k>0;k--)
}
void delay10ms()
{
unsigned char i,j,k;
for(i=5;i>0;i--)
for(j=4;j>0;j--)
for(k=248;k>0;k--);
}
void flick()
{
uchar d;
while(d<=2)
{
P2=0x00;
P3=0xc3;
Delay1s();
P2=0xff;
P3=0xff;
Delay1s();
}
}
void main()
{
uchar b,y,n;
flick();
while(1)
{
n=b;
y=(n%2);
if(y==1)
{
uchar x;
for(x=0;x<12;x++)
{
P2=tab3[x];
P3=tab4[x];
Delay1s();
H1=0;
H2=0;
L1=1;
L2=1;
L3=1;
if(!L1||!L2||!L3)
{
Delay10ms();
if(!L1||!L2||!L3)
b+=1;
while(!L1||!L2||!L3);
}
}
}
if(y==0)
{
uchar x;
for(x=0;x<12;x++)
{
P2=tab1[x];
P3=tab2[x];
Delay1s();
H1=0;
H2=0;
L1=1;