;******************************************************************** ; All rate calculations assume an 11.0592MHz Mclk. ; This program run display port 3 value on LCD : ; ; Author : Guy Bami Sens. Syst Master ;******************************************************************** $MOD812 ; Use 8052&ADuC812 predefined symbols $NOPRINT ; do not generate .lst file LED EQU P3.4 ; P3.4 drives red LED on eval board SCL EQU P2.1 ;clock SDA EQU P2.2 ;data of I2C BITCNT DATA 8h ; bit counter for I2C routines BYTECNT DATA 030h ; byte counter for I2C routines SLAVEADD DATA 032h ; slave address for I2C routines FLAGS DATA 28h NOACK BIT FLAGS.0 ; I2C no acknowledge flag BUSY BIT FLAGS.1 ; I2C busy flag ERROR BIT FLAGS.2 ; I2C error flag MISTAKE BIT P3.4 ;________________________________________________________________ CSEG ORG 0000h JMP START ; jump to main program ;________________________________________________________________ ; INTERRUPT VECTOR SPACE ;============================================================== ORG 007BH ; Subroutines ;---------------------------------------------------------------------- ; BITSTART: Send the bit start of the transmission and the slave ; address to the slave ;---------------------------------------------------------------------- BITSTART: setb LED ;switch LED SETB BUSY ; I2C is in progress SETB MDE ; to enable SDATA pin as an output CLR NOACK CLR ERROR JNB MCO,FAULT JNB MDO,FAULT CLR MDO ; this is the start bit CLR SDA LCALL DELAY CLR MCO CLR SCL FAULT: CLR MISTAKE ; set error flag MOV A, SLAVEADD ; Get slave address LCALL SENDBYTE ; call routine to send slave addr. byte CLR MISTAKE ; set error flag RET ;---------------------------------------------------------------------- ; SENDSTOP: Send the bit stop of the transmission ;---------------------------------------------------------------------- SENDSTOP: clr LED ;switch LED SETB MDE ; to enable SDATA pin as an output CLR MDO ; get SDATA ready for stop CLR SDA SETB MCO ; set clock for stop SETB SCL LCALL DELAY SETB MDO ; this is the stop bit SETB SDA CLR BUSY ; bus should be released RET ;---------------------------------------------------------------------- ; SENDBYTE: Send a 8-bits word to the slave ;---------------------------------------------------------------------- SENDBYTE: MOV BITCNT,#8 ; 8 bits in a byte SETB MDE ;to enable SDATA pin as an output CLR MDO CLR MCO clr SDA clr SCL LOOP: RLC A ; send one bit MOV MDO,C ; put data bit on pin mov SDA,C SETB MCO ; send clock CLR MCO ; clock is off setb SDA clr SCL DJNZ BITCNT,LOOP CLR MDE ; release data line for acknowledge SETB MCO ; send clock for acknowledge setb SCL JNB MDI,NEXT ; this is a check SETB NOACK ; no acknowledge NEXT: CLR MCO ; clock for acknowledge clr SCL RET ;---------------------------------------------------------------------- ; DELAY: Create a delay for the main signals ( SCLOCK , SDATA ) ;---------------------------------------------------------------------- DELAY: NOP RET START: MOV SP,#040h CLR NOACK MOV SLAVEADD,#074H MOV BYTECNT,#3 MOV I2CCON,#0A8h MOV SLAVEADD,#074H LCALL BITSTART MOV A, #074h ;send address slave for write LCALL SENDBYTE MOV A, #00h ;send the control byte for fonction set RS = 0 LCALL SENDBYTE MOV A, #2Ch ;send fonction set for 4-lines display LCALL SENDBYTE MOV A, #0Eh ;turns ON display and cursor LCALL SENDBYTE MOV A, #00h ;send the entry mode set(increment cursor by 1 and shift right) LCALL SENDBYTE MOV A, #40h ;send the control byte for fonction set RS = 1 LCALL SENDBYTE MOV A, #74h ;send address slave for write LCALL SENDBYTE MOV A, #40h ;send the control byte for write data LCALL SENDBYTE MOV A, #50h ;write to DDRAM (value ' P_ ' ) LCALL SENDBYTE MOV A, #48h ;write to DDRAM (value ' PH_ ' ) LCALL SENDBYTE MOV A, #80h ;send a control byte (value ' PH_ ' ) LCALL SENDBYTE LCALL SENDSTOP JMP START END