做了以下几个实验,点亮LED、,LED流水灯,蜂鸣器, 静态数码管
LED流水灯代码
代码语言:javascript复制#include"reg52.h"
unsigned char led[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay_ms(int n)
{
unsigned int i=0,j=0;
for(i=0;i<n;i )
for(j=0;j<123;j );
}
void main(){
unsigned char i;
while(1){
for(i=0;i<8;i ){
P0=led[i];
delay_ms(1000);
}
}
}
蜂鸣器 实验
代码语言:javascript复制#include"reg52.h"
sbit beep=P1^5;
void delay_ms(int n)
{
unsigned int i=0,j=0;
for(i=0;i<n;i )
for(j=0;j<123;j );
}
void main(){
while(1){
beep=~beep;
delay_ms(1000);
}
}
静态数码管 原理和基础知识
静态数码管 代码
代码语言:javascript复制#include"reg52.h"
unsigned char smg[4]={0xc0,0xf9,0xa4,0xb0};
void delay_ms(int n)
{
unsigned int i=0,j=0;
for(i=0;i<n;i )
for(j=0;j<123;j );
}
void main(){
unsigned char i;
while(1){
for(i=0;i<4;i )
{
P0=smg[i];
delay_ms(1000);
}
}
}