Page 31 - The Journal of the Royal Society of Thailand
P. 31

วารสารราชบััณฑิิตยสภา
                                               ปีีท่� ๔๙ ฉบัับัท่� ๑ มกิราคุม-เมษาย์น ๒๕๖๗

                    ศาสตราจารย์์กิิตติคุุณ ดร.มงคุล  เดชนคุรินทร์                                         21



                           call delay1
                           mov  al,0
                           out  ppi_port2b,al    ;turn off all LEDs
                           call delay1           ;wait 0.16 sec
                           call delay1
                           inc  si               ;next byte
                           loop dspl                  ;loop 99 times

                           mov  al,byte ptr[si]  ;last (100th) byte
                           out  ppi_port2b,al    ;show and retain data on Port 2B LEDs
                           call delay2           ;wait 0.6 sec
                           call delay2
                           call delay2
                           call delay2

                           jmp  begn             ;jump to start of principal loop

                    main   endp
                    ;******************************************

                    ;Procedures
                    LedFlicker  proc
                    ;5-cycle flicker of LEDs on Port 2B
                    ;input: data byte in al
                           push ax
                           push cx
                           mov  ah,al                 ;save al in ah
                           mov  cx,5
                    rpt:   mov  al,ah                 ;retrieve al
                           out  ppi_port2b,al   ;turn ON LEDs
                           call delay2                ;0.6-sec delay
                           mov  al,0
                           out  ppi_port2b,al   ;turn OFF LEDs
                           call delay2                ;0.6-sec delay
                           loop rpt                   ;loop 5 times
                           pop  cx
                           pop  ax
                           ret
                    LedFlicker  endp
                    ;**********************************************

                    chknak proc
                    ;check NAK=1 in ah.0 after calling i2c_wr
                           and  ah,01h                ;check bit ah.0 for "1"
                           cmp  ah,00h
                           je   extpr                 ;it's ACK="0", so return
                           mov  al,11h                ;code for NAK error
                    flick: call LedFlicker            ;flicker Port 2B LEDs 5 cycles
                           jmp  flick                 ;endless exit loop
                    extpr:
                           ret
                    chknak endp
                    ;**********************************************
   26   27   28   29   30   31   32   33   34   35   36