#include <reg52.h>

sbit LED = P1^0; //定义LED连接的引脚

void delay(unsigned int time) //延时函数 { unsigned int i,j; for(i=0;i<time;i++) { for(j=0;j<1275;j++); } }

void main() { unsigned int count = 0; //计数器初始值为0 while(1) { LED = ~LED; //翻转LED状态 delay(500); //延时0.5秒 count++; //计数器加1 if(count == 10) //若计数器到达10,重新计数 { count = 0; } } }

注:该代码仅作为示例,具体实验中可能需要根据硬件连接和实验要求进行适当修改。

C51单片机计数器实验C语言代码示例

原文地址: https://www.cveoy.top/t/topic/nsM1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录