logo
Микропроцессорные системы (УМКдляАИТ) / МетодУказания / ST7Програм

Приложение а

st7/ ; The first line is reserved for specifying the instruction

; set of the targeted processor

; ------ EXERCICE: BASIC USE OF THE LED --------------------

; Copyright (c), STMicroelectronics

;------------------------------------------------------------------------------

; The present source code which is for guidance only aims at providing

; customers with information regarding their products in order for them to save

; time. As a result, STMcroelectronics shall not be held liable for any direct,

; indirect or consequential damages with respect to any claims arising from the

; content of such a source code and/or the use made by customers of the

; information contained herein in connexion with their products.

; ------------------------------------------------------------------------------

; File: Exo_Template-LED.asm

; =============================================

; SOFTWARE DESCRIPTION:

; -------------- Turn "On" and Off the 8 LEDs ---------------

; AUTHOR:

; DESCRIPTION: This exercise consists of turn "On" and Turn "off"

; sequentially ODD and EVEN

; Turn "On" EVEN LED (1-3-5-7)

; Turn "Off" ODD LED (2-4-6-8)

; and 0.5 sec temporisation  

; Then Turn "Off" EVEN LED (1-3-5-7)

; and Turn "On" ODD LED (2-4-6-8).

TITLE "EX_LED-EVEN_ODD.asm"

MOTOROLA

#include "ST7Lite2.INC"

; ----------------Declaration in 'ram0'-------------------------

; Declaration variable zone

BYTES

segment byte 'ram0'

tempo_0 DS.B 1 ; for storing of result of

; the divider 4000000/100010 = 40

; in the subroutine tempo

tempo_1 DS.B 1 ; for storing of $7F in the subroutine tempo

;End variable declaration

;-------------------------- Zone 'rom' ----------------------

;- Constant declaration zone

WORDS

segment byte 'rom'

; This program don't use constant

; the reason why, this part is empty

; End declaration zone for constant

;------------------ Sub-program Zone -------------------------

; Configuration Port A & B

; Port_A: PA7=LED5, PA4=LED4, PA3=LED3, PA1=LED2, PA0=LED1

; Port_B: PB4 = LED6, PB5 = LED7, PB6 = LED8.

; PB7 = Reset push bottom of the ST7 (External Hardware reset)

init_ports:

ld A,#$9B ; configuration DATA DIRECTION register Port A.

ld PADDR,A ; PA7, PA4,PA3, PA1,PA0 = 1 (output)

; PA6,PA5& PA2 = 0 (input)

ld PAOR,A ; PA7, PA4,PA3, PA1,PA0 = 1 (Push pull)

; PA6,PA5 and PA2 = 0 (Hi-impedance)

ld A,#$70 ; configuration DATA DIRECTION register Port B.

ld PBDDR,A ; PB6, PB5, PB4 = 1 (Output)

; PB7, PB3, PB2, PB1, PB0 = 0 (input)

ld PBOR,A ; PB6, PB5, PB4 = 1 ( Push Pull)

; PB7, PB3, PB2, PB1, PB0 = 0(Hi- impedance)

ret

;---------------- sub-program Turn_on_Even ---------------------------------

; DESCRIPTION Application Subroutine : This routine consists of Turn "On" EVEN LED

Turn_on_Even1: ; connection : PA0 = LED1, PA3 = LED3,PA7 =LED5, PB5 = LED7

bset PADR,#0 ; set bit0 = "1" of DATA register PA0 = LED1

bset PADR,#3 ; set bit3 = "1" of DATA register PA3 = LED3

bset PADR,#7 ; set bit7 = "1" of DATA register PA7 = LED5

bset PBDR,#5 ; set bit5 = "1" of DATA register PB5 = LED7

ret ; Return to main program

;---------------- sub-program Turn_off_Even ---------------------------------

; DESCRIPTION Application Subroutine : This routine consists of Turn "Off" EVEN LED

Turn_off_Even1:

bres PADR,#0 ; reset bit0 = 0 in the register data "PA0 = LED1"

bres PADR,#3 ; reset bit3 = 0 in the register data "PA3 = LED3"

bres PADR,#7 ; reset bit7 = 0 in the register Data "PA7 = LED5"

bres PBDR,#5 ; reset bit5 = 0 in the register Data "PB5 = LED7"

ret ; Return to main program

; DESCRIPTION Application Subroutine : This routine consists of Turn "On" ODD LED

; Connection ODD LED

