单片机技能大赛编程大全.doc

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
delay();
P1=temp;
}
}
}
void delay()//延时子程序
{
int i,j;//定义局部变量i,j
for(i=200;i>0;i--)//i,j不断计数占用CPU时间,达到延时目的
for(j=1;j<150;j++);
}
四.可控的左右循环流水灯的制作
ORG 0000H;单片机上电后从0000H地址执行
{
P0=table_P0[i];
P2=table_P2[i];
delay(100);
}
}
}
}
}
三.简单的左右循环流水灯的制作
#include<reg51.h>
#include<intrins.h>
unsigned char temp;//定义字符变量temp,temp左移或右移并给连接LED的P1口赋值
0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff
};
//延时
void delay(uint xms)
{
uint i,j;
AJMP START;跳转到主程序存放地址处
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
//主程序
void main()
{
uchar i;
if(key==0)
{
delay(10);
if(key==0)
{
while(!key);
while(1)
{ //从数组中读取数据送至P0和P2口显示
for(i=0;i<136;i++)
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xc0,0xe0,0xf0,wenku.baidu.comxf8,0xfc,0xfe,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff
};
uchar code table_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,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,
0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
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,
0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
{
temp=_crol_(temp,1); //_crol_语句控制变量temp左移
delay();//每个灯点亮之后延迟一会在点下一个灯
P1=temp;
}
for(a=0;a<7;a++)//右移部分,LED从右到左依次点亮
{
temp=_cror_(temp,1); //第8个灯点亮后开始右移程序,LED从右向左点亮
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,
一.开关检测器程序编写:
ORG 00H
START: MOV A,P1
ANL A,#0F0H
RR A
RR A
RR A
RR A
ORl A,#0F0H
MOV P1,A
SJMP STARTORG 00H
START: MOV A,P1
ANL A,#0F0H
RR A
RR A
RR A
RR A
ORl A,#0F0H
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,
int a;//定义延迟函数delay()
void delay(void);
void main()
{
temp=0xfe;//给temp赋初值
P1=temp;//temp赋值给P1口,第一个LED(红色)点亮
while(1)//主程序,括号中的程序将一直循环
{
for(a=0;a<7;a++)//左移部分,LED从左到右依次点亮
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,
MOV P1,A
SJMP START
二:节日彩灯控制器编程:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit key=P1^2;
uchar code table_P0[]=
{
0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
相关文档
最新文档