单片机数码管从00到99C语言_c51单片机驱动三位8段数码管显示0.00-9.99,c语言程序...

这篇博客介绍了如何使用C语言和C51单片机驱动共阴极数码管显示从0.00到9.99的数字。程序通过定时器实现2ms延时,避免数码管抖动,并能自动循环显示,当数值达到999后自动重置回0.00。讨论中还涉及到如何处理ADC0908的8位数字量输入,以及如何进行0-10米距离的量化显示和报警功能。
摘要由CSDN通过智能技术生成

#include &ltreg51.h&gt

unsigned char temp[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}

unsigned char table[3];

unsigned int num;

void display(unsigned int num)

{

table[0] = temp[num / 100]

table[1] = temp[num / 10 % 10 ] | 0x80;

table[2] = temp[num % 10]

}

void main()

{

EA = 1;

TMOD |= 0x21;

TH0 = 0xfc;

TL0 = 0x18;

ET0 = 1;

TR0 = 1;

while(1)

{

display(num);

}

}

void timer0() interrupt 1//定时为2ms

{

static unsigned char i = 0;

static unsigned int j = 0;

TH0 = 0xfc;

TL0 = 0x18;

j++;

if(i &lt 3)

{

P2 = 0xf8;

P1 = 0x00;

P2

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值