📄 dsy.c
字号:
/**************************************************
数码管显示实验
http://www.kaifaban.com
功能:数码管显示12345678
***************************************************/
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
uchar Code[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff}; //共阳数码管编码表
uchar Bit[8]={1,2,3,4,5,6,7,8}; //数码管各位显示的数字
sbit DsySelect=P3^6; //控制数码管的74HC244所在IO口
uchar BitCode=0x80; //数码管位码初值
//延时子程序
void delay(uchar ms){
uchar i;
while(ms--){
for(i=0;i<125;i++);
}
}
//数码管扫描显示程序
void Display(){
uchar i;
for(i=0;i<8;i++){
P2=BitCode; //输出位码
P0=Code[Bit[i]]; //输出段码
BitCode=_cror_(BitCode,1); //位码循环右移一位
delay(1); //延时1ms
P0=0xFF;
}
}
//主程序
main(){
DsySelect=0; //打开数码管
P0=0xFF; //复位P0口
P2=0xFF; //复位P2口
while(1){
Display();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -