电子信息工程专业实验
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//共阳显示码
unsigned char code ledca[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳位置码
unsigned char code posca[]={0x01,0x02,0x04,0x08,0x10,
}
}
}
#include<REG51.H>
void Delay()
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void main()
{
unsigned char i;
unsigned char temp;
P1=0xff;
while(1)
0x20,0x40,0x80};
void delayms(unsigned int); //毫秒延时
void display(unsigned char,unsigned char); //LED显示
void main()
{
IE=0x85; //外部中断初始化
//IT0=0; //电平触发
IT1=1; //边沿触发
{ }
}
}
//LED显示,第1个参数为显示数据,第2个为显示位置
void display(unsigned char dat,unsigned char pos)
{
POSPIN=posca[pos];
DATPIN=ledca[dat];
delayms(5);
POSPIN=0x00;
}
//外部中断1处理函数
#define RELOAD_HIGH 0xFC
#define RELOAD_LOW 0x18
sbit KEY0 = P3^6;
sbit KEY1 = P3^7;
//最小计时单位
unsigned int t,ms,sec,min,hr;
//共阳显示码
unsigned char code ledca[]={0xc0,
Delay();
P2=0xff;
}
}
#include<REG51.H>
void Delay()
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void main()
{
unsigned char i;
unsigned char temp,temp1;
TR0 =1;
while(1)
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if (~KEY0)
{
ms=0;
IE =0x82;
}
if (~KEY1)
{
IE =0x00;
}
display(ledca[ms%10],7);
display(ledca[ms/10],6);
DATPIN=ledca[dat];
delayms(5);
POSPIN=0x00;
}
//定时器0中断
void timer0() interrupt 1
{
TH0 =(65536-49991)/256;
TL0 =(65536-49991)%256;
ms++;
}
//计数器1中断
void timer1() interrupt 3
{
temp=0x07;
for(i=0;i<8;i++)
{P1=~temp;
Delay();
temp=temp<<1;
P1=0xff;
}
P2=0xC7;
Delay();
P2=0xE3;
Delay();
P2=0X8F;
Delay();
P2=0XF1;
Delay();
P2=0X1F;
Delay();
P2=0XF8;
TL0 =(65536-49999)%256; //T0初值
while(1)
{
if (~KEYS)//按键按下
{
ms =0;//计时单位清零
cy =0;//进位清零
TH1=0;//T1初值为0
TL1=0;//T1初值为0
TR0=1;//启动定时器
TR1=1;//启动计数器
//定时器查询中断
if(TF0==1)
//毫秒延时
void delayms(unsigned int);
//LED显示
void display(unsigned char,unsigned char);
void main()
{
//定时器、中断初始化
IE =0x00;
TMOD=0x01;
TH0 =RELOAD_HIGH;
TL0 =RELOAD_LOW;//启动定时器
void main()
{
unsigned char i,wei,chr[8]; //循环变量、位数、显示字符串
unsigned long freq; //频率数
IE=0x8A;//T0、T1开中断
TMOD=0x51;//T0定时器、T1计数器
TH0 =(65536-49999)/256; //T0初值
display(ledca[sec%10],5);
display(ledca[sec/10],4);
display(ledca[min%10],3);
display(ledca[min/10],2);
display(ledca[hr%10],1);
display(ledca[hr/10],0);
}
}
sec=0;
if(min==60)
{
hr++;
min=0;
if(hr==24)
{
hr=0;
}
}
}
}
}
}
#include <reg51.h>
#define DATPIN P0 //IO口定义
#define POSPIN P2 //IO口定义
sbit KEYS =P3^0; //按键定义
unsigned char ms,cy; //最小计时单位、频率进位
void delayms(unsigned int);
void main()
{
unsigned char i,J;
i = 0;
J = 0;
while(1)
{
P2=J;
for(i=0;i<10;i++)
{
P3=ledca[i];
delayms(200);
if(i==9)
{
J=J+1;
if(J==10)
{
J=0;
}
}
}
}
}
void delayms(unsigned int t)
{
unsigned int i,j;
for (j=0;j<t;j++)
{
for (i=0;i<124;i++)
{ }
}
}
#include <reg51.h>
//定义引脚
#define DATPIN P0
#define POSPIN P2
P1=0xff;
while(1)
{
temp=0x01;
for(i=0;i<8;i++)
{P1=~temp;
Delay();
temp=temp<<2;
P1=0xff;
}
temp1=0x02;
for(i=0;i<8;i++)
{P1=~temp1;
Delay();
temp1=temp1<<2;
P1=0xff;
unsigned char code posca[]={0X80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
void delayms(unsigned int t); //毫秒延时
void display(unsigned char dat,unsigned char pos);
#include<REG51.H>
void Delay()
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void main()
{
unsigned char i;
unsigned char temp;
P1=0xff;
P2=0xff;
while(1)
{
cy++;
}
#include <reg51.h>
#define DATPIN P0 //定义IO口
#define POSPIN P2 //定义IO口
sbit KEY0 = P3^2; //定义按键
sbit KEY1 = P3^3; //定义按键
unsigned char num0=0,num1=80; //按键0和1按下次数
{
TH0 =(65536-49999)/256;
TL0 =(65536-49999)%256;
ms++;
TF0=0;
}
if(TF1==1)
{
cy++;
TF1=0;
}
while(ms<20);//等待1秒到
TR1=0;//停止计数器
TR0=0;//停止定时器
//计算脉冲数量
freq=cy*65536+TH1*256+TL1;
IT0=1;
while(1)
{
display(num1/10,num0);
display(num1%10,num0+1);
}
}
//毫秒延时
void delayms(unsigned int t)
{
unsigned int i,j;
for (j=0;j<t;j++)
{
for (i=0;i<123;i++)
0xf9,0xa4,0xb0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳位置码
unsigned char code posca[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//毫秒延时
void delayms(unsigned int t)
{
unsigned int i, j;
for (j=0; j<t; j++)
{
for (i=0; i<123; i++)
{ }
}
}
//LED显示,第1个参数为显示数据,第2个为显示位置
void display(unsigned char dat, unsigned char pos)
{
temp=0x01;
for(i=0;i<8;i++)
{P1=~temp;
Delay();
temp=temp<<1;
P1=0xff;
}
}
}
#include <reg51.h>
unsigned char code ledca[]={0x3f,
0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void int1() interrupt 2
{
num1++;
if(num1==100)
{
num1=0;
}
}
void int0() interrupt 0
{
num0++;
if(num0==7)
{
num0=0;
}
//num1=0;
}
//共阳显示码
unsigned char code ledca[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳位置码
//unsigned char code posca[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delayms(unsigned int t)
{
unsigned int i,j;
for (j=0;j<t;j++)
{
for (i=0;i<123;i++)
{ }
}
}
//LED显示
void display(unsigned char dat,unsigned char pos)
{
POSPIN=posca[pos];
{源自文库
POSPIN=posca[pos];
DATPIN=dat;
delayms(5);
POSPIN=0x00;
}
//定时中断处理函数
void timer0() interrupt 1
{
t++;
if(t==2)
{
ms++;
t=0;
if(ms==10)
{
sec++;
ms=0;
if(sec==60)
{
min++;
//将脉冲数转化为字符
for (i=0;i<8;i++)
{
chr[i]=freq%10;
freq/=10;
if (freq==0)
{
wei=i+1;break;
}
}
while(~KEYS); //等待按键抬起
}
for (i=0;i<wei;i++)
{
display(chr[i],i);
}
}
}
//毫秒延时
unsigned char code ledca[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳位置码
unsigned char code posca[]={0x01,0x02,0x04,0x08,0x10,
}
}
}
#include<REG51.H>
void Delay()
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void main()
{
unsigned char i;
unsigned char temp;
P1=0xff;
while(1)
0x20,0x40,0x80};
void delayms(unsigned int); //毫秒延时
void display(unsigned char,unsigned char); //LED显示
void main()
{
IE=0x85; //外部中断初始化
//IT0=0; //电平触发
IT1=1; //边沿触发
{ }
}
}
//LED显示,第1个参数为显示数据,第2个为显示位置
void display(unsigned char dat,unsigned char pos)
{
POSPIN=posca[pos];
DATPIN=ledca[dat];
delayms(5);
POSPIN=0x00;
}
//外部中断1处理函数
#define RELOAD_HIGH 0xFC
#define RELOAD_LOW 0x18
sbit KEY0 = P3^6;
sbit KEY1 = P3^7;
//最小计时单位
unsigned int t,ms,sec,min,hr;
//共阳显示码
unsigned char code ledca[]={0xc0,
Delay();
P2=0xff;
}
}
#include<REG51.H>
void Delay()
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void main()
{
unsigned char i;
unsigned char temp,temp1;
TR0 =1;
while(1)
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if (~KEY0)
{
ms=0;
IE =0x82;
}
if (~KEY1)
{
IE =0x00;
}
display(ledca[ms%10],7);
display(ledca[ms/10],6);
DATPIN=ledca[dat];
delayms(5);
POSPIN=0x00;
}
//定时器0中断
void timer0() interrupt 1
{
TH0 =(65536-49991)/256;
TL0 =(65536-49991)%256;
ms++;
}
//计数器1中断
void timer1() interrupt 3
{
temp=0x07;
for(i=0;i<8;i++)
{P1=~temp;
Delay();
temp=temp<<1;
P1=0xff;
}
P2=0xC7;
Delay();
P2=0xE3;
Delay();
P2=0X8F;
Delay();
P2=0XF1;
Delay();
P2=0X1F;
Delay();
P2=0XF8;
TL0 =(65536-49999)%256; //T0初值
while(1)
{
if (~KEYS)//按键按下
{
ms =0;//计时单位清零
cy =0;//进位清零
TH1=0;//T1初值为0
TL1=0;//T1初值为0
TR0=1;//启动定时器
TR1=1;//启动计数器
//定时器查询中断
if(TF0==1)
//毫秒延时
void delayms(unsigned int);
//LED显示
void display(unsigned char,unsigned char);
void main()
{
//定时器、中断初始化
IE =0x00;
TMOD=0x01;
TH0 =RELOAD_HIGH;
TL0 =RELOAD_LOW;//启动定时器
void main()
{
unsigned char i,wei,chr[8]; //循环变量、位数、显示字符串
unsigned long freq; //频率数
IE=0x8A;//T0、T1开中断
TMOD=0x51;//T0定时器、T1计数器
TH0 =(65536-49999)/256; //T0初值
display(ledca[sec%10],5);
display(ledca[sec/10],4);
display(ledca[min%10],3);
display(ledca[min/10],2);
display(ledca[hr%10],1);
display(ledca[hr/10],0);
}
}
sec=0;
if(min==60)
{
hr++;
min=0;
if(hr==24)
{
hr=0;
}
}
}
}
}
}
#include <reg51.h>
#define DATPIN P0 //IO口定义
#define POSPIN P2 //IO口定义
sbit KEYS =P3^0; //按键定义
unsigned char ms,cy; //最小计时单位、频率进位
void delayms(unsigned int);
void main()
{
unsigned char i,J;
i = 0;
J = 0;
while(1)
{
P2=J;
for(i=0;i<10;i++)
{
P3=ledca[i];
delayms(200);
if(i==9)
{
J=J+1;
if(J==10)
{
J=0;
}
}
}
}
}
void delayms(unsigned int t)
{
unsigned int i,j;
for (j=0;j<t;j++)
{
for (i=0;i<124;i++)
{ }
}
}
#include <reg51.h>
//定义引脚
#define DATPIN P0
#define POSPIN P2
P1=0xff;
while(1)
{
temp=0x01;
for(i=0;i<8;i++)
{P1=~temp;
Delay();
temp=temp<<2;
P1=0xff;
}
temp1=0x02;
for(i=0;i<8;i++)
{P1=~temp1;
Delay();
temp1=temp1<<2;
P1=0xff;
unsigned char code posca[]={0X80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
void delayms(unsigned int t); //毫秒延时
void display(unsigned char dat,unsigned char pos);
#include<REG51.H>
void Delay()
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void main()
{
unsigned char i;
unsigned char temp;
P1=0xff;
P2=0xff;
while(1)
{
cy++;
}
#include <reg51.h>
#define DATPIN P0 //定义IO口
#define POSPIN P2 //定义IO口
sbit KEY0 = P3^2; //定义按键
sbit KEY1 = P3^3; //定义按键
unsigned char num0=0,num1=80; //按键0和1按下次数
{
TH0 =(65536-49999)/256;
TL0 =(65536-49999)%256;
ms++;
TF0=0;
}
if(TF1==1)
{
cy++;
TF1=0;
}
while(ms<20);//等待1秒到
TR1=0;//停止计数器
TR0=0;//停止定时器
//计算脉冲数量
freq=cy*65536+TH1*256+TL1;
IT0=1;
while(1)
{
display(num1/10,num0);
display(num1%10,num0+1);
}
}
//毫秒延时
void delayms(unsigned int t)
{
unsigned int i,j;
for (j=0;j<t;j++)
{
for (i=0;i<123;i++)
0xf9,0xa4,0xb0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳位置码
unsigned char code posca[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//毫秒延时
void delayms(unsigned int t)
{
unsigned int i, j;
for (j=0; j<t; j++)
{
for (i=0; i<123; i++)
{ }
}
}
//LED显示,第1个参数为显示数据,第2个为显示位置
void display(unsigned char dat, unsigned char pos)
{
temp=0x01;
for(i=0;i<8;i++)
{P1=~temp;
Delay();
temp=temp<<1;
P1=0xff;
}
}
}
#include <reg51.h>
unsigned char code ledca[]={0x3f,
0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void int1() interrupt 2
{
num1++;
if(num1==100)
{
num1=0;
}
}
void int0() interrupt 0
{
num0++;
if(num0==7)
{
num0=0;
}
//num1=0;
}
//共阳显示码
unsigned char code ledca[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳位置码
//unsigned char code posca[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delayms(unsigned int t)
{
unsigned int i,j;
for (j=0;j<t;j++)
{
for (i=0;i<123;i++)
{ }
}
}
//LED显示
void display(unsigned char dat,unsigned char pos)
{
POSPIN=posca[pos];
{源自文库
POSPIN=posca[pos];
DATPIN=dat;
delayms(5);
POSPIN=0x00;
}
//定时中断处理函数
void timer0() interrupt 1
{
t++;
if(t==2)
{
ms++;
t=0;
if(ms==10)
{
sec++;
ms=0;
if(sec==60)
{
min++;
//将脉冲数转化为字符
for (i=0;i<8;i++)
{
chr[i]=freq%10;
freq/=10;
if (freq==0)
{
wei=i+1;break;
}
}
while(~KEYS); //等待按键抬起
}
for (i=0;i<wei;i++)
{
display(chr[i],i);
}
}
}
//毫秒延时