Page 94 - 22-0722 EBOOK
P. 94
int_icw2_port equ 2dh ;8259 port 2
cli ;disable INTs
int_icw4_port equ 2dh
mov si,HEAD ;init HEAD to 0
mov byte ptr[si],0
int_ocw1_port equ 2dh
int_icw1_word equ 00010011b ;edge trigger
mov si,loca0 ;raw data store
push cx
;one-IC mode
mov cx,10
int_icw2_word equ 01011000b ;INT 58h-5Fh
int_icw4_word equ 00000011b ;8088 mode
loop1: mov byte ptr[si],0
inc si
int_ocw1_word equ 01111111b ;unmask IR7 only
loop loop1 ;clear 10 data addrs.
pop cx
;START ADDR. OF RESERVED RAM LOCATIONS
;(about 256 bytes below stack top)
here: int 59h ;blink lower-nibble LEDs
int 59h ;on 8255(2) Port2B
HEAD equ 7EE8h ;head of ring buffer
buf0 equ 7EECh ;addr: 1st char from uC PIC16
int 59h
dat0 equ 7EF6h ;addr: 1st bit to send
loca0 equ 7F00h ;addr: 1st raw byte from PIC16
;set CLK (P1C3) & DAT (P1B3) high (Idle State)
mov al,08h
org 8000h ;start of ROM program
out ppi_port1_c,al ;P1C3=hi
out ppi_port1_b,al ;P1B3=hi
main proc
cli ;prevent sys. interrupts
sti ;enable INTs
;segment setup
;get raw data
here1: mov si,HEAD ;head of ring buffer
mov ax,0 ;set all segments to 0000
mov ds,ax
mov al,byte ptr[si]
cmp al,10 ;expect 11 data items
mov es,ax
mov ss,ax
jb here1
;process raw data into 8-bit code
mov ax,7FFEh ;stack top in RAM
mov sp,ax
;dl = bit count = 0-7, dh = code accumulator
loop2:
;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
;on groups A&B, Ports A=in, B & C=out
;assemble bits 0-7
out ppi_ctrl_port1,al
loop3: shr dh,1 ;for next higher bit
mov si,loca0 ;addr of 1st raw data
out ppi_ctrl_port2,al
;***************************
;SET UP INT VECTORS 5Fh and 59h
inc si ;skip Startbit
mov si,(5Fh*4) ;install 5Fh
;***************************
mov bl,dl ;bit count after Startbit
mov dx,offset kbd_isr ;5Fh ISR addr.
mov word ptr[si],dx ;offset -> IP
mov bh,0
mov al,byte ptr[si+bx] ;get raw data
add si,2
mov word ptr[si],0 ;segment -> CS
and al,10h ;extract bit 4
ภาพที่ ๘ ซอฟต์แวร์การรับ-ส่งข้อมูลแบบอนุกรมของแผงวงจรไมโครคอนโทรลเลอร์ 8088
;Page 3/8 of Fig.8
cmp al,10h ;bit4 = hi?
;store new raw data
jne noadd ;bit4 = lo
mov di,loca0
mov byte ptr [di+bx],al
addval: add dh,80h ;add bit value to code
noadd: inc dl ;dl = bit no.
inc bl ;advance HEAD
cmp dl,8 ;0 =< dl =< 7
cmp bl,11 ;max no. of raw data=11
jb nofold
jb loop3 ;repeat for another bit
read8: ;now dl=8
mov bl,0 ;fold back after 11 items
mov byte ptr[di],dh ;store code
nofold: mov byte ptr[si],bl ;new HEAD
inc di ;for next code to store
;display the complete current code on Port2B
;retrieve registers
pop si
showdat: cli ;prevent INTs ;Page 4/8 of Fig.8
mov al,dh ;get complete code pop di
call showcode pop bx
sti ;enable INTs pop ax
inc cl ;complete code count
cmp cl,10 ;only 10 codes received sti ;enable INTs
jb init1 ;repeat iret
kbd_isr endp
วารสารราชบััณฑิิตยสภา
;show stored codes received from uC PIC ปีีที่่� ๔๖ ฉบัับัที่่� ๓ กัันยายน-ธัันวาคม ๒๕๖๔
;**********************************************
mov di,buf0 ;addr: 1st stored code
84 การแลกเปล่�ยนข้้อมููลแบบอนุกรมูระหว่่างไมูโครคอนโทรลเลอร์โดยใช้้เกณฑ์์ว่ิธี่ข้องแผงแป้นอักข้ระ
mov cx,10
;pulsing upper-4 LEDs on 8255(2) Port2B
shwcde: mov al,byte ptr[di]
call showcode pulse2 proc ;INT 59h by software
inc di cli ;disable INTs
loop shwcde push ax
cli ;prevent INTs again2: mov al,0Fh ;Port2B's upp 4 lines hi
out ppi_port2_b,al
;***************************** out ppi_port2_b,al
mov al,1 ;demo by sending 1-11 call dly64 ;slow it down here too
;8088 sends data to PIC16F627A call dly64 ;slow it down a bit
mov cx,11
call dly64
;***************************** call dly64 ;approx. 2x64-ms delay
pop ax
loopy:
xmit: mov al,0 ;all Port2B's lines lo
call Byt2bit ;split 1 byte to 10 bits
sti ;enable INTs
cli ;prevent INTs
mov ah,al ;save al in ah out ppi_port2_b,al
iret ;exit INT subroutine
mov al,1 ;demo by sending 1-11
call dly64 ;slow it down here too
mov al,08h ;set al's bit 3 hi pulse2 endp
mov cx,11 call dly64
out ppi_port1_b,al ;P1B3=hi =>DAT=hi ;**********************************************
loopy: pop ax
out ppi_port1_c,al ;P1C3=hi =>CLK=hi
call Byt2bit ;split 1 byte to 10 bits sti ;enable INTs
jmp $+2 ;I/O delay
mov ah,al ;save al in ah iret ;exit INT subroutine
call Req2Snd ;8088 asks to send data ;display code in al on 8255(2) Port2B LEDs
mov al,08h ;set al's bit 3 hi
pulse2 endp
mov al,ah ;retrieve al showcode proc
out ppi_port1_b,al ;P1B3=hi =>DAT=hi ;**********************************************
call SndHdat ;send data in al (1-11) push ax
out ppi_port1_c,al ;P1C3=hi =>CLK=hi
call showcode ;display data in al out ppi_port2_b,al ;show code
jmp $+2 ;I/O delay
inc al ;next data to send call dly250 ;approx. 3x250-ms delay
call Req2Snd ;8088 asks to send data ;display code in al on 8255(2) Port2B LEDs
loop loopy ;repeat for 11 cycles call dly250
showcode proc
mov al,ah ;retrieve al
sti ;allow INTs call dly250
push ax
call SndHdat ;send data in al (1-11)
mov al,0
call showcode ;display data in al out ppi_port2_b,al ;show code
loopv: ;to exit program out ppi_port2_b,al ;to turn off LEDs
inc al ;next data to send call dly250 ;approx. 3x250-ms delay
mov al,0F0h ;enter this endless loop call dly250
loop loopy ;repeat for 11 cycles call dly250
call showcode ;& light upper-4 LEDs pop ax
sti ;allow INTs call dly250
jmp loopv ret
mov al,0
loopv: ;to exit program showcode endp
out ppi_port2_b,al ;to turn off LEDs
main endp ;**********************************************
mov al,0F0h ;enter this endless loop call dly250
; *********************************************
call showcode ;& light upper-4 LEDs pop ax
jmp loopv ret
kbd_isr proc ;interrupt service routine (ISR) ;request to send data to PIC16F627A
showcode endp
;activated by INT 5Fh on 8259's pin 25 Req2Snd proc
;**********************************************
main endp
cli ;disable INTs ;start with CLK=DAT=hi (Idle State)
; *********************************************
;save registers ;end with CLK=hi & DAT=lo (Startbit)
push ax cli ;prevent INTs
kbd_isr proc ;interrupt service routine (ISR) ;request to send data to PIC16F627A
push bx push ax
;activated by INT 5Fh on 8259's pin 25
Req2Snd proc
push di call wta7hi ;wait until CLK=hi
;start with CLK=DAT=hi (Idle State)
cli ;disable INTs
push si call wta4hi ;wait until DAT=hi
;save registers ;end with CLK=hi & DAT=lo (Startbit)
;read 11 bits from 8255(1) Port1A ;bring CLK->lo for >= 50 us
push ax cli ;prevent INTs
in al,ppi_port1_a call clc3lo ;make P1C3=lo
push bx push ax
jmp $+2 ;I/O delay call dly63us ;delay for about 100 us
push di call wta7hi ;wait until CLK=hi
mov si,HEAD ;addr: last data stored call dly20us
push si
call wta4hi ;wait until DAT=hi
mov bl,byte ptr[si] call dly20us
;read 11 bits from 8255(1) Port1A
;bring CLK->lo for >= 50 us
mov bh,0
in al,ppi_port1_a call clc3lo ;make P1C3=lo
jmp $+2 ;I/O delay call dly63us ;delay for about 100 us
mov si,HEAD ;addr: last data stored call dly20us
ภาพที่ ๘ ซอฟต์แวร์การรับ-ส่งข้อมูลแบบอนุกรมของแผงวงจรไมโครคอนโทรลเลอร์ 8088 (ต่อ)
mov bl,byte ptr[si] call dly20us
mov bh,0
;Page 5/8 of Fig.8 ;Page 6/8 of Fig.8
ภาพที่ ๘ ซอฟต์แวร์การรับ-ส่งข้อมูลแบบอนุกรมของแผงวงจรไมโครคอนโทรลเลอร์ 8088 (ต่อ)
;send Startbit by bringing DAT=lo & CLK=hi call wta7lo ;wait until CLK=lo
call clb3lo ;DAT (P1B3)=lo inc si ;next bit to send
jmp $+2 ;delay about 10 us loop loop10
;Page 5/8 of Fig.8 ;Page 6/8 of Fig.8
jmp $+2
jmp $+2 ;wait for ACK bit from PIC16F627A
;send Startbit by bringing DAT=lo & CLK=hi call wta7lo ;wait until CLK=lo
call stc3hi ;DAT=lo, CLK (P1C3)->hi call wta4lo ;wait for DAT line->lo
call clb3lo ;DAT (P1B3)=lo inc si ;next bit to send
jmp $+2 ;I/O delay call wta4hi ; // // DAT // ->hi
loop loop10
jmp $+2 ;delay about 10 us
pop ax
jmp $+2
sti ;enable INTs pop si
jmp $+2 ;wait for ACK bit from PIC16F627A
ret pop di
call stc3hi ;DAT=lo, CLK (P1C3)->hi call wta4lo ;wait for DAT line->lo
Req2Snd endp pop cx
jmp $+2 ;I/O delay call wta4hi ; // // DAT // ->hi
;********************************************** pop bx
pop ax
pop ax
sti ;enable INTs pop si
;extract 8 bits from al & calculate Parity bit sti ;allow INTs
ret pop di
Byt2bit proc ret
Req2Snd endp pop cx
cli ;prevent INTs SndHdat endp
;********************************************** pop bx
push ax ;ah = right-shifted al ;**********************************************
pop ax
push bx ;bh=Parity bit, bl=01h sti ;allow INTs
;extract 8 bits from al & calculate Parity bit
push cx ;wait for P1A4 (DAT) line to go hi
Byt2bit proc ret
push di wta4hi proc
cli ;prevent INTs SndHdat endp
mov ah,al ;save original al in ah push ax
push ax ;ah = right-shifted al ;**********************************************
mov bl,01h ;ref byte for comparing ;release DAT line by making P1B3 hi
push bx ;bh=Parity bit, bl=01h
ภาพท่� ๘ ซอฟตั์แวร์การรับ-ส่งข้้อมูลแบบอนีุ้กรมข้องแผงวงจรไมโครคอนี้โทรลเลอร์ 8088 (ตั่อ)
mov bh,01h ;odd parity mov al,08h
push cx
;wait for P1A4 (DAT) line to go hi
mov di,dat0 ;addr of dat0 out ppi_port1_b,al
push di
wta4hi proc
mov cx,8 jmp $+2 ;I/O delay
mov ah,al ;save original al in ah push ax
loop8: mov al,ah ;get shifted al from ah a4lo: in al,ppi_port1_a
mov bl,01h ;ref byte for comparing ;release DAT line by making P1B3 hi
and al,bl ;select only bit0 of al jmp $+2 ;I/O delay
mov bh,01h ;odd parity mov al,08h
xor bh,al ;new Parity bit and al,10h ;check bit 4 of P1A
mov di,dat0 ;addr of dat0 out ppi_port1_b,al
mov byte ptr[di],al ;save al’s bit0 cmp al,00h ;bit a4=lo ?
jmp $+2 ;I/O delay
mov cx,8
shr ah,1 ;next higher bit to test je a4lo
loop8: mov al,ah ;get shifted al from ah a4lo: in al,ppi_port1_a
inc di ;addr: next extractd bit pop ax
and al,bl ;select only bit0 of al jmp $+2 ;I/O delay
xor bh,al ;new Parity bit and al,10h ;check bit 4 of P1A
mov byte ptr[di],al ;save al’s bit0 cmp al,00h ;bit a4=lo ?
shr ah,1 ;next higher bit to test je a4lo
inc di ;addr: next extractd bit pop ax