单片机程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验一
书p79
实验二
#include
#include<51.h>
#define uint unsigned char
sbit led=P0^4;
uint i=0;
char
led_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39 ,0x5e,0x79,0x71};
led=1;
P2=0;
void K1()interrupt 0
{
led=!led;
}
void K2() interrupt 2
{
P2=led_mod[i];
i++;
}
if(i==16)
{
i=0;
}
void main()
{led=1;
IE=0x85;
IT0=1;
IT1=1;
}
实验三
#include"reg51.h"
void delay (unsigned int time)
{
unsigned int j=0;
for(time=time;time>0;time--)
for(j=0;j<125;j++);
}
void main ()
{
unsigned char i;
P0=1;
delay(50);
while(1)
{
for(i=1;i<=7;i++)
{
P0<<=1;
delay(50);
}
for(i=1;i<=7;i++)
{
P0>>=1;
delay(50);
}
}
}
实验四(误)
#include
unsigned char t=0;
unsigned char second=0;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f} timer0()
interrupt1{
TRO=0;
THO=0X3C;
TLO=0XB0;
TRO=1;
t++;
if(t==20)t=0;
second++;}
if(second++60)
second=0;
p0=table{second/10};
main(){TMOD=0X01 ;
THO=0X3C;
TLO=0Xb0;
p0=table[second/10];
p2=table[second%10];
tro=1;
ETO=1;
EA=1;
while(1){}}
实验五
实验六
书P139
实验七
#include
sbit _st=P2^5;
sbit _eoc=P2^6;
sbit _oe=P2^7;
sbit led0=P2^3;
sbit led1=P2^2;
sbit led2=P2^1;
unsigned long ad_result=0;
unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void delay(unsigned int time){
unsigned int j=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
void disp(void){
led2=1;
P0=table[ad_result/100]+0x80;
led2=0;
delay(10);
led2=1;
led1=1;
P0=table[(ad_result/10)%10];
led1=0;
delay(10);
led0=1;}
void main(void){
while(1){
_st=0;_st=1;_st=0;
while(!_eoc);