Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

programing PIC16F877 : I2C "assembler"

Status
Not open for further replies.

crazy-igzp

Member level 1
Joined
Feb 3, 2014
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Settat, Morocco
Activity points
255
I wrote a program in assembler so I can transmit PORTA From a pic to another with I2C ! but it didn't work ! & can't find the error !:-( any help ? I use mplab
program : emission
Code:
[syntax=asm]LIST p=16f877 , 
INCLUDE "p16f877.inc"
__CONFIG _CP_OFF & _XT_OSC & _PWRTE_OFF & _WDT_OFF

					BCF STATUS,RP0
					BCF STATUS,RP1
					MOVLW 0x28
					MOVWF SSPCON
					BSF STATUS,RP0
					MOVLW 0x80
					MOVWF SSPSTAT
					MOVLW 0x31
					MOVWF SSPADD
					MOVLW 	0Xff
					MOVWF 	TRISB
					BSF		TRISC,3
					BSF 	TRISC,4
					MOVLW	0x18
					MOVWF	SSPCON2
RS 					BSF		SSPCON2,SEN
					BCF		STATUS,RP0
					MOVLW	0x5A
					MOVWF	SSPBUF
					BSF		STATUS,RP0
test1				BTFSC	SSPSTAT,BF
					GOTO	test1
					BTFSC	SSPCON2,ACKSTAT
					GOTO	RS
Retransmission		BCF		STATUS,RP0
					MOVF	PORTB,0
					MOVWF	SSPBUF
					BSF 	STATUS,RP0
test2				BTFSC 	SSPSTAT,BF
					GOTO 	test2
					BTFSC 	SSPCON2,ACKSTAT
					GOTO 	Retransmission
					BSF 	SSPCON2,PEN
					END[/syntax]
if you need to check the reception too , here it is
program : reception
Code:
LIST p=16f877
INCLUDE "p16f877.inc"
__CONFIG _CP_OFF & _XT_OSC & _PWRTE_OFF & _WDT_OFF
			
			BCF 	STATUS,RP0
			BCF 	STATUS,RP1
			MOVLW 	0x36
			MOVWF 	SSPCON
			BSF 	STATUS,RP0
			MOVLW 	0x80
			MOVWF 	SSPSTAT 
			MOVLW 	0x5A
			MOVWF 	SSPADD
			MOVLW 	0x00
			MOVWF 	TRISB
			BSF 	TRISC,3
			BSF 	TRISC,4
			MOVLW 	0x18
			MOVWF 	SSPCON2
ST			BTFSS 	SSPSTAT,S
			GOTO 	ST
test1		BTFSS 	SSPSTAT,BF
			GOTO 	test1
			BCF 	STATUS,RP0
			MOVF	SSPBUF,0
			BSF 	STATUS,RP0
test2		BTFSS 	SSPSTAT,BF
			GOTO 	test2
			BCF 	STATUS,RP0
			MOVF 	SSPBUF,0
			MOVWF 	PORTB
			BSF 	STATUS,RP0
test3		BTFSS	SSPSTAT,BF
			GOTO	test3
test4		BTFSS	SSPSTAT,P
			GOTO 	test4
			END
 

It would be better if you post your project folder including simulation
 

here it is !
 

Attachments

  • I2C PROjECT.rar
    16.7 KB · Views: 42
  • I2C2.rar
    12.7 KB · Views: 36

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top