单片机外中断汇编语言和C语言程序
时间:12-02
来源:互联网
点击:
以下两个程序效果相同,一个使用汇编语言,一个使用C语言,从仿真效果看,c语言程序运行比较流畅。
两个外中断跑马灯汇编语言程序
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP WZD0
ORG 0013H
LJMP WZD1
ORG 0040H
WZD0: MOV DPTR,#0220H
MOV R3,#42D
CB0: CLR A
MOVC A,@A+DPTR
MOV P1,A
INC DPTR
LCALL DELAY2
DJNZ R3,CB0
RETI
WZD1: MOV DPTR,#0220H
MOV R3,#42D
CB1: CLR A
MOVC A,@A+DPTR
MOV P2,A
INC DPTR
LCALL DELAY1
DJNZ R3,CB1
RETI
ORG 0150H
MAIN: MOV P1,#00H
MOV P2,#00H
SETB EA
SETB IT0
SETB EX0
CLR PX0
SETB IT1
SETB EX1
SETB PX1
ST: MOV DPTR,#0270H
MOV R4,#17D
DD: CLR A
MOVC A,@A+DPTR
MOV P0,A
INC DPTR
LCALL DELAY1
DJNZ R4,DD
SJMP ST
DELAY1: MOV R7,#00H
DD1: MOV R6,#00H
DD2: MOV R5,#01H
DJNZ R5,$
DJNZ R6,DD2
DJNZ R7,DD1
RET
DELAY2: MOV R7,#00H
DDD1: MOV R6,#00H
DJNZ R6,$
DJNZ R7,DDD1
RET
ORG 0220H
DB 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80
DB 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01
DB 0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18
DB 0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18
DB 0x18,0x00,0x3c,0x00,0x7e,0x00,0xff,0x00
ORG 0270H
DB 0xfe,0xfc,0xf8,0xe0,0xe0,0xc0,0x80,0x00
DB 0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff, 0x00
END
两个外中断跑马灯C语言程序
#include
int code yu[]={
0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,
0x00,0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18,
0x00,0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18,
0x00,0x18,0x00,0x3c,0x00,0x7e,0x00,0xff,0x00,0x00,
0x00 };
int code yu1[]={
0xfe,0xfc,0xf8,0xe0,0xe0,0xc0,0x80,0x00,
0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,
0x00};
void delay(int ms)
{
while(ms--)
{
int i;
for(i=0;i<120;i++);
}
}
void ddd() interrupt 0
{
int k;
for(k=0;k<47;k++)
{
P2=yu[k];
delay(100);
}
}
void dd() interrupt 1
{
int k;
for(k=0;k<48;k++)
{
P1=yu[k];
delay(300);
}
P1=0x00;
}
void main()
{
int n;
IT0=0;
EX0=1;
PX0=1;
IT1=0;
EX1=1;
PX1=0;
EA=1;
P1=0x00;
P2=0x00;
while(1)
{
for(n=0;n<17;n++)
{
P0=yu1[n];
delay(100);
}
}
两个外中断跑马灯汇编语言程序
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP WZD0
ORG 0013H
LJMP WZD1
ORG 0040H
WZD0: MOV DPTR,#0220H
MOV R3,#42D
CB0: CLR A
MOVC A,@A+DPTR
MOV P1,A
INC DPTR
LCALL DELAY2
DJNZ R3,CB0
RETI
WZD1: MOV DPTR,#0220H
MOV R3,#42D
CB1: CLR A
MOVC A,@A+DPTR
MOV P2,A
INC DPTR
LCALL DELAY1
DJNZ R3,CB1
RETI
ORG 0150H
MAIN: MOV P1,#00H
MOV P2,#00H
SETB EA
SETB IT0
SETB EX0
CLR PX0
SETB IT1
SETB EX1
SETB PX1
ST: MOV DPTR,#0270H
MOV R4,#17D
DD: CLR A
MOVC A,@A+DPTR
MOV P0,A
INC DPTR
LCALL DELAY1
DJNZ R4,DD
SJMP ST
DELAY1: MOV R7,#00H
DD1: MOV R6,#00H
DD2: MOV R5,#01H
DJNZ R5,$
DJNZ R6,DD2
DJNZ R7,DD1
RET
DELAY2: MOV R7,#00H
DDD1: MOV R6,#00H
DJNZ R6,$
DJNZ R7,DDD1
RET
ORG 0220H
DB 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80
DB 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01
DB 0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18
DB 0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18
DB 0x18,0x00,0x3c,0x00,0x7e,0x00,0xff,0x00
ORG 0270H
DB 0xfe,0xfc,0xf8,0xe0,0xe0,0xc0,0x80,0x00
DB 0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff, 0x00
END
两个外中断跑马灯C语言程序
#include
int code yu[]={
0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,
0x00,0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18,
0x00,0x18,0x24,0x42,0x81,0x00,0x81,0x42,0x24,0x18,
0x00,0x18,0x00,0x3c,0x00,0x7e,0x00,0xff,0x00,0x00,
0x00 };
int code yu1[]={
0xfe,0xfc,0xf8,0xe0,0xe0,0xc0,0x80,0x00,
0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,
0x00};
void delay(int ms)
{
while(ms--)
{
int i;
for(i=0;i<120;i++);
}
}
void ddd() interrupt 0
{
int k;
for(k=0;k<47;k++)
{
P2=yu[k];
delay(100);
}
}
void dd() interrupt 1
{
int k;
for(k=0;k<48;k++)
{
P1=yu[k];
delay(300);
}
P1=0x00;
}
void main()
{
int n;
IT0=0;
EX0=1;
PX0=1;
IT1=0;
EX1=1;
PX1=0;
EA=1;
P1=0x00;
P2=0x00;
while(1)
{
for(n=0;n<17;n++)
{
P0=yu1[n];
delay(100);
}
}
单片机外中断汇编语言C语言程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)