51单片机-跑马灯例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include "reg52.h" #include "intrins.h" #include <stdio.h> typedef unsigned int u16; typedef unsigned char u8; typedef unsigned int uint ; typedef unsigned char uchar; #define LED_PORT P2 #define SMG_A_DP_PORT P0 u8 gsmg_code[17] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; void delayms(u16 ten_us) { while (ten_us--) ; } sbit led1 = P2 ^ 3; sfr LED = 0xA0; void main() { // led1 = 0; // u8 i = 0; // LED_PORT = ~0x01; // uchar aa = 0xfe; uchar aa = 0x7f; while (1) { LED = aa; delayms(50000); aa = _cror_(aa, 1); if (aa == 0xfe) { while (1) { LED = aa; delayms(50000); aa = _crol_(aa, 1); if (aa == 0x7f) { break ; } } } // aa = _crol_(aa, 1); // led1 = 0; // delayms(50000); // led1 = 1; // delayms(50000); // for (i = 0; i < 4; i++) // { // led1 = 0; // delayms(50000); // led1 = 1; // // LED_PORT = _crol_(LED_PORT, 2); // // printf("LED_PORT = %x\n", LED_PORT) // delayms(50000); // } // for (i = 0; i < 4; i++) // { // // LED_PORT = _cror_(LED_PORT, 2); // // printf("LED_PORT = %x\n", LED_PORT) // delayms(50000); // } // SMG_A_DP_PORT = gsmg_code[0]; } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律