#include <stc12c5a60s2.h> #define uchar unsigned char #define uint unsigned int //…
- User
#include <stc12c5a60s2.h>
#define uchar unsigned char #define uint unsigned int
// 延时函数(大约 1 ms @11.0592MHz) void delay_ms(uint ms) { uint i, j; while (ms--) for (i = 0; i < 110; i++) for (j = 0; j < 1; j++); }
// 7 层灯选通信号(低电平选中该层) sbit L1 = P3^0; sbit L2 = P3^1; sbit L3 = P3^3; sbit L4 = P3^4; sbit L5 = P3^5; sbit L6 = P3^6; sbit L7 = P3^7; sbit L8 = P2^0; // 如果只有 7 层,可忽略此行
// 推挽/锁存控制(如果原来用 P4.6 做列锁存,则保留;否则可直接不用) sbit COL_LATCH = P4^6;
// 主函数 void main(void) { uchar i, pattern;
// 1)端口模式全部推挽输出 P0M0 = 0xFF; P0M1 = 0x00; // P0 作为列输出 P1M0 = 0xFF; P1M1 = 0x00; // 如果 P1 有扩展列,可一并设 P2M0 = 0x00; P2M1 = 0x00; // P2.0(L8) 作为层选,剩余不动 P3M0 = 0x00; P3M1 = 0x00; // P3.0~P3.7 全作层选 P4M0 = 0xFF; P4M1 = 0x00; // P4.6 作为锁存 // 初始:关闭所有层 L1 = L2 = L3 = L4 = L5 = L6 = L7 = 1; COL_LATCH = 1; while (1) { // 让所有层都选通(低电平有效) L1 = L2 = L3 = L4 = L5 = L6 = L7 = 0; // 列数据做 1→2→4→…→128 的流水(共 8 列) pattern = 0x01; for (i = 0; i < 8; i++) { P0 = pattern; // P0 输出当前列 COL_LATCH = 0; // 如果需要锁存 COL_LATCH = 1; delay_ms(100); // 刷新间隔,可调 pattern <<= 1; // 下一个列 } // 全灭 P0 = 0x00; delay_ms(200); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.