?? led鐘.lst
字號:
.equ ACD =7
.equ ACO =5
.equ ACI =4
.equ ACIE =3
.equ ACIC =2
.equ ACIS1 =1
.equ ACIS0 =0
.equ MUX2 =2
.equ MUX1 =1
.equ MUX0 =0
.equ ADEN =7
.equ ADSC =6
.equ ADFR =5
.equ ADIF =4
.equ ADIE =3
.equ ADPS2 =2
.equ ADPS1 =1
.equ ADPS0 =0
.def XL =r26
.def XH =r27
.def YL =r28
.def YH =r29
.def ZL =r30
.def ZH =r31
.equ RAMEND =$25F ;Last On-Chip SRAM location
.equ XRAMEND =$25F
.equ E2END =$1FF
.equ FLASHEND=$FFF
.equ INT0addr=$001 ;External Interrupt0 Vector Address
.equ INT1addr=$002 ;External Interrupt1 Vector Address
.equ OC2addr =$003 ;Timer2 compare match Vector Address
.equ OVF2addr=$004 ;Timer2 overflow Vector Address
.equ ICP1addr=$005 ;Timer1 Input Capture Vector Address
.equ OC1Aaddr=$006 ;Timer1 Output Compare A Interrupt Vector Address
.equ OC1Baddr=$007 ;Timer1 Output Compare B Interrupt Vector Address
.equ OVF1addr=$008 ;Overflow1 Interrupt Vector Address
.equ OVF0addr=$009 ;Overflow0 Interrupt Vector Address
.equ SPIaddr =$00A ;SPI Interrupt Vector Address
.equ URXCaddr=$00B ;UART Receive Complete Interrupt Vector Address
.equ UDREaddr=$00C ;UART Data Register Empty Interrupt Vector Address
.equ UTXCaddr=$00D ;UART Transmit Complete Interrupt Vector Address
.equ ADCCaddr=$00E ;ADC Conversion Complete Interrupt Vector Address
.equ ERDYaddr=$00F ;EEPROM Write Complete Interrupt Vector Address
.equ ACIaddr =$010 ;Analog Comparator Interrupt Vector Address .def TEMP =r16
.def TEMP1 =r17
.def temp2 =r18
.def temp3 =r19
.def CNT =r20
.def SCNN =r21
.def KSNI =r22
.def SCNDP =r23
.def KEYN =r24
.def cnt1 =r25
.def hour=r24
.def minute=r22
.def second=r21
.equ label=$0f00 ;字形表首址
.org $0000
000000 c02f rjmp reset
.org $007
000007 e608 intt0: ldi temp,104 ;因25ms內差40us故補上40/(1/8)即320個CK。
000008 950a bu: dec temp ;因中斷需4CK這樣:4+104*(1+2)+1+1+1+1=320。
000009 f7f1 brne bu
00000a 0000 nop
00000b 9593 inc cnt1 ;cnt1計數40次為1秒鐘。
00000c e30d ldi temp,256-195 ;計數(256-195)次才產生1次中斷。
00000d bf02 out tcnt0,temp ;CK/1024分頻,這樣一次中斷需25ms。
00000e c074 rjmp recog
.org $030
reset:
000030 e50f ldi temp,low(ramend) ;設置堆棧指針。
000031 bf0d out spl,temp
000032 e002 ldi temp,high(ramend)
000033 bf0e out sph,temp
000034 2422 clr r2 ;清工作寄存器。
000035 2433 clr r3
000036 2444 clr r4
000037 2455 clr r5
000038 2466 clr r6
000039 2477 clr r7
00003a 27ff clr zh
00003b 27bb clr xh
00003c 27dd clr yh
00003d 2788 clr keyn
00003e 2755 clr second
00003f 2766 clr minute
000040 2788 clr hour
000041 2744 clr cnt
000042 27dd clr yh
000043 e800 ldi temp,$80
000044 2e80 mov r8,temp ;R8=$80
000045 e6c0 ldi yl,$60 ;設置顯示內存地址指針Y為$0060.
000046 d06b rcall disram ;調用DISRAM。
000047 8108 ld temp,y
000048 e810 ldi temp1,$80
000049 0f01 add temp,temp1
00004a 8308 st y,temp
00004b e007 scanad: ldi temp,$07
00004c e6c0 ldi yl,$60
00004d d090 scann: rcall scan1 ;調用鍵掃顯示子程序SCAN1。
00004e f3f6 brts scann
00004f d08e scank: rcall scan1
000050 f7f6 brtc scank
000051 d08c rcall scan1
000052 0000 scans: nop
000053 3180 cpi keyn,$10 ;KEYN=$10轉EXEC。
000054 f428 brcc exec
000055 d06f rcall wraddram ;調用WRADDRAM。
000056 950a dec temp ;TEMP減1。
000057 3001 cpi temp,$01
000058 f7a1 brne scann ;TEMP=1則轉SCANN
000059 cff1 rjmp scanad
00005a 2d17 exec: mov temp1,r7 ;把r7,r6的兩個十進制換成一個十六進制入hour中
00005b 2d06 mov temp,r6
00005c d04a rcall dechex
00005d 2f80 mov hour,temp
00005e 2d15 mov temp1,r5 ;把r5,r4的兩個十進制換成一個十六進制入minute中
00005f 2d04 mov temp,r4
000060 d046 rcall dechex
000061 2f60 mov minute,temp
000062 2d13 mov temp1,r3 ;把r3,r2的兩個十進制換成一個十六進制入second中
000063 2d02 mov temp,r2
000064 d042 rcall dechex
000065 2f50 mov second,temp
000066 e005 ldi temp,$05 ;T0設置為CK/1024分頻。
000067 bf03 out tccr0,temp
000068 e30d ldi temp,256-195
000069 bf02 out tcnt0,temp ;裝載T0時間常數。
00006a ef0f ldi temp,$ff ;設置b口,d口為輸出
00006b bb07 out ddrb,temp
00006c bb01 out ddrd,temp
00006d 9478 sei ;開中斷總開關
00006e e002 ldi temp,$02
00006f bf09 out timsk,temp ;允許t0中斷。
000070 d041 display:rcall disram ;調用disram
000071 27dd clr yh ;設置顯示內存地址指針Y為$0060
000072 e6c0 ldi yl,$60
000073 ed7f ldi scndp,$df ;設置掃描顯示碼SCNDP起址0B11011111.
000074 9019 agdis: ld r1,y+
000075 36c2 cpi yl,$62
000076 f409 brne npoint
000077 0c18 add r1,r8
000078 36c4 npoint: cpi yl,$64
000079 f409 brne next
00007a 0c18 add r1,r8
00007b ba18 next: out portb,r1 ;把R1送B口顯示
00007c bb72 out portd,scndp ;掃亮某個數碼管
00007d 9408 sec ;C=1
00007e 9577 ror scndp ;右移SCNDP
00007f d056 rcall delay ;延時
000080 36c6 cpi yl,$66
000081 f791 brne agdis ;未掃亮最后一位繼續
000082 cfed rjmp display
000083 3298 recog: cpi cnt1,40 ;40次中斷為40*25ms=1秒
000084 f4d1 brne inthome ;40次中斷未到轉inthome
000085 2799 clr cnt1 ;40次中斷到則清cnt1
000086 9553 inc second ;秒寄存器加1
000087 335c cpi second,60
000088 f451 brne change ;秒寄存器未滿轉change
000089 2755 clr second ;否則清秒寄存器
00008a 9563 inc minute ;分寄存器加1
00008b 336c cpi minute,60
00008c f431 brne change ;分寄存器未滿轉change
00008d 2766 clr minute ;否則清分寄存器
00008e 9583 inc hour ;時寄存器加1
00008f 3188 cpi hour,24
000090 f411 brne change ;時寄存器未滿轉change
000091 2788 clr hour ;否則清時寄存器
000092 9518 reti ;中斷返回
000093 2f05 change: mov temp,second ;把second中的十六進制轉換成二個十進制數存入r3,r2中
000094 d00b rcall hexdec
000095 2e31 mov r3,temp1
000096 2e20 mov r2,temp
000097 2f06 mov temp,minute ;把minute中的十六進制轉換成二個十進制數存入r5,r4中
000098 d007 rcall hexdec
000099 2e51 mov r5,temp1
00009a 2e40 mov r4,temp
00009b 2f08 mov temp,hour ;把hour中的十六進制轉換成二個十進制數存入r7,r6中
00009c d003 rcall hexdec
00009d 2e71 mov r7,temp1
00009e 2e60 mov r6,temp
00009f 9518 inthome:reti ;中斷返回
0000a0 2711 hexdec: clr temp1 ;把temp中的十六進制轉成二個十進制入temp1,temp中的子程序
0000a1 500a hexdec1:subi temp,10
0000a2 f010 brcs negs
0000a3 9513 inc temp1
0000a4 cffc rjmp hexdec1
0000a5 5f06 negs: subi temp,$f6
0000a6 9508 ret ;子程序返回
0000a7 930f dechex: push temp ;把temp1,temp的兩個十進制數轉換成一個十六進制入temp中
0000a8 e02a ldi temp2,$0a
0000a9 2700 clr temp
0000aa 3010 dechex1:cpi temp1,$00
0000ab f019 breq dh
0000ac 951a dec temp1
0000ad 0f02 add temp,temp2
0000ae cffb rjmp dechex1
0000af 911f dh: pop temp1
0000b0 0f01 add temp,temp1
0000b1 9508 ret ;子程序返回
0000b2 93cf disram: push yl ;壓棧保護
0000b3 93ef push zl
0000b4 93af push xl
0000b5 e1fe ldi zh,high(label*2) ;Z指針指向字形表首址label*2
0000b6 e0e0 ldi zl,low(label*2)
0000b7 27bb clr xh
0000b8 e6a0 ldi xl,$60
0000b9 e0c7 ldi yl,$07
0000ba 8128 ramag: ld temp2,y ;y為間址的內容送temp2
0000bb 95ca dec yl
0000bc 2fe2 mov zl,temp2
0000bd 95c8 lpm
0000be 920d st x+,r0 ;把r0的內容送到$0060-$0065中
0000bf 36a6 cpi xl,$66
0000c0 f7c9 brne ramag
0000c1 91af pop xl
0000c2 91ef pop zl
0000c3 91cf pop yl ;退棧
0000c4 9508 ret ;子程序返回
0000c5 930f wraddram:push temp ;讀鍵存入顯示內存及寄存器中。
0000c6 27ff clr zh
0000c7 2fe0 mov zl,temp
0000c8 8380 st z,keyn
0000c9 e1fe ldi zh,high(label*2)
0000ca 2fe8 mov zl,keyn
0000cb 95c8 lpm
0000cc 9209 st y+,r0
0000cd 36c6 cpi yl,$66
0000ce f409 brne pointc
0000cf e6c0 ldi yl,$60
0000d0 8128 pointc: ld temp2,y
0000d1 e830 ldi temp3,$80
0000d2 0f23 add temp2,temp3
0000d3 8328 st y,temp2
0000d4 910f pop temp
0000d5 9508 ret ;子程序返回
0000d6 930f delay: push temp ;延時子程序
0000d7 e120 lp1: ldi temp2,$10
0000d8 950a lp2: dec temp
0000d9 f7f1 brne lp2
0000da 952a dec temp2
0000db f7e1 brne lp2
0000dc 910f pop temp
0000dd 9508 ret ;子程序返回
0000de 93bf SCAN1: push xh ;鍵盤掃描顯示子程序。
0000df 93af PUSH XL
0000e0 931f PUSH TEMP1
0000e1 930f PUSH TEMP
0000e2 e6a0 LDI XL,$60
0000e3 9468 SET
0000e4 e050 LDI SCNN,$00
0000e5 ed7f LDI SCNDP,0B11011111
0000e6 e046 LDI CNT,$06
0000e7 ef67 LDI KSNI,0B11110111
0000e8 ef0f COL1: LDI TEMP,$FF
0000e9 bb07 OUT DDRb,TEMP
0000ea bb04 OUT DDRC,TEMP
0000eb bb05 OUT PORTC,TEMP
0000ec bb01 OUT DDRd,TEMP
0000ed bb72 OUT PORTd,SCNDP
0000ee 901d LD R1,X+
0000ef ba18 OUT PORTb,R1
0000f0 dfe5 RCALL DELAY
0000f1 2f04 MOV TEMP,CNT
0000f2 5003 SUBI TEMP,$03
0000f3 f0a0 BRCS NOSK
0000f4 e014 LDI TEMP1,$04
0000f5 e00f LDI TEMP,0B00001111
0000f6 bb04 OUT DDRc,TEMP
0000f7 bb65 OUT PORTc,KSNI
0000f8 d01b RCALL DELYT
0000f9 b303 IN TEMP,PINc
0000fa 7f00 ANDI TEMP,0B11110000
0000fb 9502 SWAP TEMP
0000fc 9408 KROW: SEC
0000fd 9507 ROR TEMP
0000fe f020 BRCS NOKEY
0000ff 94e8 CLT
000100 2f85 MOV KEYN,SCNN
000101 9b87 SBIS PINd,$07
000102 9640 ADIW KEYN,$10
000103 9553 NOKEY: INC SCNN
000104 951a DEC TEMP1
000105 f7b1 BRNE KROW
000106 9408 SEC
000107 9567 ROR KSNI
000108 9408 NOSK: SEC
000109 9577 ROR SCNDP
00010a 954a DEC CNT
00010b f6e1 BRNE COL1
00010c ef0f LDI TEMP,$FF
00010d bb04 OUT DDRC,TEMP
00010e bb05 OUT PORTC,TEMP
00010f 910f POP TEMP
000110 911f POP TEMP1
000111 91af POP XL
000112 91bf pop xh
000113 9508 RET
000114 e230 delyt: ldi temp3,$20
000115 953a dt31:dec temp3
000116 f7f1 brne dt31
000117 9508 ret
.cseg
.org $0f00
.dw 0x063f,0x4f5b,0x6d66,0x077d
000f00 063f
000f01 4f5b
000f02 6d66
000f03 077d
.dw 0x6f7f,0x7c77,0x5e39,0x7179 000f04 6f7f
000f05 7c77
000f06 5e39
000f07 7179
Assembly complete with no errors.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -