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.

Unable to communicate between PIC18F4420 devices

Status
Not open for further replies.

pratikpanchal

Newbie level 3
Joined
Mar 7, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,378
I am developing an application where a PIC18F4420 device is sending data to another PIC18F4420 device. The receiver device is not getting the code as sent by the transmitter. I'm attaching the circuit diagram, and program herewith.

TRANSMITTER CODE:

**************************************

;******************************************************************************
; This file is a basic template for creating relocatable assembly code for *
; a PIC18F4420. Copy this file into your project directory and modify or *
; add to it as needed. *
; *
; The PIC18FXXXX architecture allows two interrupt configurations. This *
; template code is written for priority interrupt levels and the IPEN bit *
; in the RCON register must be set to enable priority levels. If IPEN is *
; left in its default zero state, only the interrupt vector at 0x008 will *
; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not *
; be needed. *
; *
; Refer to the MPASM User's Guide for additional information on the *
; features of the assembler and linker. *
; *
; Refer to the PIC18Fxx20 Data Sheet for additional *
; information on the architecture and instruction set. *
; *
;******************************************************************************
; *
; Filename: TRANSMIT CODE *
; Date: 24.MARCH.2011 *
; File Version: *
; *
; Author: PRATIK PANCHAL *
; Company: *
; *
;******************************************************************************
; *
; Files required: P18F4420.INC *
; *
;******************************************************************************

LIST P=18F4420, F=INHX32 ;directive to define processor and file format
#include <P18F4420.INC> ;processor specific variable definitions

;******************************************************************************
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please
;see the .inc file for futher details on notation. Below are a few examples.

;-------------------------------------- Oscillator Selection:
CONFIG OSC = INTIO67 ;INT OSC WITH PORTING
CONFIG FCMEN = OFF ;FAIL SAFE CLOCK OFF
CONFIG IESO = OFF
CONFIG PWRT = ON
CONFIG BOREN = OFF
CONFIG WDT = OFF
CONFIG PBADEN = OFF
CONFIG MCLRE = ON
CONFIG STVREN = ON
CONFIG LVP = OFF
;CONFIG XINST = OFF
CONFIG DEBUG = OFF
CONFIG CP0 = ON
CONFIG CP1 = ON
CONFIG CPB = ON
CONFIG CPD = ON


Main:

GOTO START

;------------------------- INTERRUPT SPACE

ORG 0008H ;HIGH PRIORITY INTERRUPT
GOTO HIGHINT

ORG 00018H ;LOW PRIORITY INTERRUPT
GOTO LOWINT

;------------------------- MAIN CODE SPACE
START:

ORG 0028H ;main program starts from here
CLRF 0X80 ;TIMER PRESCALER REGISTER

BCF OSCCON,0
BCF OSCCON,1
BSF OSCCON,4
BSF OSCCON,5
BSF OSCCON,6
BSF CMCON,0
BSF CMCON,1
BSF CMCON,2
BCF TMR0ON,7
CLRF CCP2CON
CLRF CCP1CON
BCF ADCON0,0
SETF ADCON1

CLRF PORTA
CLRF LATA
CLRF TRISA
MOVLW 0Xff
MOVWF LATA

CLRF LATB
CLRF TRISB

BSF RCON,7 ;ENABLE PRIORITY FEATURE ON INTERRUPTS
BSF INTCON,7 ;ENABLE ALL HIGH PRIORITY INTERRUPTS
BCF INTCON,2
;BSF INTCON,5 ;ENABLE TMR0 OVERFLOW INTERRUPT
BSF INTCON2,2 ;SET TMR0 OVERFLOW INTERRUPT AS HIGH PRIORITY



LINE1:


;--------------------------TIMER0 CONFIGURATION

BCF T0CON,7 ;STOP TIMER
BCF T0CON,6 ;16 BIT TIMER
BCF T0CON,5 ;CLK SOURCE = INTERNAL
BCF T0CON,3 ;PRESCALER IS USED
BSF T0CON,2
BSF T0CON,1
BSF T0CON,0 ;1:256 PRESCALER IS USED

CLRF TMR0L
CLRF TMR0H

BSF T0CON,7 ;START TIMER

LOOP:

BSF TRISC,6 ;TX

