![NEC 78K0S/K 1+ Series Application Note Download Page 27](http://html.mh-extra.com/html/nec/78k0s-k-1-series/78k0s-k-1-series_application-note_249252027.webp)
CHAPTER 4 SETTING METHODS
4.7 Main
Processing
The following operations are performed with the main processing in assembly language.
<1> The P4 register data is read.
<2> Among the read 8-bit data, bits except those of the input ports (P40, P43) are cleared to 0.
<3> Output data corresponding to the combination of the P40 and P43 input levels are extracted from addresses
0100H to 0109H (“LEDDATA” table).
<4> The extracted data is output to the P2 register.
Thanks to operations <1> and <2>, only the combination of the input levels of P40 and P43 connected to the
switches (SW1 and SW2) can be identified. In operation <3>, only data of addresses 0100H, 0101H, 0108H, and
0109H, among addresses 0100H to 0109H are used (because there are only four patterns of input level
combinations).
XTBL1 CSEG AT
0100H
LEDDATA:
DB
00000011B
;00: SW1=ON, SW2=ON -> LED3=ON
DB
00000101B
;01: SW1=OFF,SW2=ON -> LED2=ON
DB
00000111B
;02:
Dummy
DB
00000111B
;03:
Dummy
DB
00000111B
;04:
Dummy
DB
00000111B
;05:
Dummy
DB
00000111B
;06:
Dummy
DB
00000111B
;07:
Dummy
DB
00000110B
;08: SW1=ON, SW2=OFF -> LED1=ON
DB
00000111B
;09: SW1=OFF,SW2=OFF -> LED1,2,3=OFF
MOVW HL,
#LEDDATA
; Set the table address to the
;
HL
register
;*******************************************************************************
;
; Main
loop
;
;*******************************************************************************
MAIN_LOOP:
MOV
A,
P4
; Read switch-input status
AND
A,
#00001001B
; Mask the data except the switch-input status
MOV L,
A
; Set switch-input status to the lower
; 8 bits of the table address
MOV
A,
[HL]
; Read LED output data from the table
MOV
P2, A
; Output the LED light
BR
$MAIN_LOOP
; Go to the MAIN_LOOP
Address 0100H
Main processing
The data of
address 0100H,
0101H, 0108H,
or 0109H (data
of the underlined
part) is read.
Correspondences of bits 0 and 3 between SW1 and SW2, and P4
<1>
(a) SW1 = SW2 = ON:
P40 = P43 = 0
(b) SW1 = OFF, SW2 = ON: P40 = 1, P43 = 0
(c) SW1 = ON, SW2 = OFF: P40 = 0, P43 = 1
(d) SW1 = SW2 = OFF:
P40 = P43 = 1
The address of the A register after operation is 00H ((a)
above), 01H ((b) above), 08H ((c) above), or 09H ((d) above).
ROM area setting
Correspondences between the P2
output value and LEDs 1 to 3
(a) P2 = 00000011: Lights only LED3.
(b) P2 = 00000101: Lights only LED2.
<2>
<3>
<4>
(c) P2 = 00000110: Lights only LED1.
(d) P2 = 00000111: Lights off all LEDs.
Application Note U18752EJ2V0AN
27