Category : Assembly Language Source Code
Archive   : SIG8051.ZIP
Filename : SIO_NEW.ASM

 
Output of file : SIO_NEW.ASM contained in archive : SIG8051.ZIP
; SIO_NEW.ASM - IIC COMMUNICATION ROUTINES ....
; MODIFIED TO ALLOW BETTER COMMUNICATIONS TO HOST PROGRAM....
;
;---------==========----------==========---------=========---------
; BIT LOCATIONS
;---------==========----------==========---------=========---------

STA: EQU 0DDH ; STA BIT IN S1CON
SIO1HP: EQU 0BDH ; IP0, SIO1 PRIORITY BIT
;
; IMMEDIATE DATA FOR REGISTER S1CON

; THE FOLLOWING DEFINITIONS USE CR1/CR0=01 = 100KHZ...
;
;ENS1_NOTSTA_STO_NOTSI_AA_CR0: EQU 0D5H ; GENERATES STOP, CR0=100KHz
;ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0: EQU 0C5H ; RELEASES BUS AND ACK
;ENS1_NOTSTA_NOTSTO_NOTSI_NOTAA_CR0: EQU 0C1H ; RELEASE BUS AND NOT ACK
;ENS1_STA_NOTSTO_NOTSI_AA_CR0: EQU 0E5H ; RELEASE BUS SET STA

; THE FOLLOWING DEFINITIONS USE CR1/CR0=00 = 12.5 KHZ...

ENS1_NOTSTA_STO_NOTSI_AA_CR0: EQU 0D4H ; GENERATES STOP, CR0=100KHz
ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0: EQU 0C4H ; RELEASES BUS AND ACK
ENS1_NOTSTA_NOTSTO_NOTSI_NOTAA_CR0: EQU 0C0H ; RELEASE BUS AND NOT ACK
ENS1_STA_NOTSTO_NOTSI_AA_CR0: EQU 0E4H ; RELEASE BUS SET STA

;
; GENERAL IMMEDIATE DATA
;
OWNSLA EQU 031H ; OWN SLA + GENERAL CALL
ENSIO1 EQU 0A0H ; EA+ESI (ENABLE SIO1 INT)

; DATA RAM LOCATIONS....

BACKUP EQU 030H ; BACKUP NUMBYTMST FOR LOST ARB. (1 BYTE)
NUMBYTMST EQU 031H ; NUMBER OF BYTES TO XMIT/REC AS MST (1 BYTE)
SLA EQU 032H ; SLAVE ADDRESS TO BE XMITTED (1 BYTE)

MTD EQU 040H ;MST/TRX BUFFER (8 BYTES) 50-57
MRD EQU 048H ;MST/REC BUFFER (8 BYTES) 58-5F
SRD EQU 050H ;SLV/REC BUFFER (8 BYTES) 60-67
STD EQU 058H ;SLV/TRX BUFFER (8 BYTES) 68-6F
$EJECT
;===========-----------==========----------==========----------========----
;===========---- INITIALIZE IIC INTERFACE ===----------========----
;===========-----------==========----------==========----------========----
INIT_SIO: EQU $

MOV D_S1ADR,#OWNSLA ;LOAD CPU SLAVE ADDRESS AND ENABLE
; GENERAL CALL RECOGNITION
SETB P1.6 ; SET UP SDA AND SCL LINES
SETB P1.7

ORL D_IEN0,#ENSIO1 ; ENABLE SIO1 INTERRUPTS
CLR SIO1HP ; SIO1 INTERRUPT LOW PRIORITY

; INIT SLAVE FUNCTION

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0

RET
$EJECT
;===========-----------==========----------==========----------========----
;===========---- SIO1 INTERRUPT ROUTINE ===----------========----
;===========-----------==========----------==========----------========----

IIC_IN: EQU $ ; IIC INTERRUPT ROUTINE...

; call b_cmd ; display status of the bus

PUSH ACC ;
PUSH DPH ; SAVE DATA POINTER AND ACC
PUSH DPL
PUSH PSW ; SAVE THE SELECTED REGISTER BANK