CLRF SPBRGH
MOVLW 0X7C
MOVWF SPBRG ;SETTING BAUDRATE = 1K
BCF TXSTA,2 ;LOW SPEED (BRGH)
BCF BAUDCON,3 ;8 BIT BAUD GENERATOR (BRG16)

BCF TXSTA,4 ;ASYNCHRONOUS MODE (SYNC)
BSF RCSTA,7 ;SERIAL PORT ENABLED (SPEN)

BSF BAUDCON,4 ;IDLE STATE FOR TRANSMIT IS LOW LEVEL (TXCKP)
BSF BAUDCON,1 ;WAKE UP ENABLE (WUE)
BCF BAUDCON,0 ;AUTO BAUD DETECT DISABLED (ABDEN)

BCF TXSTA,6 ;8 BIT TRANSMISSION (TX9)
BSF TXSTA,5 ;TRANSMIT ENABLED (TXEN)


REPEATTX:
MOVLW 0X24 ;2(DEC)
MOVWF TXREG
NOP
NOP
WAITTX1:
BTFSS PIR1,4 ; (TXIF)
GOTO WAITTX1
MOVLW 0X19 ;4(DEC)
MOVWF TXREG
NOP
NOP
WAITTX2:
BTFSS PIR1,4 ; (TXIF)
GOTO WAITTX2
MOVLW 0X02 ;6(DEC)
MOVWF TXREG
NOP
NOP
WAITTX3:
BTFSS PIR1,4 ; (TXIF)
GOTO WAITTX3

MOVF TMR0L, W ;DISPLAY COUNTER VALUE ON 7 SEG LED TO SHOW ACTIVITY
MOVWF LATB

GOTO REPEATTX

;------------------------------------- INTERRUPT SPACE

HIGHINT:
BCF INTCON, 5 ;DISABLE TMR0 INTERRUPT
INCF 0X80,1
MOVLW 0X9
CPFSEQ 0X80
GOTO LINE60
CLRF 0X80
BSF PORTA,0
CALL DELAY02
BCF PORTA,0
CALL DELAY02 ;BLINK LED ON PORTA,0 TO SHOW ACTIVITY
BSF PORTA,0
CALL DELAY02
BCF PORTA,0
CALL DELAY02
BSF PORTA,0
CALL DELAY02
BCF PORTA,0
CALL DELAY02
BSF PORTA,0
CALL DELAY02
BCF PORTA,0
CALL DELAY02
LINE60:
BCF INTCON,2
BSF INTCON,5
RETFIE

LOWINT:
GOTO LINE1

;--------------------------------------SUBROUTINES

DELAY03:
MOVLW 0X03
MOVWF 0X106
D3.1:
MOVLW 0XFF
MOVWF 0X107
D3.2:
MOVLW 0XFF
MOVWF 0X108
D3.3:
NOP
NOP
DECF 0X108, F
BNZ D3.3
DECF 0X107, F
BNZ D3.2
DECF 0X106, F
BNZ D3.1
RETURN

DELAY01:
MOVLW 0X01
MOVWF 0X100
D1.1:
MOVLW 0XFF
MOVWF 0X101
D1.2:
MOVLW 0XFF
MOVWF 0X102
D1.3:
NOP
NOP
DECF 0X102, F
BNZ D1.3
DECF 0X101, F
BNZ D1.2
DECF 0X100, F
BNZ D1.1
RETURN

DELAY02:
MOVLW 0X02
MOVWF 0X103
D2.1:
MOVLW 0XFF
MOVWF 0X104
D2.2:
MOVLW 0XFF
MOVWF 0X105
D2.3:
NOP
NOP
DECF 0X105, F
BNZ D2.3
DECF 0X104, F
BNZ D2.2
DECF 0X103, F
BNZ D2.1
RETURN



;******************************************************************************
;End of program

END



RECEIVER CODE:

***********************************************

;******************************************************************************
; This file is a basic template for creating relocatable assembly code for *
; a PIC18F4420. Copy this file into your project directory and modify or *
; add to it as needed. *
; *
; The PIC18FXXXX architecture allows two interrupt configurations. This *
; template code is written for priority interrupt levels and the IPEN bit *
; in the RCON register must be set to enable priority levels. If IPEN is *
; left in its default zero state, only the interrupt vector at 0x008 will *
; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not *
; be needed. *
; *
; Refer to the MPASM User's Guide for additional information on the *
; features of the assembler and linker. *
; *
; Refer to the PIC18Fxx20 Data Sheet for additional *
; information on the architecture and instruction set. *
; *
;******************************************************************************
; *
; Filename: *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
;******************************************************************************
; *
; Files required: P18F4420.INC *
; *
;******************************************************************************

