当前位置:网站首页>点灯
点灯
2022-07-15 15:23:00 【夏夜晚风_】
文章目录
方式1
#include<reg52.h>
#define LED_NUM 8 // LED的个数
#define TIME 150 // 延时的时间
#define LED_PORT P0 // LED使用P0组端口
// 延时函数
void delay_ms(int ms)
{
int i,j;
for(i=0; i<ms; i++)
{
for(j=0; j<120; j++)
{
// 空语句
}
}
}
int main(void)
{
int i;
LED_PORT = 0x00; // 8个灯全部熄灭,高电平点亮,低电平熄灭
while(1)
{
// 流水灯,顺流
for(i=0; i<LED_NUM; ++i)
{
LED_PORT = 1<<i; // 0-7 循环左移,高电平点亮
delay_ms(TIME); // 延时150ms
}
// 流水灯,逆流
for(i=LED_NUM-1; i>=0 --i)
{
LED_PORT = 1<<i; // 7-0 循环左移,高电平点亮
delay_ms(TIME); // 延时150ms
}
}
}
方式2:
#include<reg52.h>
/** * 功 能: 延时函数 * 参 数: ms 要延时的ms数 * 返回值: void 无 */
void delay_ms(int ms)
{
int i,j;
for(i=0; i<ms; i++)
{
for(j=0; j<120; j++)
; // 空语句
}
}
int main(void)
{
int i;
uchar code_table[] = {
0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};
P2 = 0xFF; // 初始化8个灯全部熄灭,高电平熄灭,低电平点亮
while(1)
{
// 顺序点亮
for(i=0; i<7; ++i){
P2 = code_table[i]; // 使用数组的方式点亮相应的LED灯
delay_ms(200); // 延时200ms
}
// 逆序点亮
for(i=7; i>=0 --i){
P2 = code_table[i]; // 使用数组的方式点亮相应的LED灯
delay_ms(200); // 延时200ms
}
}
}
边栏推荐
- Cool dog music interface is amazingly open
- C # write a GUI tool and decompile it
- Information system project managers must recite the core examination sites (10) information system planning
- Kekeguo information management] information management paper writing requirements - unqualified papers
- Distributed transaction integration netcore Cap
- 电商平台后台管理系统--->系统详细设计(订单管理模块)
- 牛客2021暑期训练1-A-Alice and Bob
- ERROR 1366 (HY000): Incorrect string value: ‘\xE8\xB5\xB5\xE9\x9B\xB7‘ for column ‘s_name‘ at row 1
- Wechat applet from getting started to learning the ninth day -- system operation of applet
- H5 cloud image background reading and writing CAD files - Online CAD, web CAD, web browsing and editing CAD
猜你喜欢

三、索引优化

Six ways to simplify the process adopted by it suppliers

一/二、高级篇- Mysql逻辑架构、性能与JOIN

牛客2021暑期训练4-J-Average

Information system project managers must recite the core examination points (I) six elements of the national information system

(PC+WAP)织梦模板防水建材类网站

实现两个元素并排显示 (含flex一些属性的讲解)

最常用的chrome浏览器控制台的调试技巧,你看你知道不。

hbuilder提交代码

Core examination sites for information system project managers (VI) layering of OSI protocol, mapping + real questions
随机推荐
小白挑战学c语言第一天----运行环境的搭建
uni-app做微信登录(待写完)
牛客2021暑期训练6-H-Hopping Rabbit
The seventh day of learning C language with small Bai challenge -- Enumeration, structure, community
Redis03: five common data types of redis
信息系统项目管理师核心考点(九)组织结构类型
创建线程的方式
动态规划 | 最长公共子序列
Redis01: introduction to NoSQL and redis
Information system project manager 10 days before the exam limit sprint + answer (10): summary of comprehensive knowledge
Three obstacles to the IPO of "adopt a cow"
Uni app call function
uni-app 表单提交按钮发送请求
Mobile Robotics (I) fundamentals of Mathematics
c# LeetCode刷题笔记1-句子中的最多单词数
1、 MySQL Foundation
现在ChaosBlade对数据库支持哪些故障的模拟呀?老师们有什么资料吗?
华为云Stack南向开放框架,帮助生态伙伴高效入云
牛客2021暑期训练1-A-Alice and Bob
牛客2021暑期训练1-H-Hash Function