MOV A,D_S1STA ; GET STATUS INTO ACC
RR A
RR A ; ROTATE RIGHT TO GET STATE NUMBER
RR A
ANL A,#01FH ; MASK OUT HIGHER BITS

RL A ; MUTLIPLY ACC BY 2 BYTES PER ENTRY

MOV DPTR,#IIC_JUMPS ; POINT TO JUMP TABLE
JMP @A+DPTR ; JUMP TO PROPER SERVICE ROUTINE


IIC_RET: POP PSW
POP DPL
POP DPH

; mov A,#43H ; some new debug stuff to remove later..
; call CHAROUT ; """""""""""""""

POP ACC


RETI
$EJECT
IIC_JUMPS: EQU $

AJMP STATE00 ; 00 = BUS ERROR...
AJMP STATE08 ; 08 = START CONDITION XMITTED..
AJMP STATE10 ; 10 = REPEATED START CONDITION HAS BEEN XMITTED..

;==============================================
; MASTER TRANSMITTER STATES
;==============================================

AJMP STATE18 ; 18 = PRIOR STATE WAS 8 OR 10
AJMP STATE20 ; 20 = SLAW HAVE BEEN XMTD, NOTACK HAS BEEN RECD
AJMP STATE28 ; 28 = DATA OF SIDAT HAVE BEEN XMTD, ACK HAS BEEN RECD
AJMP STATE30 ; 30 = DATA OF SIDAT HAVE BEEN XMTD, NOTACK HAS BEEN RECD
AJMP STATE38 ; 38 = ARB LOST IN SLA+W OR DATA

;==============================================
; MASTER RECEIVER STATE SERVICE ROUTINES
;==============================================

AJMP STATE40 ; 40 = PRIOR STATE WAS 08 OR 10...
AJMP STATE48 ; 48 = SLA+R HAVE BEEN XMITTED, NOT ACK RECD...
AJMP STATE50 ; 50 = DATA HAVE BEEN RECD...ACK RETD.....
AJMP STATE58 ; 58 = DATA HAVE BEEN RECD...NOTACK RETD.....

;==============================================
; SLAVE RECEIVER STATE SERVICE ROUTINES
;==============================================

AJMP STATE60 ; 60 = OWN SLA+W HAVE BEEN REC'D .. ACK RECD...
AJMP STATE68 ; 68 = ARB LOST IN SLA AND R AJMP STATE00 W AS MASTER
AJMP STATE70 ; 70 = GENERAL CALL HAS BEEN REC'D .. ACK RECD...
AJMP STATE78 ; 78 = ARB LOST IN SLA AND R AJMP STATE00 W AS MASTER
AJMP STATE80 ; 80 = PREVIOUSLY ADDRESSED WITH OWN SLA
AJMP STATE88 ; 88 = PREVIOUSLY ADDRESSED WITH OWN SLA
AJMP STATE90 ; 90 = PREVISOUSLY ACCRESSED WITH GENERAL CALL..
AJMP STATE98 ; 98 = PREVISOUSLY ACCRESSED WITH GENERAL CALL..
AJMP STATEA0 ; A0 = A STOP CONDITION OR REPEATED START HAS BEEN RECD

;==============================================
; SLAVE TRANSMITTER STATE SERVICE ROUTINES
;==============================================

AJMP STATEA8 ; A8 = OWN SLA+R REC'D...ACK RETND
AJMP STATEB0 ; B0 = ARB LOST IN SLA AND R/W AS MASTER
AJMP STATEB8 ; B8 = DATA HAS BEEN XMITTED..ACK REC'D
AJMP STATEC0 ; C0= DATA HAS BEEN XMITTED..NOT ACK REC'D
AJMP STATEC8 ; C8= LAST DATA HAS BEEN XMITTED..AA=0..ACK REC'D
$EJECT
;-------------------------------------------
; STATE 00 = BUS ERROR...
; ACTION - ENTER NOT ADDRESSED SLV MODE AND RELEASE BUS..STO RESET
;-------------------------------------------

STATE00: EQU $
MOV D_S1CON,#ENS1_NOTSTA_STO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------------------------
; STATE 08 = A START CONDITION HAS BEEN XMITTED..
; ACTION - ENTER NOT ADDRESSED SLV MODE AND RELEASE BUS..STO RESET
;-------------------------------------------

STATE08: EQU $
MOV D_S1DAT,SLA

; mov a,sla
; call hex_out ; debug junk >>>>>>>>>>>>>>>>>>>>>>
; call cr_lf

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0;
AJMP INITBASE1


;-------------------------------------------
; STATE 10 = A REPEATED START CONDITION HAS BEEN XMITTED..
; ACTION - ENTER NOT ADDRESSED SLV MODE AND RELEASE BUS..STO RESET
;-------------------------------------------

STATE10: EQU $
MOV D_S1DAT,SLA
MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0;

; AJMP INITBASE1 ; FALL THROUGH

;----------------------FOLLOWING USED BY 08 AND 10.....
INITBASE1: EQU $
MOV PSW,#SELRB3
MOV R1,#MTD
MOV R0,#MRD
MOV BACKUP,NUMBYTMST
AJMP IIC_RET

$EJECT
;===============================================
; MASTER XMITTER STATE SERVICE ROUTINES
;===============================================

;-------------------------------------------
; STATE 18 = PRIOR STATE WAS 8 OR 10
; SLAW HAVE BEEN XMTD, ACK HAS BEEN RECD
; ACTION - FIRST DATA IS TRANS, ACK BIT IS RECD
;-------------------------------------------

STATE18: EQU $

MOV PSW,#SELRB3
MOV D_S1DAT,@R1
AJMP CON

;-------------------------------------------
; STATE 20 = SLAW HAVE BEEN XMTD, NOTACK HAS BEEN RECD
; ACTION - XMIT STOP CONDITION
;-------------------------------------------

STATE20: EQU $

MOV D_S1CON,#ENS1_NOTSTA_STO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------------------------
; STATE 28 = DATA OF SIDAT HAVE BEEN XMTD, ACK HAS BEEN RECD
; ACTION - IF XMIT'D DATA LAST DATA, XMIT STOP, ELSE XMIT NEXT DATA
;-------------------------------------------

STATE28: EQU $

DJNZ NUMBYTMST,NOTLDAT1
MOV D_S1CON,#ENS1_NOTSTA_STO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------- FOLLOWING USED BY 20 AND 28.....

NOTLDAT1: MOV PSW,#SELRB3
MOV D_S1DAT,@R1
CON: MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0;
INC R1
AJMP IIC_RET

;-------------------------------------------
; STATE 30 = DATA OF SIDAT HAVE BEEN XMTD, NOTACK HAS BEEN RECD
; ACTION - XMIT STOP
;-------------------------------------------

STATE30: EQU $

MOV D_S1CON,#ENS1_NOTSTA_STO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------------------------
; STATE 38 = ARB LOST IN SLA+W OR DATA
; ACTION - RELEASE BUS. ENTER NOT SLV MODE. XMIT NEW
; START WHEN BUS IS NO LONGER BUSY
;-------------------------------------------

STATE38: EQU $

MOV D_S1CON,#ENS1_STA_NOTSTO_NOTSI_AA_CR0
MOV NUMBYTMST,BACKUP
AJMP IIC_RET

$EJECT
;===============================================
; MASTER RECEIVER STATE SERVICE ROUTINES
;===============================================

;-------------------------------------------
; STATE 40 = PRIOR STATE WAS 08 OR 10...
; SLA+R HAVE BEEN XMITTED, ACK RECD...
; ACTION - DATA WILL BE REVCEIVED, ACK RETURNED
;-------------------------------------------

STATE40: EQU $

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
AJMP RETMR

;-------------------------------------------
; STATE 48 = SLA+R HAVE BEEN XMITTED, NOT ACK RECD...
; ACTION - GENERATE STOP CONDITION
;-------------------------------------------

STATE48: EQU $

MOV D_S1CON,#ENS1_NOTSTA_STO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------------------------
; STATE 50 = DATA HAVE BEEN RECD...ACK RETD.....
; ACTION - READ DATA OF S1DAT...DATA W/B REC'D...IF
; LAST DATA, XMIT NOT ACK, ELSE XMIT ACK
;-------------------------------------------

STATE50: EQU $

MOV PSW,#SELRB3
MOV @R0,D_S1DAT
; AJMP REC1 ; FALL THROUGH

;---------------------------FOLLOWING USED BY 38,40,50 ..........

REC1: DJNZ NUMBYTMST,NOTLDAT2
MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_NOTAA_CR0
AJMP RETMR

NOTLDAT2: MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0

RETMR: INC R0
AJMP IIC_RET


;-------------------------------------------
; STATE 58 = DATA HAVE BEEN RECD...NOTACK RETD.....
; ACTION - READ DATA OF S1DAT...GEN STOP CONDITION
;-------------------------------------------

STATE58: EQU $

MOV PSW,#SELRB3
MOV @R0,D_S1DAT
MOV D_S1CON,#ENS1_NOTSTA_STO_NOTSI_AA_CR0
AJMP IIC_RET
$EJECT
;===============================================
; SLAVE RECEIVER STATE SERVICE ROUTINES
;===============================================

;-------------------------------------------
; STATE 60 = OWN SLA+W HAVE BEEN REC'D .. ACK RECD...
; ACTION - REC DATA AND RETURN ACK
;-------------------------------------------

STATE60: EQU $

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
MOV PSW,#SELRB3
AJMP INITSRD

;-------------------------------------------
; STATE 68 = ARB LOST IN SLA AND R/W AS MASTER
; OWN SLA+W HAVE BEEN REC'D, ACK RET'D
; ACTION - REC DATA AND RETURN ACK
; STA IS SET TO RESTART MST MODE AFTER BUS FREE
;-------------------------------------------

STATE68: EQU $

MOV D_S1CON,#ENS1_STA_NOTSTO_NOTSI_AA_CR0
MOV PSW,#SELRB3
AJMP INITSRD

;-------------------------------------------
; STATE 70 = GENERAL CALL HAS BEEN REC'D .. ACK RECD...
; ACTION - REC DATA AND RETURN ACK
;-------------------------------------------

STATE70: EQU $

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
MOV PSW,#SELRB3
AJMP INITSRD

;-------------------------------------------
; STATE 78 = ARB LOST IN SLA AND R/W AS MASTER
; GENERAL CALL HAS BEEN REC'D, ACK RET'D
; ACTION - REC DATA AND RETURN ACK
; STA IS SET TO RESTART MST MODE AFTER BUS FREE
;-------------------------------------------

STATE78: EQU $

MOV D_S1CON,#ENS1_STA_NOTSTO_NOTSI_AA_CR0
MOV PSW,#SELRB3

; AJMP INITSRD ; FALL THROUGH

;--------------------FOLLOWING USED BY 60, 68, 70, AND 78....

INITSRD: MOV R0,#SRD
MOV R1,#08H
AJMP IIC_RET

;-------------------------------------------
; STATE 80 = PREVIOUSLY ADDRESSED WITH OWN SLA
; DATA HAS BEEN REC'D .. ACK RET'D..
; ACTION - REC DATA. IF LAST, SUPERFLUOUS DATA W/B REC'D
; AND NOT ACK RET'D, ELSE NEXT DATA REC'D AND ACK RET'D
;-------------------------------------------

STATE80: EQU $

MOV PSW,#SELRB3
MOV @R0,D_S1DAT
AJMP REC2

;-------------------------------------------
; STATE 88 = PREVIOUSLY ADDRESSED WITH OWN SLA
; DATA HAS BEEN REC'D .. NOT ACK RET'D..
; ACTION - NO SAVE OFDATA.
; ENTER NOT ADDRESSED SLV MODE. RECOGNIZE OWN SLA, AND
; GENERAL CALL IF D_S1ADR.0=1
;-------------------------------------------

STATE88: EQU $

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------------------------
; STATE 90 = PREVISOUSLY ACCRESSED WITH GENERAL CALL..
; DATA HAS BEEN REC'D, ACK RET'D...
; ACTION - READ DATA. AFTER GENERAL CALL ONLY PME BYTE
; W/B REC'D WITH ACK...SECOND DATA REC'D WITH NOTACK
; DATA W/B REC'D AND NOT ACK RET'D
;-------------------------------------------

STATE90: EQU $

MOV PSW,#SELRB3
MOV @R0,D_S1DAT
AJMP LDAT



;======----------- FOLLOWING USED BY 80, 88, 90.....

REC2: DJNZ R1,NOTLDAT3
LDAT: MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_NOTAA_CR0
AJMP IIC_RET
NOTLDAT3: MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
INC R0
RETSR: AJMP IIC_RET


;-------------------------------------------
; STATE 98 = PREVISOUSLY ADDRESSED WITH GENERAL CALL..
; DATA HAS BEEN REC'D, NOT ACK RET'D...
; ACTION - NO SAVE OF DATA.
; ENTER NOT ADDRESSED SLV MODE...RECOG. OWN SLA.
; GENERAL CALL RECOG IF D_S1ADR.0=1
;-------------------------------------------

STATE98: EQU $

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------------------------
; STATE A0 = A STOP CONDITION OR REPEATED START HAS BEEN RECD
; WHILE STILL ADDRESSED AS SLV/REC OR SLV/TRX...
; ACTION - NO SAVE OF DATA...ENTERNOT ADDRESSED SLV MODE...RECOG
; OWN SLA..GENERAL CALL RECOG IF D_S1ADR.0=1
;-------------------------------------------

STATEA0: EQU $

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
AJMP IIC_RET
$EJECT
;===============================================
; SLAVE TRANSMITTER STATE SERVICE ROUTINES
;===============================================

;-------------------------------------------
; STATE A8 = OWN SLA+R REC'D...ACK RETND
; ACTION - DATA W/B XMITTED...A BIT REC'D
;-------------------------------------------

STATEA8: EQU $

MOV D_S1DAT,STD
MOV D_S1CON,ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
AJMP INITBASE2

;-------------------------------------------
; STATE B0 = ARB LOST IN SLA AND R/W AS MASTER
; OWN SLA+R REC'D...ACK RET'D
; ACTION - DATA W/B XMITTED...A BIT REC'D
; STA IS SET TO RESTART MST MODE AFTER BUS FREE AGAIN
;-------------------------------------------

STATEB0: EQU $

MOV D_S1DAT,STD
MOV D_S1CON,#ENS1_STA_NOTSTO_NOTSI_AA_CR0
AJMP INITBASE2

;-------------------------------------------
; STATE B8 = DATA HAS BEEN XMITTED..ACK REC'D
; ACTION - DATA W/B XMITTED...ACK BIT IS REC'D
;-------------------------------------------

STATEB8: EQU $

MOV PSW,#SELRB3
MOV D_S1DAT,@R1
MOV D_S1CON,#ENS1_STA_NOTSTO_NOTSI_AA_CR0
AJMP INITBASE2

;=======----------FOLLOWING USED IN A8, B0, B8, ....

INITBASE2: EQU $
MOV PSW,#SELRB3
MOV R1,#STD
INC R1
AJMP IIC_RET

;-------------------------------------------
; STATE C0= DATA HAS BEEN XMITTED..NOT ACK REC'D
; ACTION - ENTER NOT ADDRESSED SLV MODE
;-------------------------------------------

STATEC0: EQU $

MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
AJMP IIC_RET

;-------------------------------------------
; STATE C8= LAST DATA HAS BEEN XMITTED..AA=0..ACK REC'D
; ACTION - ENTER NOT ADDRESSED SLV MODE
;-------------------------------------------

STATEC8: EQU $
MOV D_S1CON,#ENS1_NOTSTA_NOTSTO_NOTSI_AA_CR0
AJMP IIC_RET


  3 Responses to “Category : Assembly Language Source Code
Archive   : SIG8051.ZIP
Filename : SIO_NEW.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/