单片机的两个个简单C程序

来源:百度知道 编辑:UC知道 时间:2024/06/07 08:17:30
#include<reg52.h>
sbit p13=P1^3;
unsigned char time=0;
void main()
{ time=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(time==20)
{ time=0;
p13=0;
}
else p13=1;
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
}
麻烦大家帮我看下 为什么p1_3的等不按1s的闪
现在的情况是不亮

#include<reg52.h>
unsigned char num=0,time=0;
sbit duan=P3^7;
sbit wei=P2^1;
unsigned char code table[]
={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void main()
{
TMOD=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(time==20)
{
num=0;
num++;
if(n

第一:我已经试过,没问题
#include<reg52.h>
sbit P13=P1^3;
unsigned char time=0;
void main()
{
time=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{

if(time==0)
P13=0;
if(time==10)
P13=1;
}
}

void timer0() interrupt 1 using 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
if(time==20)
time=0;
}

第二:我写了一个,数码的公共端直接接电源,每隔一秒变一次,显示16进制数0—F;
#include<reg52.h>
unsigned char num=0,time=0;
unsigned char code table[]
={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void main()
{
TMOD=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
P0=table[num];
}
}

voi