Page 93 - 22-0722 EBOOK
P. 93

วารสารราชบััณฑิิตยสภา
                                         ปีีที่่� ๔๖ ฉบัับัที่่� ๓  กัันยายน-ธัันวาคม ๒๕๖๔
             ศาสตราจารย์์กิิตติคุุณ ดร.มงคุล เดชนคุรินทร์           cli             ;disable INTs   83
              int_icw2_port   equ  2dh ;8259 port 2
              int_icw4_port   equ  2dh                           mov   si,HEAD   ;init HEAD to 0
              int_ocw1_port   equ  2dh                           mov   byte ptr[si],0
              int_icw1_word   equ  00010011b ;edge trigger            mov   si,loca0  ;raw data store
                                             ;one-IC mode            push  cx
              int_icw2_port   equ  2dh ;8259 port 2             cli             ;disable INTs
              int_icw2_word  equ  01011000b  ;INT 58h-5Fh
                                                                 mov   cx,10
              int_icw4_port   equ  2dh                          mov   si,HEAD   ;init HEAD to 0
                                                        loop1:   mov   byte ptr[si],0
              int_icw4_word  equ  00000011b  ;8088 mode
              int_ocw1_port   equ  2dh                          mov   byte ptr[si],0
                                                                 inc   si
              int_ocw1_word  equ  01111111b  ;unmask IR7 only
              int_icw1_word   equ  00010011b ;edge trigger            mov   si,loca0  ;raw data store
                                                                 loop  loop1     ;clear 10 data addrs.

                                             ;one-IC mode            push  cx
                                                                 pop   cx
              ;START ADDR. OF RESERVED RAM LOCATIONS
              int_icw2_word  equ  01011000b  ;INT 58h-5Fh            mov   cx,10
                                                        here:    int   59h     ;blink lower-nibble LEDs
              ;(about 256 bytes below stack top)
              int_icw4_word  equ  00000011b  ;8088 mode   loop1:   mov   byte ptr[si],0
                                                                 int   59h     ;on 8255(2) Port2B
              HEAD  equ  7EE8h ;head of ring buffer
              int_ocw1_word  equ  01111111b  ;unmask IR7 only            inc   si
              buf0  equ  7EECh ;addr: 1st char from uC PIC16
                                                                 int   59h
                dat0  equ  7EF6h ;addr: 1st bit to send            loop  loop1     ;clear 10 data addrs.

              ;START ADDR. OF RESERVED RAM LOCATIONS            pop   cx
                                                        ;set CLK (P1C3) & DAT (P1B3) high (Idle State)
              loca0 equ  7F00h ;addr: 1st raw byte from PIC16
              ;(about 256 bytes below stack top)       here:    int   59h     ;blink lower-nibble LEDs
                                                                 mov   al,08h

              HEAD  equ  7EE8h ;head of ring buffer             int   59h     ;on 8255(2) Port2B
                       org   8000h ;start of ROM program
                                                                 out   ppi_port1_c,al ;P1C3=hi
              buf0  equ  7EECh ;addr: 1st char from uC PIC16            int   59h
              main     proc
                                                                 out   ppi_port1_b,al ;P1B3=hi
              dat0  equ  7EF6h ;addr: 1st bit to send              sti           ;enable INTs
                       cli         ;prevent sys. interrupts
              loca0 equ  7F00h ;addr: 1st raw byte from PIC16    ;set CLK (P1C3) & DAT (P1B3) high (Idle State)


                                                                mov   al,08h
                                                        ;get raw data
              ;segment setup
                       org   8000h ;start of ROM program            out   ppi_port1_c,al ;P1C3=hi
                                                        here1:   mov   si,HEAD ;head of ring buffer
                       mov   ax,0  ;set all segments to 0000
              main     proc                                     out   ppi_port1_b,al ;P1B3=hi
                                                                 mov   al,byte ptr[si]
                       mov   ds,ax
                       cli         ;prevent sys. interrupts            sti           ;enable INTs
                       mov   es,ax
                                                                 cmp   al,10   ;expect 11 data items
                         mov   ss,ax                              jb    here1
              ;segment setup                           ;get raw data
                       mov   ax,7FFEh ;stack top in RAM
                                                        ;process raw data into 8-bit code
                       mov   ax,0  ;set all segments to 0000   here1:   mov   si,HEAD ;head of ring buffer
                       mov   sp,ax
                                                        ;dl = bit count = 0-7, dh = code accumulator
                       mov   ds,ax                              mov   al,byte ptr[si]
                                                        loop2:

                       mov   es,ax                              cmp   al,10   ;expect 11 data items
                                                                 mov   dl,0    ;reset dl & dh when dl=8
              ;config. 8255(1) and 8255(2) for data exchange
                       mov   ss,ax                              jb    here1
                                                                 mov   dh,0    ;dh = partial code
                       mov   al,10011000b ;mode 0
                       mov   ax,7FFEh ;stack top in RAM   ;process raw data into 8-bit code
                       ;on groups A&B, Ports A=in, B & C=out
                                                        ;assemble bits 0-7
                       mov   sp,ax                     ;dl = bit count = 0-7, dh = code accumulator
                       out   ppi_ctrl_port1,al
                                                        loop3:   shr   dh,1    ;for next higher bit
                         out   ppi_ctrl_port2,al       loop2:
                                                                 mov   si,loca0 ;addr of 1st raw data
              ;config. 8255(1) and 8255(2) for data exchange            mov   dl,0    ;reset dl & dh when dl=8
                                                                 ;***************************

                       mov   al,10011000b ;mode 0               mov   dh,0    ;dh = partial code
                                                                 inc   si      ;skip Startbit
              ;SET UP INT VECTORS 5Fh and 59h
                       ;on groups A&B, Ports A=in, B & C=out   ;assemble bits 0-7
                                                                 ;***************************
                       mov   si,(5Fh*4)        ;install 5Fh
                       out   ppi_ctrl_port1,al         loop3:   shr   dh,1    ;for next higher bit
                       mov   dx,offset kbd_isr ;5Fh ISR addr.
                                                                 mov   bl,dl  ;bit count after Startbit
                       out   ppi_ctrl_port2,al                  mov   si,loca0 ;addr of 1st raw data
                                                                 mov   bh,0
                       mov   word ptr[si],dx   ;offset -> IP
                         add   si,2                             ;***************************
                                                                 mov   al,byte ptr[si+bx] ;get raw data
              ;SET UP INT VECTORS 5Fh and 59h                   inc   si      ;skip Startbit
                                                                 and   al,10h  ;extract bit 4
                       mov   word ptr[si],0    ;segment -> CS
                       mov   si,(5Fh*4)        ;install 5Fh             ;***************************

                       mov   dx,offset kbd_isr ;5Fh ISR addr.               mov   bl,dl  ;bit count after Startbit
                       mov   word ptr[si],dx   ;offset -> IP            mov   bh,0
                                                                mov   al,byte ptr[si+bx] ;get raw data
                       add   si,2  ภาพที่ ๘  ซอฟต์แวร์การรับ-ส่งข้อมูลแบบอนุกรมของแผงวงจรไมโครคอนโทรลเลอร์ 8088
                       mov   word ptr[si],0    ;segment -> CS            and   al,10h  ;extract bit 4

                                                       ;Page 4/8 of Fig.8
              ;Page 3/8 of Fig.8

                       cmp   al,10h  ;bit4 = hi?       ;store new raw data
                      ภาพที่ ๘  ซอฟต์แวร์การรับ-ส่งข้อมูลแบบอนุกรมของแผงวงจรไมโครคอนโทรลเลอร์ 8088
                       jne   noadd   ;bit4 = lo                 mov   di,loca0
                addval:  add   dh,80h  ;add bit value to code            mov   byte ptr [di+bx],al
              ;Page 3/8 of Fig.8                       ;Page 4/8 of Fig.8
                                                                inc   bl     ;advance HEAD
              noadd:   inc   dl      ;dl = bit no.
                         cmp   dl,8    ;0 =< dl =< 7              cmp   bl,11  ;max no. of raw data=11
                       cmp   al,10h  ;bit4 = hi?       ;store new raw data
                       jb    loop3   ;repeat for another bit
                                                                jb    nofold
                       jne   noadd   ;bit4 = lo                 mov   di,loca0
                                                                mov   bl,0   ;fold back after 11 items
              read8:                 ;now dl=8
              addval:  add   dh,80h  ;add bit value to code            mov   byte ptr [di+bx],al

                       mov   byte ptr[di],dh ;store code
              noadd:   inc   dl      ;dl = bit no.              inc   bl     ;advance HEAD
                                                       nofold:  mov   byte ptr[si],bl ;new HEAD
                       inc   di      ;for next code to store
                       cmp   dl,8    ;0 =< dl =< 7              cmp   bl,11  ;max no. of raw data=11


                       jb    loop3   ;repeat for another bit            jb    nofold
              ;display the complete current code on Port2B
                                                       ;retrieve registers
              read8:                 ;now dl=8                  mov   bl,0   ;fold back after 11 items
                                                                pop   si
              showdat: cli           ;prevent INTs
                       mov   byte ptr[di],dh ;store code              pop   di
                       mov   al,dh   ;get complete code
                       inc   di      ;for next code to store   nofold:  mov   byte ptr[si],bl ;new HEAD
                                                                pop   bx
                       call  showcode
                         sti           ;enable INTs               pop   ax
              ;display the complete current code on Port2B   ;retrieve registers

                       inc   cl      ;complete code count
              showdat: cli           ;prevent INTs              pop   si
                       cmp   cl,10   ;only 10 codes received
                                                                sti          ;enable INTs
                       mov   al,dh   ;get complete code            pop   di
                       jb    init1   ;repeat
                                                                iret
                       call  showcode                           pop   bx
                                                       kbd_isr  endp

                       sti           ;enable INTs               pop   ax
              ;show stored codes received from uC PIC
                                                       ;**********************************************
                       inc   cl      ;complete code count
                       mov   di,buf0 ;addr: 1st stored code
                       cmp   cl,10   ;only 10 codes received            sti          ;enable INTs
                       mov   cx,10

                       jb    init1   ;repeat                    iret
              shwcde:  mov   al,byte ptr[di]
                                                       ;pulsing upper-4 LEDs on 8255(2) Port2B
                         call  showcode                kbd_isr  endp
                                                       pulse2   proc         ;INT 59h by software
              ;show stored codes received from uC PIC   ;**********************************************
                                                                cli          ;disable INTs
                       inc   di
                       mov   di,buf0 ;addr: 1st stored code              push  ax
                       loop  shwcde
                       mov   cx,10                       again2:  mov   al,0Fh ;Port2B's upp 4 lines hi

              shwcde:  mov   al,byte ptr[di]           ;pulsing upper-4 LEDs on 8255(2) Port2B
               ภาพท่� ๘  ซอฟตั์แวร์การรับ-ส่งข้้อมูลแบบอนีุ้กรมข้องแผงวงจรไมโครคอนี้โทรลเลอร์ 8088 (ตั่อ)
                                                                out   ppi_port2_b,al
              ;*****************************
                       call  showcode                  pulse2   proc         ;INT 59h by software
                                                                call  dly64  ;slow it down a bit
              ;8088 sends data to PIC16F627A
                       inc   di                                 cli          ;disable INTs
              ;*****************************
                                                                call  dly64  ;approx. 2x64-ms delay
                       loop  shwcde                             push  ax
                                                                mov   al,0   ;all Port2B's lines lo
              xmit:
                                                       again2:  mov   al,0Fh ;Port2B's upp 4 lines hi
              ;*****************************                    out   ppi_port2_b,al
              ;8088 sends data to PIC16F627A                    call  dly64  ;slow it down a bit
              ;*****************************                    call  dly64  ;approx. 2x64-ms delay
              xmit:                                             mov   al,0   ;all Port2B's lines lo
   88   89   90   91   92   93   94   95   96   97   98