6个单片机实验设计报告
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
uchar num;
void main()
{
TOMD=0X01;//设置定时器0工作方式为1(M1M0为01)
TH0=(65536-45872)/256;//装初值11.0952M晶振定时50ms数为45872
TL0=(65536-45872)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
实验一:流水灯
程序:
#include<reg52.h>
sbit d0=P0^0;
sbit d1=P0^1;
sbit d2=P0^2;
sbit d3=P0^3;
sbit d4=P0^4;
sbit d5=P0^5;
sbit d6=P0^6;
sbit d7=P0^7;
void delay(unsigned int x);
delay(250);
d6=1;
d7=0;
delay(250);
d7=1;
}
}
void delay(unsigned int x)
{
unsigned int y;
for(;x>0;x--)
for(y=500;y>0;y--);
}
实验二:单个数码管显示0~9循环
#include<reg52.h>
unsigned int dulatable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
{
for(i=0;i<4;i++)
{
P2=s[i];//利用P2.4~P2.7端口作为位选动态扫描
if(i==3)P0=table[*k[i]]&0x7f;//通过&运算点亮第一个数码管小数点
else P0=table[*k[i]];
delay(200);
}
}
}
void delay(unsigned int t)
{
unsigned int p;
for(p=20;p>=0;p--)
{
d=1;
delay(150);
d=0;
delay(150);
}
}
void delay(unsigned int z)
{
unsigned int y;
for(;z>0;z--)
for(y=1000;y>0;y--);
}
实验四:ADC0804测电压并用四连体共阳数码管显示
for(;z>0;z--)
for(y=1000;y>0;y--);
}
实验三:外部中断,数字循环终止,led闪烁报警持续20秒
#include<reg52.h>
unsigned int dulatable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段码表
{
for(t=0;t<120;t++)
{
for(b=0;b<8;b++)
{
P1=dulatable[a][b];
P0=welatable[b];
delay(200);
}
}
}
}
}
void delay(unsigned int x)
{
unsigned int y;
for(y=x;y>0;y--);
}
return(q);
}
double convert(unsigned char sixteen)
{
unsigned int a;
double qq;
a=(unsigned int)sixteen;//强制装换char为unsigned int
qq=(double)a;
qq=qq/256*5;
retuБайду номын сангаасn(qq);
void delay(unsigned int t);//延时函数
double convert(unsigned char sixteen);
unsigned char dushu(void);//从AD读数
void show(double qqq);//数码管显示
void main()
{
unsigned char output;//从AD读出的8位2二进制
}
}
实验六:点阵扫描1~3
#include<reg52.h>
unsigned int welatable[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned int dulatable[][8]={0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,
void main()
{
while(1)
{
d0=1;
delay(250);
d0=0;
d1=1;
delay(250);
d1=0;
d2=1;
delay(250);
d2=0;
d3=0;
delay(250);
d3=1;
d4=0;
delay(250);
d4=1;
d5=0;
delay(250);
d5=1;
d6=0;
{
unsigned int qwe;
for(qwe=t;qwe>0;qwe--);
}
实验五:定时器中断
利用定时器0工作方式1,实现发光管以1s亮灭闪烁
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit led1=P1^0;
P1=0xff;//P1全部置一准备
cs=0;
wr=0;
wr=1;//启动ADC0804开始测电压
while(int1==1);//等待A/D转换完毕产生INT1(低电平有效)信号
rd=0;//开始读转换后数据
i=i; i=i;
q=P1;//读出的数据赋与output
rd=1;
cs=1;//读数完毕
0xc3,0xfb,0xfb,0xc3,0xdf,0xdf,0xc3,0xff,
0xc3,0xfb,0xfb,0xc3,0xfb,0xfb,0xc3,0xff,};
void delay(unsigned int x);
void main()
{
unsigned int a,b,t;
while(1)
{
for(a=0;a<3;a++)
void delay(unsigned int z);
void main()
{
unsigned int x;
while(1)
{
for(x=0;x<10;x++)
{
P1=dulatable[x];
delay(250);
}
}
}
void delay(unsigned int z)
{
unsigned int y;
#include<reg52.h>
sbit int1=P3^3;//定义管脚功能
sbit cs=P3^2;//使能端
sbit wr=P3^6;//写端口
sbit rd=P3^7;//读端口
unsigned int s[]={0x10,0x20,0x40,0x80};//位码表
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段码表
double dianya;
while(1)
{
output=dushu();
dianya=convert(output);
show(dianya);
}
}
unsigned char dushu( void )
{
unsigned char q,i;
rd=1;
wr=1;
int1=1;//读ADC0804前准备
sbit d=P0^0;
void delay(unsigned int z);
void main()
{
unsigned int x;
EA=1;
EX0=1;
d=0;
while(1)
{
for(x=0;x<10;x++)
{
P1=dulatable[x];
delay(250);
}
}
}
void exter0() interrupt 0
TR0=1;//启动定时器0
while(1)//程序等待中断发生
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;//重装初值
TL0=(65536-45872)%256;
num++;
if(num==20)
{
num=90;
led1=~led1;//发光管状态取反
}
void show(double qqq)
{
unsigned int p,a,b,c,t,d,i,*k[]={&d,&c,&b,&a};
p=(unsigned int)(qqq*1000);
a=p/1000;
p=p%1000;
b=p/100;
p=p%100;
c=p/10;
p=p%10;
d=p;
for(t=1000;t>0;t--)//数码管动态扫描
void main()
{
TOMD=0X01;//设置定时器0工作方式为1(M1M0为01)
TH0=(65536-45872)/256;//装初值11.0952M晶振定时50ms数为45872
TL0=(65536-45872)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
实验一:流水灯
程序:
#include<reg52.h>
sbit d0=P0^0;
sbit d1=P0^1;
sbit d2=P0^2;
sbit d3=P0^3;
sbit d4=P0^4;
sbit d5=P0^5;
sbit d6=P0^6;
sbit d7=P0^7;
void delay(unsigned int x);
delay(250);
d6=1;
d7=0;
delay(250);
d7=1;
}
}
void delay(unsigned int x)
{
unsigned int y;
for(;x>0;x--)
for(y=500;y>0;y--);
}
实验二:单个数码管显示0~9循环
#include<reg52.h>
unsigned int dulatable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
{
for(i=0;i<4;i++)
{
P2=s[i];//利用P2.4~P2.7端口作为位选动态扫描
if(i==3)P0=table[*k[i]]&0x7f;//通过&运算点亮第一个数码管小数点
else P0=table[*k[i]];
delay(200);
}
}
}
void delay(unsigned int t)
{
unsigned int p;
for(p=20;p>=0;p--)
{
d=1;
delay(150);
d=0;
delay(150);
}
}
void delay(unsigned int z)
{
unsigned int y;
for(;z>0;z--)
for(y=1000;y>0;y--);
}
实验四:ADC0804测电压并用四连体共阳数码管显示
for(;z>0;z--)
for(y=1000;y>0;y--);
}
实验三:外部中断,数字循环终止,led闪烁报警持续20秒
#include<reg52.h>
unsigned int dulatable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段码表
{
for(t=0;t<120;t++)
{
for(b=0;b<8;b++)
{
P1=dulatable[a][b];
P0=welatable[b];
delay(200);
}
}
}
}
}
void delay(unsigned int x)
{
unsigned int y;
for(y=x;y>0;y--);
}
return(q);
}
double convert(unsigned char sixteen)
{
unsigned int a;
double qq;
a=(unsigned int)sixteen;//强制装换char为unsigned int
qq=(double)a;
qq=qq/256*5;
retuБайду номын сангаасn(qq);
void delay(unsigned int t);//延时函数
double convert(unsigned char sixteen);
unsigned char dushu(void);//从AD读数
void show(double qqq);//数码管显示
void main()
{
unsigned char output;//从AD读出的8位2二进制
}
}
实验六:点阵扫描1~3
#include<reg52.h>
unsigned int welatable[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned int dulatable[][8]={0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,
void main()
{
while(1)
{
d0=1;
delay(250);
d0=0;
d1=1;
delay(250);
d1=0;
d2=1;
delay(250);
d2=0;
d3=0;
delay(250);
d3=1;
d4=0;
delay(250);
d4=1;
d5=0;
delay(250);
d5=1;
d6=0;
{
unsigned int qwe;
for(qwe=t;qwe>0;qwe--);
}
实验五:定时器中断
利用定时器0工作方式1,实现发光管以1s亮灭闪烁
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit led1=P1^0;
P1=0xff;//P1全部置一准备
cs=0;
wr=0;
wr=1;//启动ADC0804开始测电压
while(int1==1);//等待A/D转换完毕产生INT1(低电平有效)信号
rd=0;//开始读转换后数据
i=i; i=i;
q=P1;//读出的数据赋与output
rd=1;
cs=1;//读数完毕
0xc3,0xfb,0xfb,0xc3,0xdf,0xdf,0xc3,0xff,
0xc3,0xfb,0xfb,0xc3,0xfb,0xfb,0xc3,0xff,};
void delay(unsigned int x);
void main()
{
unsigned int a,b,t;
while(1)
{
for(a=0;a<3;a++)
void delay(unsigned int z);
void main()
{
unsigned int x;
while(1)
{
for(x=0;x<10;x++)
{
P1=dulatable[x];
delay(250);
}
}
}
void delay(unsigned int z)
{
unsigned int y;
#include<reg52.h>
sbit int1=P3^3;//定义管脚功能
sbit cs=P3^2;//使能端
sbit wr=P3^6;//写端口
sbit rd=P3^7;//读端口
unsigned int s[]={0x10,0x20,0x40,0x80};//位码表
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段码表
double dianya;
while(1)
{
output=dushu();
dianya=convert(output);
show(dianya);
}
}
unsigned char dushu( void )
{
unsigned char q,i;
rd=1;
wr=1;
int1=1;//读ADC0804前准备
sbit d=P0^0;
void delay(unsigned int z);
void main()
{
unsigned int x;
EA=1;
EX0=1;
d=0;
while(1)
{
for(x=0;x<10;x++)
{
P1=dulatable[x];
delay(250);
}
}
}
void exter0() interrupt 0
TR0=1;//启动定时器0
while(1)//程序等待中断发生
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;//重装初值
TL0=(65536-45872)%256;
num++;
if(num==20)
{
num=90;
led1=~led1;//发光管状态取反
}
void show(double qqq)
{
unsigned int p,a,b,c,t,d,i,*k[]={&d,&c,&b,&a};
p=(unsigned int)(qqq*1000);
a=p/1000;
p=p%1000;
b=p/100;
p=p%100;
c=p/10;
p=p%10;
d=p;
for(t=1000;t>0;t--)//数码管动态扫描