单片机c51编程

来源:百度知道 编辑:UC知道 时间:2024/09/23 01:27:27
单片机实现0-999循环显示,P1接段码选则,P2接片选(共8个七段led),
c51程序如下
#include <reg51.h>
#include <intrins.h>
int k;
static unsigned long num;
void delay();
unsigned char data dis_digit;
unsigned char code dis_code[11]={0x3f,0x06,0x5b,0x4f, // 0, 1, 2, 3
0x66,0x6d,0x7d,0x07,0x7f,0x6f, 0xff};// 4, 5, 6, 7, 8, 9, off
unsigned char data dis_buf[8];
unsigned char data value;
unsigned char data dis_index;
void main()
{ int i;
i=0;
// P1 = 0xff;
//P2 = 0xff;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x17;
IE = 0x82;
//num=0;
dis_digit = 0xfe;
dis_index = 0;
P2=dis_digit;
TR0 = 1;

dis_buf[0] = dis_code[(num%100000000)/10000000];
dis_buf[1] = dis_code[(num%10000000)/1000000];
dis_buf[2] = dis_code[(num%1000000)/100000];
dis_buf[3] = dis_code[(num%100000)/10000];
dis_buf[4] = dis_code[(num%10000)/1000];
dis_buf[5] = dis_code[

也不晓楼主把这个C程序发出来,有不有什么问题需要帮助的
我自各儿做的一个数字钟:00-00-00型的,为24小时制的,汇编程序和Protues都发给了你,注意查收噢!(twp……@126.com)