找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

帮看看这个程序,怎么产生不了外部中断

[复制链接]
admin 发表于 2012-9-2 10:09:01 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#include <reg52.h>

sbit A1=P1^0;
sbit B1=P1^1;
sbit C1=P1^2;
sbit D1=P1^3;

sbit wela=P2^3;
sbit dula=P2^2;

#define coil_A1 {A1=1;B1=0;C1=0;D1=0;}
#define coil_B1 {A1=0;B1=1;C1=0;D1=0;}
#define coil_C1 {A1=0;B1=0;C1=1;D1=0;}
#define coil_D1 {A1=0;B1=0;C1=0;D1=1;}
#define coil_AB1 {A1=1;B1=1;C1=0;D1=0;}
#define coil_BC1 {A1=0;B1=1;C1=1;D1=0;}
#define coil_CD1 {A1=0;B1=0;C1=1;D1=1;}
#define coil_DA1 {A1=1;B1=0;C1=0;D1=1;}
#define coil_OFF {A1=0;B1=0;C1=0;D1=0;}

#define uchar unsigned char
#define uint unsigned int

uchar numdis;
uint Data[10],Speed,num0,num,shi,ge;

uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void Init_Timer0();
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=100;j>0;j--);
}

void display(uint shi,uint ge)
{


static uchar i=0;
shi=Data[i];
ge=Data[i+1];


dula=1;
P0=table[shi];
dula=0;
P0=0xff;

wela=1;
P0=0xfe;
wela=0;
delay(5); //延时

dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);

}
main()
{

uint i=512;
Init_Timer0();

EA=1;
EX0=1;
IT0=1;


Speed=3;
Data[0]=Speed/10;
Data[1]=Speed%10;




while(1)
{

coil_OFF

while(i--)
{
coil_A1
delay(Speed);
coil_AB1
delay(Speed);
coil_B1
delay(Speed);
coil_BC1
delay(Speed);
coil_C1
delay(Speed);
coil_CD1
delay(Speed);
coil_D1
delay(Speed);
coil_DA1
delay(Speed);
coil_A1
delay(Speed);
}
}
}
void ISR_INT0() interrupt 0
{
if(!INT0)
{
delay(10);
if(!INT0)
{
Speed++;

if(Speed==30);
Speed=3;

Data[0]=Speed/10;
Data[1]=Speed%10;

}
}
}

void Init_Timer0()
{
TMOD |=0x01;

EA=1;
ET0=1;
TR0=1;
PT0=1;



}

void Timer0_isr() interrupt 1
{

TH0=(65536-2000)/256;
TL0=(65536-2000)%256;


display(0,3);

}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 15:41 , Processed in 0.054007 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表