2.1、实验目的
8位共阴数码管显示8位以内的数字
2.2、实验环境
普中51开发板(stc89c52、74HC245、74HC138、8位共阴数码管)
2.3、实验代码
#include<reg52.h>
#include<intrins.h>
typedef unsigned char u8;
typedef unsigned int u16;
static u8 digital_buffer[8];
static u8 digital_code[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay1ms(u8 count){
int i,j;
while(count>0){
count=count-1;
_nop_();
i=2;
j=199;
do{
while(--j);
}while(--i);
}
}
void DigitalTube_Single(u16 dig,u16 dat){
P0 = 0x00;
P2 = P2 | 0xc7;
dat = dig << 3;
P2 = P2 | dat;
P0 = dat;
}
void DigitalTube_Flush(){
u8 i = 0;
for(i;i<8;i++){
DigitalTube_Single(i,digital_buffer[i]);
delay1ms(10);
}
}
void DigitalTube_Num(u16 num){
u8 i=0;
for(i;i<8;i++){
digital_buffer[i] = 0x00;
}
i=7;
while(num>0){
digital_buffer[i] = digital_code[num%10];
num = num / 10;
i = i - 1;
}
}
void main(){
DigitalTube_Num();
while(1){
DigitalTube_Flush();
}
}
标签:count,u8,单片机,void,51,数码管,while,digital
From: https://www.cnblogs.com/keeepfool/p/18533652