畢業設計微控制器的交通燈控制設計

2022-08-05 16:10:03 字數 6405 閱讀 6500

1樓:匿名使用者

org 0000h

ajmp main

org 0003h

ajmp sever

org 0030h

main:addr8279_1 equ 0bfffh

addr8279_2 equ 0bffeh

mov dptr,#addr8279_1

mov a,#0d1h

movx @dptr,a

wait:movx a,@dptr

jb acc.7,wait

mov a,#00h

movx @dptr,a

mov a,#2ch

movx @dptr,a

setb ea

setb ex0

clr it0

clr 00h

clr 01h

mov 60h,#05h ;起始5秒

mov 61h,#05h ; ;;5秒顯示

mov 62h,#14h ;20秒

mov 63h,#20h ;;20秒顯示

mov 64h,#03h ;;3秒

mov 65h,#03h ;;3秒顯示

mov 66h,#0ah ; ;10秒

mov 67h,#10h ; ;10秒顯示

main1:lcall seach1

ajmp start ;; jbc 00h,start

ajmp main1

start:mov 34h,61h

mov r2,60h

mov r0,#0fh

lcall ptfo1

s1:mov 34h,63h

mov r0,#96h

mov r2,62h

lcall ptfo1

mov r2,64h

mov 34h,65h

mov 35h,#9fh

mov 36h,#06h

lcall ptfo2

mov r2,62h

mov 34h,63h

mov r0,#69h

lcall ptfo1

mov r2,64h

mov 34h,65h

mov 35h,#6fh

mov 36h,#09h

lcall ptfo2

ajmp s1

sever:clr ex0

push 34h

push 30h

push 31h

push psw

push dph

push dpl

mov 40h,a

mov 41h,r7

mov 42h,r1

mov 34h,67h

mov p1,#0fh

mov r6,66h

last1:lcall ptfo3

lcall led

lcall delay2

djnz r6,last1

mov p1,r0

mov a,40h

mov r7,41h

mov r1,42h

pop dpl

pop dph

pop psw

pop 31h

pop 30h

pop 34h

setb ex0

reti

ptfo1:mov p1,r0

lcall ptfo3

lcall led

lcall delay2

mov dptr,#addr8279_1

movx a,@dptr

anl a,#07h

jz next1

lcall key

jbc 01h,next11

next1: djnz r2,ptfo1

retnext11:lcall seach1

jbc 00h,next1

sjmp next11

ptfo2:mov r0,35h

mov p1,r0

lcall ptfo3

lcall led

lcall delay1

mov r0,36h

mov p1,r0

lcall delay1

mov dptr,#addr8279_1

movx a,@dptr

anl a,#07h

jz next2

lcall key

jbc 01h,next12

next2: djnz r2,ptfo2

retnext12:lcall seach1

jbc 00h,next2

sjmp next12

delay1:mov r7,#0ah

ajmp delay

delay2:mov r7,#14h

delay:clr ex0

mov tmod,#01h

mov tl0,#00h

mov th0,#4ch

setb tr0

here:jbc tf0,next13

sjmp here

next13:mov tl0,#00h

mov th0,#4ch

djnz r7,here

clr tr0

setb ex0

retled:mov dptr,#addr8279_1

mov a,#90h

movx @dptr,a

mov r1,#30h

mov r7,#02h

mov dptr,#addr8279_2

loop:mov a,@r1

add a,#05h

movc a,@a+pc

movx @dptr,a

inc r1

djnz r7,loop

retdb 3fh,06h,5bh,4fh,66h,6dh

db 7dh,07h,7fh,6fh

ptfo3:mov a, 34h

clr c

subb a,#01h

jnb psw.6,next

clr c

subb a,#06h

next:mov 34h,a

anl a,#0fh

mov 30h,a

mov a,34h

anl a,#0f0h

swap a

mov 31h,a

retkey:mov dptr ,#addr8279_1

mov a,#40h

movx @dptr,a

mov dptr,#addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#0ah,key1

setb 00h

ajmp retun

key1:cjne a,#0bh,key2

setb 01h

ajmp retun

key2:cjne a,#0ch,key3

acall seach2

mov dptr ,#addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error1

error1:jc next3

mov 61h,#05h

ajmp retun

next3:swap a

mov 61h,a

acall seach2

mov dptr, #addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error2

error2:jc next4

mov 61h,#05h

ajmp retun

next4:orl 61h,a

mov a,61h

lcall bcdh

mov 60h,a

ajmp retun

key3:cjne a,#0dh,key4

acall seach2

mov dptr, #addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error3

error3:jc next5

mov 63h,#20h

ajmp retun

next5:swap a

mov 63h,a

acall seach2

mov dptr ,#addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error4

error4:jc next6

mov 63h,#20h

ajmp retun

next6:orl 63h,a

mov a,63h

lcall bcdh

mov 62h,a

ajmp retun

key4:cjne a,#0eh,key5

acall seach2

mov dptr ,#addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error5

error5:jc next7

mov 65h,#03h

ajmp retun

next7:swap a

mov 65h,a

acall seach2

mov dptr ,#addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error6

error6:jc next8

mov 65h,#03h

ajmp retun

next8:orl 65h,a

mov a,65h

lcall bcdh

mov 64h,a

ajmp retun

key5:cjne a,#0fh,retun

acall seach2

mov dptr ,#addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error7

error7:jc next9

mov 67h,#10h

ajmp retun

next9:swap a

mov 67h,a

acall seach2

mov dptr, #addr8279_2

movx a,@dptr

anl a,#3fh

cjne a,#09h,error8

error8:jc next10

mov 67h,#10h

ajmp retun

next10:orl 67h,a

mov a,67h

lcall bcdh

mov 66h,a

ajmp retun

retun: ret

seach1:mov dptr,#addr8279_1

movx a,@dptr

anl a,#07h

jz retun1

ljmp key

retun1:ret

seach2:mov dptr,#addr8279_1

movx a,@dptr

anl a,#07h

jnz retun3

sjmp seach2

retun3:ret

bcdh: mov b,#10h ;;;分離十位和個位

div ab

mov r4,b ;;;暫存個位

mov b,#10 ;;;;將十位轉換成十六進位制

mul ab

add a,r4 ;;;;;;按十六進位制加上個位

retend