; PA1=LED2, PA4=LED4, PB4 = LED6, PB6 = LED8.

Turn_on_Even2:

bset PADR,#1 ; set bit1 = "1" of DATA register PA1 = LED2

bset PADR,#4 ; set bit4 = "1" of DATA register PA4 = LED4

bset PBDR,#4 ; set bit4 = "1" of DATA register PB4 = LED6

bset PBDR,#6 ; set bit6 = "1" of DATA register PB6 = LED8

ret ; Return to main program

; DESCRIPTION Application Subroutine : This routine consists of Turn "Off" ODD LED

; Connection ODD LED

; PA1=LED2, PA4=LED4, PB4 = LED6, PB6 = LED8

Turn_off_Even2:

bres PADR,#1 ; reset bit1 = "0" of DATA register PA1 = LED2

bres PADR,#4 ; reset bit4 = "1" of DATA register PA4 = LED4

bres PBDR,#4 ; reset bit4 = "1" of DATA register PB4 = LED6

bres PBDR,#6 ; reset bit6 = "1" of DATA register PB6 = LED8

ret ; Return to main program

; --- Temporisation 0.5s subroutine program by using instruction set -------------

wait_for: ; “label =Wait_for”

ld A,#40 ; Frequency : 4 000 000 cycles,

; 4000000/100010 = 40 result of the divider  

; strore the result 40 in the tempo_0 (variable)

ld tempo_0,A ;

; loop_0= 14 + 78 x 1282 = 100 010 cycles

loop_0

ld A,#$7F ; 2 cycles

ld tempo_1,A ; 4 cycles

loop_1

nop ; 2 cycles, loop_1 = 12 cycles + 1270 cycles

ld X,#$7F ; 2 cycles, loop_2 = 10 cycles

loop_2

rlc Y ; 4 cycles

dec X ; 3 cycles

jrne loop_2 ; 3 cycles

dec tempo_1 ; 5 cycles

jrne loop_1 ; 3 cycles (Jump if Z = 0 /not equal : go to label loop_1)

dec tempo_0 ; 5 cycles

jrne loop_0 ; 3 cycle

ret ; return to main Program

; ---- END Sub-Program temporization named "wait_for" ----

; --------- MAIN Program ----------

main:

RSP ; Reset stack RAM

call init_ports ; Call init I_O port subroutine program

clr PADR ; Clear Data register of Port A ( Turn off all LEDs)

clr PBDR ; clear Data register of Port B ( Turn Off all LEDs)

loop

call Turn_on_Even1 ; Call subroutine Turn_on_Even1

call wait_for ; Call subroutine temporization of 0.5s named wait_for

call Turn_off_Even1 ; Call subroutine program Turn_off_Even1 (EVEN_LED --> Off)

call Turn_on_Even2 ; Call subroutine program Turn_on_Even2 (ODD_LED --> ON)

call wait_for ; Call subroutine program temporization "wait_for"

call Turn_off_Even2 ; Call subroutine program Turn_off_Even2 (ODD_LED --> Off)

JP loop ; retour vers loop

;------------------- Sous-Programmes d’interruptions -----------------------

dummy_rt: IRET ; Empty procedure: back to the main program.

;------------------- INTERRUPT VECTORS MAPPING -----------------------------

segment 'vectit'

DC.W dummy_rt ; Address FFE0-FFE1h

SPI_it DC.W dummy_rt ; Address FFE2-FFE3h

lt_RTC1_it DC.W dummy_rt ; Address FFE4-FFE5h

lt_IC_it DC.W dummy_rt ; Address FFE6-FFE7h

at_timerover_it DC.W dummy_rt ; Address FFE8-FFE9h

at_timerOC_it DC.W dummy_rt ; Address FFEA-FFEBh

AVD_it DC.W dummy_rt ; Address FFEC-FFEDh

DC.W dummy_rt ; Address FFEE-FFEFh

lt_RTC2_it DC.W dummy_rt ; Address FFF0-FFF1h

ext3_it DC.W dummy_rt ; Address FFF2-FFF3h

ext2_it DC.W dummy_rt ; Address FFF4-FFF5h

ext1_it DC.W dummy_rt ; Address FFF6-FFF7h

ext0_it DC.W dummy_rt ; Address FFF8-FFF9h

AWU_it DC.W dummy_rt ; Address FFFA-FFFBh

softit DC.W dummy_rt ; Address FFFC-FFFDh

reset DC.W main ; Address FFFE-FFFFh

END