代码:
#include "reg51.h"
// 共阴极 0~9 若是想改为共阳极,仅需对引用的数据取反即可~, 而不是0xff-
unsigned char code seg_code[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
void delay(unsigned int time){
while(time--);
}
void main(){
unsigned char i;
while(1){
for (i = 0; i < 10; i++){ // 显示十个数字
P3 = seg_code[i]; // 共阴的引用方法 共阳:~seg[i]
delay(50000);
}
}
}
仿真图:

本文介绍了如何使用C语言在8051单片机中控制共阳极数码管显示,通过`codeseg_code`数组存储不同数字对应的段码,并利用`delay`函数实现5ms的延时。程序在无限循环中依次显示0-9的数字。
3186

被折叠的 条评论
为什么被折叠?