LIST P=18F4420, F=INHX32 ;directive to define processor and file format
#include <P18F4420.INC> ;processor specific variable definitions

;******************************************************************************
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please
;see the .inc file for futher details on notation. Below are a few examples.

; Oscillator Selection:
CONFIG OSC = INTIO67 ;INT OSC WITH PORTING
CONFIG FCMEN = OFF ;FAIL SAFE CLOCK OFF
CONFIG IESO = OFF
CONFIG PWRT = ON
CONFIG BOREN = OFF
CONFIG WDT = OFF
CONFIG PBADEN = OFF
CONFIG MCLRE = ON
CONFIG STVREN = ON
CONFIG LVP = OFF
;CONFIG XINST = OFF
CONFIG DEBUG = OFF
CONFIG CP0 = ON
CONFIG CP1 = ON
CONFIG CPB = ON
CONFIG CPD = ON


Main:

; *** main code goes here ***

GOTO START

;------------------------- INTERRUPT SPACE

ORG 0008H ;HIGH PRIORITY INTERRUPT
GOTO HIGHINT

ORG 00018H ;LOW PRIORITY INTERRUPT
GOTO LOWINT

;------------------------- MAIN CODE SPACE
START:

ORG 0028H ;main program starts from here
CLRF 0X80 ;TIMER PRESCALER REGISTER

BCF OSCCON,0
BCF OSCCON,1
BSF OSCCON,4
BSF OSCCON,5
BSF OSCCON,6
BSF CMCON,0
BSF CMCON,1
BSF CMCON,2

BCF TMR0ON,7
CLRF CCP2CON
CLRF CCP1CON
BCF ADCON0,0
SETF ADCON1

CLRF PORTA
CLRF LATA
CLRF TRISA
MOVLW 0Xff
MOVWF LATA

CLRF LATB
CLRF TRISB



LOOP:

BSF TRISC,7 ;RX

CLRF SPBRGH
MOVLW 0X7C
MOVWF SPBRG ;SETTING BAUDRATE = 1K
BCF TXSTA,2 ;LOW SPEED (BRGH)
BCF BAUDCON,3 ;8 BIT BAUD GENERATOR (BRG16)

BCF BAUDCON,5 ;RECIEVE DATA IS NOT INVERTED (RXDTP)


BCF TXSTA,4 ;ASYNCHRONOUS MODE (SYNC)
BSF RCSTA,7 ;SERIAL PORT ENABLED (SPEN)

BCF BAUDCON,0 ;AUTO BAUD DETECT DISABLED (ABDEN)

BCF RCSTA,6 ;8 BIT RECEPTION (RX9)
BSF RCSTA,4 ;ENABLE RECEIVER (CREN)

REPEATRC:
BTFSS PIR1,5 ;POLL RECEIVE BUFFER FULL FLAG (RCIF)
GOTO REPEATRC
MOVF RCREG,0 ;COPY CONTENTS OF RCREG INTO WREG
MOVWF LATB ;TRANSFER CONTENTS OF WREG TO PORT B
CALL DELAY03
BCF PORTA,0
CALL DELAY03
BSF PORTA,0 ;BLINK A LED TO SHOW ACTIVITY

BCF RCSTA,4 ;RESET RECEIVER
BSF RCSTA,4
GOTO REPEATRC

;--------------------------------------SUBROUTINES

DELAY03:
MOVLW 0X03
MOVWF 0X106
D3.1:
MOVLW 0XFF
MOVWF 0X107
D3.2:
MOVLW 0XFF
MOVWF 0X108
D3.3:
NOP
NOP
DECF 0X108, F
BNZ D3.3
DECF 0X107, F
BNZ D3.2
DECF 0X106, F
BNZ D3.1
RETURN

;******************************************************************************
;End of program

END


Please Assist.

Regards, Pratik Panchal.
 

Attachments

  • PIC18F4420 EXPERIMENTATION.bmp
    1.6 MB · Views: 83
  • 24.MARCH.2011 RECEIVER CODE.txt
    5.2 KB · Views: 28
  • 24.MARCH.2011 TRANSMIT CODE.txt
    6.8 KB · Views: 31

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top