郭天祥十天学会单片机例程.docx
- 文档编号:5845154
- 上传时间:2023-01-01
- 格式:DOCX
- 页数:50
- 大小:21.25KB
郭天祥十天学会单片机例程.docx
《郭天祥十天学会单片机例程.docx》由会员分享,可在线阅读,更多相关《郭天祥十天学会单片机例程.docx(50页珍藏版)》请在冰豆网上搜索。
郭天祥十天学会单片机例程
郭天祥十天学会单片机视频例程(部分)
Lesson3_1-lesson3_4
#include
sbitdula=P2^6;
sbitwela=P2^7;
voidmain()
{
wela=1;
P0=0xc0;
wela=0;
dula=1;
P0=0x06;
dula=0;
while
(1);
}
#include
#defineuintunsignedint
#defineucharunsignedchar
sbitdula=P2^6;
sbitwela=P2^7;
ucharnum;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
voiddelay(uintz);
voidmain()
{
wela=1;//11101010
P0=0xea;
wela=0;
while
(1)
{
for(num=0;num<16;num++)
{
dula=1;
P0=table[num];
dula=0;
delay(1000);
}
}
}
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
#include
#defineuintunsignedint
#defineucharunsignedchar
sbitdula=P2^6;
sbitwela=P2^7;
sbitd1=P1^0;
ucharnum;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
voiddelay(uintz);
voidmain()
{
EA=1;//开总中断
EX0=1;//开外部中断0
//IT0=1;
TCON=0x01;
wela=1;//11101010
P0=0xea;
wela=0;
while
(1)
{
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>0;y--);
}
voidexter0()interrupt0
{
d1=0;
}
#include
#defineuintunsignedint
#defineucharunsignedchar
sbitdula=P2^6;
sbitwela=P2^7;
sbitd1=P1^0;
ucharnum,num1;tt;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
voiddelay(uintz);
voidmain()
{
num=0;
tt=0;
TMOD=0x11;//设置定时器0为工作方式1
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TH1=(65536-20000)/256;
TL1=(65536-20000)%256;
//EA=1;//开总中断
ET0=1;//开定时器0中断
ET1=1;
TR0=1;//启动定时器0
TR1=1;
wela=1;//11101010
P0=0xea;
wela=0;
dula=1;
P0=0x3f;
dula=0;
while
(1)
{
if(num1==25)
{
num1=0;
P1=~P1;
}
if(tt==100)
{
tt=0;
num++;
if(num==16)
num=0;
dula=1;
P0=table[num];
dula=0;
}
}
}
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voidtime0()interrupt1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
tt++;
}
voidtime1()interrupt3
{
TH1=(65536-20000)/256;
TL1=(65536-20000)%256;
num1++;
}
Lesson4_1-lesson4_3
#include
#include
#defineuintunsignedint
#defineucharunsignedchar
uchartemp,aa,num;
sbitdula=P2^6;
sbitwela=P2^7;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
voiddelay(uintz);
voidmain()
{
num=0;
aa=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
temp=0xfe;
P1=temp;
dula=1;
P0=table[0];
dula=0;
wela=1;
P0=0xc0;
wela=0;
while
(1)
{
delay(1000);
temp=_crol_(temp,1);
P1=temp;
/*if(aa==40)
{
aa=0;
num++;
if(num==16)
num=0;
dula=1;
P0=table[num];
dula=0;
}*/
}
}
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voidtimer0()interrupt1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==40)
{
aa=0;
num++;
if(num==16)
num=0;
dula=1;
P0=table[num];
dula=0;
}
}
#include
#include
#defineuintunsignedint
#defineucharunsignedchar
uchartemp,aa,numdu,numwe;
sbitdula=P2^6;
sbitwela=P2^7;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
ucharcodetablewe[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
//voiddelay(uintz);
voidmain()
{
numdu=0;
numwe=0;
aa=0;
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
EA=1;
ET0=1;
TR0=1;
while
(1)
{
//delay(1000);
//temp=_crol_(temp,1);
//P1=temp;
if(aa==1)
{
aa=0;
numdu++;
if(numdu==7)
numdu=1;
dula=1;
P0=table[numdu];
dula=0;
wela=1;
P0=tablewe[numwe];
wela=0;
numwe++;
if(numwe==6)
numwe=0;
}
}
}
/*
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}*/
voidtimer0()interrupt1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
aa++;
}
#include
#defineuintunsignedint
#defineucharunsignedchar
uchartemp,aa,bai,shi,ge;
sbitdula=P2^6;
sbitwela=P2^7;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
voiddisplay(ucharbai,ucharshi,ucharge);
voiddelay(uintz);
voidinit();
voidmain()
{
init();//初始化子程序
while
(1)
{
if(aa==20)
{
aa=0;
temp++;
if(temp==100)
{
temp=0;
}
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
}
display(bai,shi,ge);
}
}
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voiddisplay(ucharbai,ucharshi,ucharge)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay
(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay
(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay
(1);
}
voidinit()
{
wela=0;
dula=0;
temp=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
voidtimer0()interrupt1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
Lesson5_1—Lesson5_3
#include
#include
#defineucharunsignedchar
#defineuintunsignedint
sbitdula=P2^6;
sbitwela=P2^7;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
uchartemp,t0,t1,bai,shi,ge,flag,flag1;
uintshu;
voidinit();
voiddisplay(uchar,uchar,uchar,uchar,uchar,uchar);
voiddelay(uintz)
{
uintt1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
voidmain()
{
init();
while
(1)
{
if(flag1!
=1)
display(7,6,5,bai,shi,ge);
else
display(16,17,18,18,19,20);
}
}
voidinit()
{
shu=432;
temp=0xfe;
P1=temp;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
voidtimer0()interrupt1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(flag!
=1)
{
if(t0==10)
{
t0=1;
temp=_crol_(temp,1);
P1=temp;
}
}
else
{
if(t0%4==0)
P1=~P1;
if(t0==60)
{
TR0=0;
P1=0xff;
flag1=1;
}
}
}
voidtimer1()interrupt3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
t1++;
if(t1==2)
{
t1=0;
shu--;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
if(shu==398)
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
flag=1;
t0=0;
P1=0xff;
TR1=0;
}
}
}
voiddisplay(ucharaa,ucharbb,ucharcc,ucharba,ucharsh,ucharg)
{
dula=1;
P0=table[aa];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay
(1);
dula=1;
P0=table[bb];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay
(1);
dula=1;
P0=table[cc];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay
(1);
dula=1;
P0=table[ba];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay
(1);
dula=1;
P0=table[sh];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay
(1);
dula=1;
P0=table[g];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay
(1);
}
#include
#defineuintunsignedint
#defineucharunsignedchar
sbitd1=P1^0;
sbitdula=P2^6;
sbitwela=P2^7;
sbitkey1=P3^4;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
ucharnum;
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voidmain()
{
wela=1;
P0=0xfe;
wela=0;
P3=0xff;
while
(1)
{
if(key1==0)
{
delay(5);
if(key1==0)
{
d1=0;
num++;
if(num==10)
num=0;
}
while(!
key1);
delay(5);
while(!
key1);
}
else
d1=1;
dula=1;
P0=table[num];
dula=0;
}
}
#include
#defineuintunsignedint
#defineucharunsignedchar
sbitdula=P2^6;
sbitwela=P2^7;
sbitkey1=P3^4;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
ucharnum,temp,num1;
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
ucharkeyscan();
voiddisplay(ucharaa);
voidmain()
{
num=17;
dula=1;
P0=0;
dula=0;
wela=1;
P0=0xc0;
wela=0;
while
(1)
{
display(keyscan());
}
}
voiddisplay(ucharaa)
{
dula=1;
P0=table[aa-1];
dula=0;
}
ucharkeyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!
=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!
=0xf0)
{
temp=P3;
switch(temp)
{
case0xee:
num=1;
break;
case0xde:
num=2;
break;
case0xbe:
num=3;
break;
case0x7e:
num=4;
break;
}
while(temp!
=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!
=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!
=0xf0)
{
temp=P3;
switch(temp)
{
case0xed:
num=5;
break;
case0xdd:
num=6;
break;
case0xbd:
num=7;
break;
case0x7d:
num=8;
break;
}
while(temp!
=0xf0)
{
temp=P3;
temp=temp&0xf0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 郭天祥十天 学会 单片机 例程
![提示](https://static.bdocx.com/images/bang_tan.gif)