51单片机点亮1个LED灯_AD,Allegro,pads,PCB设计,电源模块,硬件,stm32,嵌入式,单片机,小北设计 Allegro,pads,PCB电路板设计,硬件及芯片资料分享—小北设计

51单片机点亮1个LED灯

51单片机 by AD,Allegro,pads,PCB设计,电源模块,硬件,stm32,嵌入式,单片机,小北设计
#include<reg51.h>
#define uchar unsigned char //定义uchar 为无符号字符,对应的十位数为最大值为255
#define uint unsigned int //定义uint 为无符号整型,16位系统中十位数最大为65535
sbit LED = P1^0;//定义P1端的0端。

void delay(uint ms)// 延时函数 
{  
    uint i, j; //定义变量i ,j .
  
   for(i=0; i<ms,i++)
   for(j=0; j<110; j++);//j每次加1,等j>110时,跳出此for 

}
//主程序
void main() 
{
    while(1)
 {
   LED = 0;      // 点亮
     
     delay(500);   // 延时500ms。每隔500,单片机电平反转一次
     
     LED = 1;      // 熄灭
        
delay(500);   // 延时500ms
    
   }

}
在11.0592MHZ晶振频率的情况下,即1s晶振震荡11059200次,T=1/F

一个机器周期为12个时钟周期,一个时钟周期是1/(11.0592*1000000)秒,所以一个机器周期为12*1/(11.0592*1000000)秒,约1.09微秒。

Proutues与程序下载:通过网盘分享的文件:点亮1个LED灯 链接: https://pan.baidu.com/s/1TZBkbsWQGN7ZDmvfL9sfLg 提取码: 4kyq





    Message:

    Name:
    Email:
    Content:
PgUP ...
Allegro,pads,PCB电路板设计,电源模块件及stm32,嵌入式,单片机资料分享—小北设计