/* Koden er til 12 MHz */ ;--------------------------------------------------------------- ;Pins: SCL EQU P3.5 ; Clock på P3.5 SDA EQU P3.4 ; Data på ; def af Konstanter EEPROMADR_W equ 10100000b ; 1010 xxx R//W ; EEPROM EEPROMADR_R equ 10100001b ; read PCF8574_W equ 01000000b ; 0100xxx W ; portkreds PCF8574_R equ 01000001b ; 0100xxx R ; PCF8574A_W equ 01110000b ; 0100xxx W ; portkreds A PCF8574A_R equ 01110001b ; 0100xxx R DS1621_W equ 10010000b ; 1001xxx W ; temperatur IC DS1621_R equ 10010001b ; 1001xxx R ; RAM Outbyte1 equ 70h Outbyte2 equ 71h Inbyte1 equ 75h Inbyte2 equ 76h Inbyte3 equ 77h Org 30h start: ; Initialiser I2C-Bussen setb SCL setb SDA ; Initier SFR'registrene mov SP, #30h ;----------------------------------------------------- ; I2C-Primitives, I2C Subrutiner Sendstart: ; tjekket I2C_on: I2C_start: ; Send START, defined as high-to-low SDA with SCL high. ; Return with SCL, SDA low. ; Returns CY set if bus is not available. ; verifiseret via ATMEL 8/6-04 setb SDA nop setb SCL ; Verify bus available jnb SDA, I2C_start8 ;Jump if not high jnb SCL, I2C_start8 ;Jump if not high nop clr SDA nop nop nop nop nop clr SCL clr c jmp I2C_start9 I2C_start8: setb c I2C_start9: ret ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sendstop: ; tjekket I2C_off: I2C_stop: ; Send STOP, defined as low-to-high SDA with SCL high. ; SCL expected low on entry. Return with SCL, SDA high. ;verifiseret iflg atmel clr SDA nop nop setb SCL nop nop nop nop nop setb SDA nop nop ret ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sendbyte: ; tjekket I2C_Out: I2C_shout: ; Shift out a byte to device, most significant bit first. ; SCL, SDA expected low on entry. Return with SCL low. ; Called with data to send in A. ; Returns CY set to indicate failure by slave to acknowledge. ; Destroys A. ; Tjekket med ATMEL push b mov b, #8 I2C_shout2: rlc a ; Bit 7 ( første gang ) ud i carry mov SDA, c nop setb SCL ; set clock nop nop nop nop nop clr SCL ; clock low djnz b, I2C_shout2 ; get ACK bit from slave (9. bit) setb SDA nop nop setb SCL ; Ack høj nop nop nop nop mov c, SDA ; Get ACK Bit, Cy har værdi afh af om det lykkedes clr SCL ; Clr ACK clock pop b ret ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Laesbyte: ; tjekket I2C_in: I2C_shin: ; Shift in a byte from the device, most significant bit first. ; SCL expected low on entry. Return with SCL low. ; Returns received data byte in A. ; setb SDA push b mov b, #8 I2C_shin2: nop nop nop nop setb SCL nop nop nop mov c, SDA rlc a clr SCL djnz b, I2C_shin2 pop b ret ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SendACK: ; tjekket I2C_ack: ; Clock out an acknowledge bit (low). ; SCL expected low on entry. Return with SCL, SDA low. ; Tjekket med ATMEL clr SDA nop nop setb SCL nop nop nop nop clr SCL ret ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SendnotACK: ; tjekket Send_NAK: I2C_nak: ; Clock out a negative acknowledge bit (high). ; SCL expected low on entry. Return with SCL low, SDA high. ; tjekket med Atmel setb SDA nop nop setb SCL nop nop nop nop clr SCL ret ; -------------------------------------------------------