89C52单片机的共阴数码管怎么显示数字0-99(c语言)
时间:10-02
整理:3721RD
点击:
为什么十位会和个位显示一样
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit d1=P1^0;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
uchar ge,shi,aa;
uint temp;
void main()
{
temp = 0;
TMOD = 0x01;
TH0=(65536-50000)/256;
TH0=(65536-50000)%256;
EA = 1;
ET0 = 1;
TR0=1;
aa=0;
while(1){
shi=temp/10;
ge=temp%10;
dula=1;
P0=table[shi];
dula=0;
P0=0xc0;
wela=1;
P0=0xc1;
wela=0;
dula=1;
P0=table[ge];
dula=0;
P0=0xc0;
wela=1;
P0=0xc2;
wela=0;
}
}
void timer0 () interrupt 1
{
TH0 = (65536 - 50000)/256;
TL0 = (65536 - 50000)%256;
aa++;
if(aa==20){
if(temp==99)
temp=0;
temp++;
aa=0;
}
}
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit d1=P1^0;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
uchar ge,shi,aa;
uint temp;
void main()
{
temp = 0;
TMOD = 0x01;
TH0=(65536-50000)/256;
TH0=(65536-50000)%256;
EA = 1;
ET0 = 1;
TR0=1;
aa=0;
while(1){
shi=temp/10;
ge=temp%10;
dula=1;
P0=table[shi];
dula=0;
P0=0xc0;
wela=1;
P0=0xc1;
wela=0;
dula=1;
P0=table[ge];
dula=0;
P0=0xc0;
wela=1;
P0=0xc2;
wela=0;
}
}
void timer0 () interrupt 1
{
TH0 = (65536 - 50000)/256;
TL0 = (65536 - 50000)%256;
aa++;
if(aa==20){
if(temp==99)
temp=0;
temp++;
aa=0;
}
}
没有人吗?
你的显示转换是不是没有做好,都做成一样的了。
完全没有看懂你得程序,可以加2381996031
主程序th0和tl0两个语句的赋值语句走错。不过这不是主要原因。shi=temp/10。ge=temp%10。这样写看看
你自己先用定时器做一个秒表 别的你就懂得啦
学习单片机,小编先买本郭天祥的书和开发板看看