51单片机交通灯程序及PROTEUS仿真 集合

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#08H
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#0AH
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#08H
51单片机外接8255A做成的交通灯程序及PROTEUS仿真结果(附对应C语言程序)2010-04-21 22:01 CONTROL EQU 7FFFH
PORTA EQU 7FFCH
ORG 0
START: MOV DPTR,#7FFFH
MOV A,#80H
MOVX @DPTR,A
MOV DPTR,#7FFCH
3,3,12,21,
27,6,9,18,
21,3,3,12,
18,27,6,9,
12,21,3,3,
9,18,27,6,
3,12,21,3};
void main()
{
EA=1;
TH0=(65536-2500)/256;
TL0=(65536-2500)%256;
P2=0x02;
TMOD=0X01;
TR0=1;
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#01H
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#0CH
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYLONG
MOV A,#0AH
{
j=j+1;
if(j%2==0)n++;
if(n==4)n=0;
if(j==8)j=0;
i++;
TH0=(65536-2500)/256;
TL0=(65536-2500)%256;
if(i==160)
{
i=0;
count++;
if(count%5==0)temp++;
if(count>=180)count=0;
case 120:P2=0x30;m=5;temp=0;break; // 3号黄灯亮
case 135:P2=0x40;m=6;temp=0;break; // 4号绿灯亮
case 165:P2=0xc0;m=7;temp=0; // 4号黄灯亮
}
}
}
void time0() interrupt 1
ET0=1;
while(1)
{
if(j%2==0)
{
P3=p3[j];P1=p1[(temp1[m][n]-temp)/10];
}
else
{
P3=p3[j];P1=p1[(temp1[m][n]-temp)%10];
}
switch(count)
{
case 0:P2=0x01;m=0;temp=0;break; // 1号绿灯亮
case 30:P2=0x03;m=1;temp=0;break;// 1号黄灯亮
case 45:P2=0x04;m=2;temp=0;break;// 2号绿灯亮
case 75:P2=0x0c;m=3;temp=0;break; // 2号黄灯亮
caቤተ መጻሕፍቲ ባይዱe 90:P2=0x10;m=4;temp=0;break;// 3号绿灯亮
DELAYLONG: MOV R7,#40
L1: MOV R6,#200
L2: MOV R5,#250
DJNZ R5,$
DJNZ R6,L2
DJNZ R7,L1
RET
DELAYSHORT: MOV R4,#200
L3: MOV R3,#250
DJNZ R3,$
DJNZ R4,L3
RET
END
C语言程序:
{
unsigned i;
for(i=0;i<30000;i++);
}
===========================================
# include<reg51.h>
unsigned char i=0,j=0;
unsigned char count=0,m,n;
unsigned char temp;
unsigned char code p3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char code p1[]={0,1,2,3,4,5,6,7,8,9};
unsigned char code temp1[][4]={6,9,18,27,
while(1)
{
PORTA=0X21;
DELAYLONG();
PORTA=0X11;
DELAYSHORT();
PORTA=0X01;
DELAYSHORT();
PORTA=0X11;
DELAYSHORT();
PORTA=0X01;
DELAYSHORT();
PORTA=0X11;
DELAYSHORT();
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#11H
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#01H
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#11H
PORTA=0X01;
DELAYSHORT();
PORTA=0X0C;
DELAYLONG();
PORTA=0X0A;
DELAYSHORT();
PORTA=0X08;
DELAYSHORT();
PORTA=0X0A;
DELAYSHORT();
PORTA=0X08;
DELAYSHORT();
PORTA=0X0A;
DELAYSHORT();
PORTA=0X08;
DELAYSHORT();
}
}
void DELAYLONG(void)
{
unsigned i,j,k;
for(i=0;i<20;i++)
for(j=0;j<40;j++)
for(k=0;k<2500;k++);
}
void DELAYSHORT(void)
# include<absacc.h>
# define PORTA XBYTE[0X7FFC]
# define CONTROL XBYTE[0X7FFF]
void DELAYLONG(void);
void DELAYSHORT(void);
void main(void)
{
CONTROL=0x80;
PORTA=0XFF;
}
}
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#0AH
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
MOV A,#08H
MOV DPTR,#7FFCH
MOVX @DPTR,A
CALL DELAYSHORT
AJMP LOOP
MOV A,#0FFH
MOVX @DPTR,A
LOOP:
MOV A,#21H
MOV DPTR,#7FFCH
MOVX @DPTR,A ;东西红,南北绿
CALL DELAYLONG
MOV A,#11H
MOV DPTR,#7FFCH
MOVX @DPTR,A ;三次闪烁
CALL DELAYSHORT
MOV A,#01H
相关文档
最新文档