Freescale mc9s08aw60 Compilation Study notes (eight)

Source: Internet
Author: User

The ability to display numbers and letters in seven-segment led digital tubes, to show them at the same time, and even to scroll, has been pretty good, but not enough, and we want to achieve more accurate control, so that the digital tube is shown in our mind instead of a stiff loop, so we introduce the idea of interruption. Perhaps other people from the relationship between the query and interrupt to lead to the interruption, but I still tend to from the control point of view to lead to interruption, after all, the interruption is to achieve more intuitive human control method, the operation of the program can be added to the wishes of the execution, if we want to let the program into an interrupt program, Then send an interrupt to the main program, let it jump into the interrupt subroutine to run the line, we do not interrupt, the interrupt subroutine will not be executed. Or a seven-segment led digital tube to demonstrate that we did not send an interrupt signal, the digital tube in the 0~9 between the change of a bit. The code is as follows:

INCLUDE Mc9s08aw60.inc

ORG $0070
Irq_count ds.b 1


ORG $1860
Tab:dc.b $c 0, $f 9, $a 4, $b 0,$99,$92,$82, $f 8,$80,$90,$88,$83, $a 7, $a 1,$86,$8e

Io_init:
MOV #$00,ptbd
MOV #$00,ptdd
MOV # $FF, PTGD
LDA #%11111111
STA PTBDD
STA ptddd
STA PTGDD
STA Ptbds
STA Ptdds
STA Ptgds
Rts


Irq_init:; IRQ Module initialization
MOV #$00,irq_count
LDA #%00010010
STA IRQSC; IRQ feature allows, only falling edge trigger, allow interrupt
Rts


IRQ_ISR:; Interrupt sub-Program
Inc Irq_count; The main function of the Interrupt subroutine: cumulative number of interrupts
bSET 2,IRQSC; Write to Irqack 1 to clear 0 IRQF
RTI; interrupt return


Main:clra
Clrx
Clrh

JSR Io_init
STA SOPT; no cop
JSR Irq_init
CLI; open Total interrupt
MOV #$00,irq_count

Again
Clra
Clrx
Clrh

LDX Irq_count
LDA tab,x

STA PTBD
Lsra
Lsra
Lsra
Lsra
STA PTDD
MOV # $f 7,PTGD

CPX #$10
BNE Next

MOV #$00,irq_count

NEXT:JMP again


ORG $fffa
DC.W Irq_isr; IRQ interrupt Vector

ORG $fffe
DC.W Main

This program is added after the interruption, some instructions on the interruption can be see:

The program is then shown in 16-in-increments (less than 255):

INCLUDE Mc9s08aw60.inc

ORG $0070
Irq_count ds.b 1
Num ds.b 1
Count Ds.b 1

ORG $1860
Tab:dc.b $c 0, $f 9, $a 4, $b 0,$99,$92,$82, $f 8,$80,$90,$88,$83, $a 7, $a 1,$86,$8e


re_cycle:
mov #70t, num
dbnz num,*
RTS
delay_1ms:
mov #08t, Count
Re_call:
BSR re _cycle
DBNZ count,re_call
RTS

Io_init:
mov #$00,ptbd
mov #$00,ptdd
mov # $FF, ptgd lda #%11111111
STA ptbdd
STA ptddd
STA ptgdd
STA ptbds
STA ptdds
STA ptgds
RTS


Irq_init:
mov #$00,irq_count
lda #%00010010
STA IRQSC
RTS


Irq_isr:   
Inc Irq_count
bset 2,IRQSC
RTI


Main:clra
Clrx
clrh

Sta $1802
JSR io_init
Sta SOPT
JSR irq_init
CLI
mov #$00,irq_count

Again
Clra
Clrx
Clrh

LDA Irq_count
LDX #16t
Div
Pshh
Clrh
Clrx
Tax
Clra
LDA tab,x

MOV # $FB, PTGD
STA PTBD
Lsra
Lsra
Lsra
Lsra
STA PTDD
JSR delay_1ms
MOV # $FF, PTGD

Clrx
Clrh
Clra
Pula
Tax

Clrh
LDA tab,x


STA PTBD
Lsra
Lsra
Lsra
Lsra
STA PTDD
MOV # $f 7,PTGD
JSR delay_1ms
MOV # $FF, PTGD

JMP again


ORG $fffa
DC.W IRQ_ISR

ORG $fffe
DC.W Main

The idea is this: we want to show the number of interrupts, that is, the number of interrupts are displayed in 16, we will break the number of times extracted, divided by 16, to get the quotient and the remainder, the quotient as a high, we find its glyph code display into the digital tube, the remainder as a low, and do the same treatment. This allows us to achieve a 16 binary display interrupt count. Note that we deal with the remainder of the quotient first, because if we enlarge the scope of the display, we should divide the remainder first, for example, if we change the above example to the 10-input display range or the 0~255, of course, we can do this completely 0~999, we divide the number of interrupts by 100 and the quotient can deal with them directly. The remainder is divided into quotient and remainder to be processed after dividing by 10. The code is as follows:

INCLUDE Mc9s08aw60.inc

ORG $0070
Irq_count ds.b 1
Num ds.b 1
Count Ds.b 1

ORG $1860
Tab:dc.b $c 0, $f 9, $a 4, $b 0,$99,$92,$82, $f 8,$80,$90,$88,$83, $a 7, $a 1,$86,$8e


Re_cycle:
mov #70t, num
DBNZ num,*
Rts
DELAY_1MS:
mov #08t, Count
Re_call:
BSR Re_cycle
DBNZ Count,re_call
Rts

Io_init:
MOV #$00,ptbd
MOV #$00,ptdd
MOV # $FF, PTGD
LDA #%11111111
STA PTBDD
STA ptddd
STA PTGDD
STA Ptbds
STA Ptdds
STA Ptgds
Rts


Irq_init:
MOV #$00,irq_count
LDA #%00010010
STA IRQSC
Rts


IRQ_ISR:
Inc Irq_count
bSET 2,IRQSC
Rti


Main:clra
Clrx
Clrh

STA $1802
JSR Io_init
STA SOPT
JSR Irq_init
Cli
MOV #$00,irq_count

Again
Clra
Clrx
Clrh

LDA Irq_count
LDX #100t
Div
Pshh
Clrh
Clrx
Tax
Clra
LDA tab,x

MOV # $FD, PTGD
STA PTBD
Lsra
Lsra
Lsra
Lsra
STA PTDD
JSR delay_1ms
MOV # $FF, PTGD

Clrx
Clrh
Clra
Pula
LDX #10t
Div
Pshh
Clrh
Clrx
Tax
Clra
LDA tab,x

MOV # $FB, PTGD
STA PTBD
Lsra
Lsra
Lsra
Lsra
STA PTDD
JSR delay_1ms
MOV # $FF, PTGD

Clrx
Clrh
Clra
Pula
Tax
LDA tab,x


STA PTBD
Lsra
Lsra
Lsra
Lsra
STA PTDD
MOV # $f 7,PTGD
JSR delay_1ms
MOV # $FF, PTGD

JMP again


ORG $fffa
DC.W IRQ_ISR

ORG $fffe
DC.W Main

Freescale mc9s08aw60 Compilation Study notes (eight)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.