Ilia Gildin
Junior Member level 3
- Joined
- Sep 27, 2014
- Messages
- 26
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 184
hello
I have written the following assembler code
and this code is not working as I receive from SSP1BUF the same thing that was transmitted to it last.
before writing this code I have followed this tutorials:
https://ww1.microchip.com/downloads/en/DeviceDoc/i2c.pdf
https://www.microchip.com/forums/m591463.aspx
can you please pinpoint me to the problem in my code
I have written the following assembler code
Code:
;******************************************************************************
; *
; This file is a basic code template for code generation on the *
; PIC18F46K22. This file contains the basic code building blocks to build *
; upon. *
; *
; Refer to the MPASM User's Guide for additional information on features *
; of the assembler. *
; *
; Refer to the respective data sheet for additional information on the *
; instruction set. *
; *
;******************************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; Author: *
; Company: *
; *
;******************************************************************************
; *
; Files Required: *
; *
;******************************************************************************
; *
; Notes: *
; *
;******************************************************************************
; *
; Revision History: *
; *
;******************************************************************************
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST P=PIC18F46K22 ; list directive to define processor
#INCLUDE <P18F46K22.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
;Setup CONFIG11H
CONFIG FOSC = INTIO67, PLLCFG = OFF, PRICLKEN = OFF, FCMEN = OFF, IESO = OFF
;Setup CONFIG2L
CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
;Setup CONFIG2H
CONFIG WDTEN = OFF, WDTPS = 1
;Setup CONFIG3H
CONFIG MCLRE = EXTMCLR, CCP2MX = PORTC1, CCP3MX = PORTE0, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTC0
;Setup CONFIG4L
CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
;Setup CONFIG5L
CONFIG CP0 = OFF, CP1 = OFF, CP2=OFF, CP3=OFF
;Setup CONFIG5H
CONFIG CPB = OFF, CPD = OFF
;Setup CONFIG6L
CONFIG WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
;Setup CONFIG6H
CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
;Setup CONFIG7L
CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
;Setup CONFIG7H
CONFIG EBTRB = OFF
;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Refer to datasheet for available data memory (RAM) organization
;
;------------------------------------------------------------------------------
CBLOCK 0x60 ; Sample GPR variable register allocations
MYVAR1 ; user variable at address 0x60
MYVAR2 ; user variable at address 0x61
MYVAR3 ; user variable at address 0x62
ENDC
W_TEMP EQU 0x000 ; w register for context saving (ACCESS)
STATUS_TEMP EQU 0x001 ; status used for context saving
BSR_TEMP EQU 0x002 ; bank select used for ISR context saving
#define LCD_RS LATD,LATD4 ; LCD RS bit
#define LCD_RW LATD,LATD5 ; LCD R/W bit
#define LCD_EN LATD,LATD6 ; LCD Enable bit
LCD_PORT equ LATD ; LCD Interface PORT
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 18F46K22 has 256 bytes of non-volatile EEPROM starting at 0xF00000
;
;------------------------------------------------------------------------------
DATAEE ORG 0xF00000 ; Starting address for EEPROM for 18F46K22
DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RES_VECT ORG 0x0000 ; processor reset vector
GOTO START ; go to beginning of program
;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------
ISRH ORG 0x0008
; Run the High Priority Interrupt Service Routine
GOTO HIGH_ISR
;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------
ISRL ORG 0x0018
; Run the High Priority Interrupt Service Routine
GOTO LOW_ISR
;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
HIGH_ISR
; Insert High Priority ISR Here
RETFIE FAST
;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
LOW_ISR
; Context Saving for Low ISR
MOVWF W_TEMP ; save W register
MOVFF STATUS, STATUS_TEMP ; save status register
MOVFF BSR, BSR_TEMP ; save bankselect register
; Insert Low Priority ISR Here
; Context Saving for Low ISR
MOVFF BSR_TEMP, BSR ; restore bankselect register
MOVF W_TEMP, W ; restore W register
MOVFF STATUS_TEMP, STATUS ; restore status register
RETFIE
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
;WORKING DISPLAY INCLUDING SECOUND LINE
;ONLY FOR POWER IS PORTD FOR CONTROL BITS AND DATA LATD
;FOSC 16MHz
START
CLRF TRISD
Clrf ANSELD
clrf ANSELC
clrf ANSELB
movlw B'00011000'
movwf TRISC
d1 EQU 0x80
d2 EQU 0x81
d3 EQU 0x82
LCD_DATA EQU 0x83
LCD_DATA1 EQU 0x88
var EQU 0x89
temp1 EQU 0x8A
temp EQU 0x84
sotni EQU 0x85
desiat EQU 0x86
edin EQU 0x87
call LCD_INIT
movlw B'01110110'
movwf OSCCON
start1
;INIT I2C
movlw B'00101000'
movwf SSP1CON1
movlw B'00001001'
movwf SSP1ADD
clrf SSP1STAT
bcf SSP1CON2,ACKDT
bsf SSP1CON2,ACKEN
call delay_200us
gh
btfsc SSP1STAT,R_NOT_W
bra gh
btfsc SSP1CON2,ACKDT
bra gh
;START I2C
bsf SSP1CON2,SEN
gh1
btfsc SSP1CON2,SEN
bra gh1
call delay_5us
gh2
;I2C WRITE ADDRESS OF CHIP
btfsc SSP1STAT,R_NOT_W
bra gh2
btfsc SSP1CON2,ACKDT
bra gh2
movlw B'10011010'
movwf SSP1BUF
gh3
btfsc SSP1STAT,BF
bra gh3
gh4
;I2C REGISTER SELECT OF OUR CHIP
btfsc SSP1STAT,R_NOT_W
bra gh4
btfsc SSP1CON2,ACKDT
bra gh4
movlw B'0'
movwf SSP1BUF
gh6
btfsc SSP1STAT,BF
bra gh6
;RESTART
gh7
btfsc SSP1STAT,R_NOT_W
bra gh7
btfsc SSP1CON2,ACKDT
bra gh7
bsf SSP1CON2,RSEN
gh8
btfsc SSP1CON2,RSEN
bra gh8
call delay_5us
gh9
;READ DATA
btfsc SSP1STAT,R_NOT_W
bra gh9
btfsc SSP1CON2,ACKDT
bra gh9
movlw B'10011011'
movwf SSP1BUF
gh10
btfsc SSP1STAT,BF
bra gh10
gh11
btfsc SSP1STAT,R_NOT_W
bra gh11
btfsc SSP1CON2,ACKDT
bra gh11
bsf SSP1CON2,RCEN
ghq
btfsc SSP1CON2,RCEN
bra ghq
gh12
btfsc SSP1STAT,BF
bra gh12
movff SSP1BUF,temp
gh13
;STOP I2C
btfsc SSP1STAT,R_NOT_W
bra gh13
btfsc SSP1CON2,ACKDT
bra gh13
bsf SSP1CON2,ACKDT
bsf SSP1CON2,ACKEN
gh14
btfsc SSP1CON2,ACKEN
bra gh14
bsf SSP1CON2,PEN
gh15
btfsc SSP1CON2,PEN
bra gh15
gh16
bra gh16
delay_45ms
movlw D'208'
movwf d3
op
movlw D'18'
movwf d2
ty
movlw D'15'
movwf d1
ui
decfsz d1
goto ui
decfsz d2
goto ty
decfsz d3
goto op
return
delay_5ms
movlw D'208'
movwf d3
op1
movlw D'6'
movwf d2
ty1
movlw D'5'
movwf d1
ui1
decfsz d1
goto ui1
decfsz d2
goto ty1
decfsz d3
goto op1
return
delay_200us
movlw D'20'
movwf d3
op2
movlw D'3'
movwf d2
ty2
movlw D'5'
movwf d1
ui2
decfsz d1
goto ui2
decfsz d2
goto ty2
decfsz d3
goto op2
return
delay_5us
movlw D'1'
movwf d3
op3
movlw D'1'
movwf d2
ty3
movlw D'2'
movwf d1
ui3
decfsz d1
goto ui3
decfsz d2
goto ty3
decfsz d3
goto op3
return
end
before writing this code I have followed this tutorials:
https://ww1.microchip.com/downloads/en/DeviceDoc/i2c.pdf
https://www.microchip.com/forums/m591463.aspx
can you please pinpoint me to the problem in my code