?? 93c46.asm
字號:
;********************************************************************
;* PICALC Directives Section *
;********************************************************************
SUBTITL "93C46 3 WIRE INTERFACE ROUTINE"
LIST P=16C54,N=40,C=132
;********************************************************************
;* Register Assignments *
;********************************************************************
indir equ 0x00 ;Use this register as source/destination for
;indirect addressing.
pc equ 0x02 ;PIC Program Counter.
status equ 0x03 ;PIC Status Register.
fsr equ 0x04 ;File Select Register.
serial equ 0x05 ;Port used for 93C46 control. Since Port A
;is 4 bits wide, we'll use all of Port A.
;The following three registers must be
;located consecutively in memory.
cmd equ 0x10 ;This register contains the 2 bit 93C46
;command is the upper 2 bit positions and
;memory address in the lower 6.
highb equ 0x11 ;Used in read/write routines to store the
;upper byte of a 16 bit 93C46 data word.
lowb equ 0x12 ;Used in read/write routines to store the
;lower byte of a 16 bit 93C46 data word.
cnthi equ 0x13 ;Used as the upper byte of a sixteen bit loop
;counter in RDYCHK routine.
cnt equ 0x14 ;Used as the lower byte of a sixteen bit loop
;counter in RDYCHK routine, and elsewhere as
;an eight bit counter.
;********************************************************************
;* Bit Assignments *
;********************************************************************
carry equ 0 ;Carry Flag of Status Register.
zflag equ 2 ;Zero Flag of Status Register.
;For the 3 wire interface, connect the din and dout to the same
;i/o line of the PIC16C5X.
cs equ 0 ;Port pin tied to CS on 93C46.
din equ 1 ;Port pin tied to DI on 93C46.
dout equ 1 ;Port pin tied to DO on 93C46.
clock equ 2 ;Port pin tied to CLK on 93C46.
;********************************************************************
;* General Assignments *
;********************************************************************
no_err equ 0 ;
error equ 1 ;
tries equ 0x04 ;After issuing a WRITE, ERASE, ERAL, or WRAL
;command, the approximate number of machine
;cycles X 256 to wait for the RDY status.
;This value must be adjusted for operating
;frequencies other than 4 MHz.
read equ 0x80 ;93C46 Read command.
write equ 0x40 ;93C46 Write command.
erase equ 0xC0 ;93C46 Erase command.
ewen equ 0x30 ;93C46 Erase/Write Enable command.
ewds equ 0x00 ;93C46 Erase/Write Disable command.
eral equ 0x20 ;92CXX Erase All command.
wral equ 0x10 ;92CXX Write All command.
;********************************************************************
;* Macro Definitions *
;********************************************************************
sel MACRO ;Selects the 93C46 device.
bsf serial,cs ;Chip Select (CS) = '1' to select the device.
ENDM
dsel MACRO ;De-select the 93C46 device.
bcf serial,cs ;Chip Select (CS) = '0' to de-select the
;device.
ENDM
strtbt MACRO ;Issue the Start Bit to the 93C46.
bsf serial,din ;Start Bit = '1'.
clkit ;Clock it out.
ENDM
clkit MACRO ;Clocks a serial data bit into or out of the
;93C46 device.
bsf serial,clock ;Clock (CLK) = '1'.
nop ;Adjust the number of nop instructions
;between the assertion and de-assertion of
;CLK in proportion to the PIC operating
;frequency. Refer to the 93C46 data for the
;minimum CLK period.
bcf serial,clock ;Clock (CLK) = '0'.
ENDM
;********************************************************************
;* Power-On/Reset Entry Point *
;********************************************************************
reset_ org 0x1FF
goto main
;********************************************************************
;* 93C46 Routines *
;********************************************************************
org 0x000 ;Locate all subroutines in the lower half of
;a Program Memory Page.
;********************************************************************
;* DOUT8 *
;********************************************************************
;Dout8 will output 8 bits of data to the
;93C46. Before calling this routine, the FSR
;must point to the byte being transmitted.
dout8 movlw 0x08 ;Initialize loop counter.
movwf cnt ;
d_o_8 bcf serial,din ;Assume that the bit to be transfered is a
;'0'. Hence, de-assert DI.
rlf indir ;Rotate the actual bit to be transferred into
;the carry bit.
btfsc status,carry ;Test the carry, if our assumption was
;correct, skip the next instruction.
bsf serial,din ;No, actual bit was a '1'. Assert DI.
clkit ;Clock the 93C46.
decfsz cnt ;Repeat until cnt = 0.
goto d_o_8 ;Cnt still > 0.
rlf indir ;Restore register to its original condition.
retlw no_err ;Exit with good status.
;********************************************************************
;* DIN8 *
;********************************************************************
;Din8 will input 8 bits of data from the
;93C46. Before calling this routine, the FSR
;must point to the register being used to
;hold the incomming data.
din8 movlw 0x08 ;Initialize loop counter.
movwf cnt ;
;for the 3 wire interface the direction of the i/o line connected to
;din and dout has to converted from an output to an input.
movlw b'00000010' ;convert RA1 to an input
tris serial ; /
d_i_8 clkit ;Clock a bit out of the 93C46.
rlf indir ;Make room for the incomming bit in the
;destination register.
bcf indir,0 ;Assume that the incomming bit is a '0' and
;clear the LSB of the destination register.
btfsc serial,dout ;Test the incomming bit, if our assumption
;was correct, skip the next instruction.
bsf indir,0 ;No, actual bit is a '1'. Set the LSB of the
;destination register.
decfsz cnt ;Repeat until cnt = 0.
goto d_i_8 ;Cnt still > 0
;for a 3 wire interface, convert the RA1 line back to an output
movlw 0 ;make RA1 to an output
tris serial ; /
retlw no_err ;Exit with good status.
;********************************************************************
;* RDYCHK *
;********************************************************************
;Rdychk will read the 93C46 READY/BUSY status
;and wait for RDY status within the alloted
;number of processor cycles. If RDY status
;is not present after this set period, the
;routine will return with an error status.
rdychk movlw tries ;Initialize time-out counter.
movwf cnthi ;
clrf cnt ;
;for a 3 wire interface, make the RA1 line an input
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -