I made a code for communicating PIC 16f877 to PIC 16f877.
Both PICs are transmitter ans receiver. One side takes a byte from PORTB and sends that byte to other PIC2 and PIC2 shows that byte on PORTB (there are LED).
Also PIC2 takes a byte from PORTA and sends that byte to PORTA on PIC1 and PIC1 shows that byte on PORTB (there are LED).
I see that it works except PORTB and PORTA are blinking all the time with frequency about 1-2 Hz (I mean LED i put on these ports) .
What is the problem ?
Down there is the code for PIC1. Code for PIC2 is the same except it takes data from PORTA and shows received byte on PORTB
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
org 00h
goto start
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;ISR
;---------------------------------------------------------------------------
org 04h
banksel PIE1
bcf PIE1,TXIE
bcf PIE1,RCIE
bcf INTCON,PEIE
bcf INTCON,GIE
;---------------------------------------------------------------------------
banksel TXSTA
bcf TXSTA,TXEN
banksel RCSTA
bcf RCSTA,CREN
;---------------------------------------------------------------------------
banksel RCREG
movf RCREG,W
movwf PORTA
;---------------------------------------------------------------------------
movf RCREG,W
movf RCREG,W
;---------------------------------------------------------------------------
banksel TXSTA
bsf TXSTA,TXEN
banksel RCSTA
bsf RCSTA,CREN
;---------------------------------------------------------------------------
banksel PIE1
bcf PIE1,TXIE
bsf PIE1,RCIE
movlw b'11000000'
movwf INTCON
return
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
start
radix dec
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
cblock 20h
brojac,brojac1,podatak,aktiviraj_transmisiju
endc
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISB
movwf TRISC
movlw 00h
movwf TRISA
;---------------------------------------------------------------------------
movlw b'00000110' ; all analog pins = digital
movwf ADCON1
banksel PIE1
movlw b'00100000'
movwf PIE1
movlw b'11000000'
movwf INTCON
;---------------------------------------------------------------------------
banksel SPBRG
movlw 0x0C
movwf SPBRG
movlw b'00100100'
movwf TXSTA
banksel RCSTA
movlw b'10010000'
movwf RCSTA
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
banksel PIE1
bcf PIE1,TXIE
bsf PIE1,RCIE
movlw b'11000000'
movwf INTCON
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
Main
call Trans
call Pauza
goto Main
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;Subrutine
;---------------------------------------------------------------------------
Trans
banksel INTCON
bcf INTCON,GIE
banksel PORTB
movf PORTB,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
banksel INTCON
bsf INTCON,GIE
nop
return
;---------------------------------------------------------------------------
Pauza
movlw 75
movwf brojac1
mala_pauza_1
movlw 100
movwf brojac
mala_pauza
decfsz brojac,f
goto mala_pauza
decfsz brojac1,f
goto mala_pauza_1
return
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
end
Both PICs are transmitter ans receiver. One side takes a byte from PORTB and sends that byte to other PIC2 and PIC2 shows that byte on PORTB (there are LED).
Also PIC2 takes a byte from PORTA and sends that byte to PORTA on PIC1 and PIC1 shows that byte on PORTB (there are LED).
I see that it works except PORTB and PORTA are blinking all the time with frequency about 1-2 Hz (I mean LED i put on these ports) .
What is the problem ?
Down there is the code for PIC1. Code for PIC2 is the same except it takes data from PORTA and shows received byte on PORTB
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
org 00h
goto start
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;ISR
;---------------------------------------------------------------------------
org 04h
banksel PIE1
bcf PIE1,TXIE
bcf PIE1,RCIE
bcf INTCON,PEIE
bcf INTCON,GIE
;---------------------------------------------------------------------------
banksel TXSTA
bcf TXSTA,TXEN
banksel RCSTA
bcf RCSTA,CREN
;---------------------------------------------------------------------------
banksel RCREG
movf RCREG,W
movwf PORTA
;---------------------------------------------------------------------------
movf RCREG,W
movf RCREG,W
;---------------------------------------------------------------------------
banksel TXSTA
bsf TXSTA,TXEN
banksel RCSTA
bsf RCSTA,CREN
;---------------------------------------------------------------------------
banksel PIE1
bcf PIE1,TXIE
bsf PIE1,RCIE
movlw b'11000000'
movwf INTCON
return
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
start
radix dec
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
cblock 20h
brojac,brojac1,podatak,aktiviraj_transmisiju
endc
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISB
movwf TRISC
movlw 00h
movwf TRISA
;---------------------------------------------------------------------------
movlw b'00000110' ; all analog pins = digital
movwf ADCON1
banksel PIE1
movlw b'00100000'
movwf PIE1
movlw b'11000000'
movwf INTCON
;---------------------------------------------------------------------------
banksel SPBRG
movlw 0x0C
movwf SPBRG
movlw b'00100100'
movwf TXSTA
banksel RCSTA
movlw b'10010000'
movwf RCSTA
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
banksel PIE1
bcf PIE1,TXIE
bsf PIE1,RCIE
movlw b'11000000'
movwf INTCON
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;---------------------------------------------------------------------------
Main
call Trans
call Pauza
goto Main
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
;///////////////////////////////////////////////////////////////////////////
;Subrutine
;---------------------------------------------------------------------------
Trans
banksel INTCON
bcf INTCON,GIE
banksel PORTB
movf PORTB,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
banksel INTCON
bsf INTCON,GIE
nop
return
;---------------------------------------------------------------------------
Pauza
movlw 75
movwf brojac1
mala_pauza_1
movlw 100
movwf brojac
mala_pauza
decfsz brojac,f
goto mala_pauza
decfsz brojac1,f
goto mala_pauza_1
return
;---------------------------------------------------------------------------
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;---------------------------------------------------------------------------
end