Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What can reset PORTx ?

Status
Not open for further replies.
hi pic2pic,
I have programmed two 16F877 with the program you have posted, the version that has PORTA has the switched inputs and the LED's on PORTB.

It works OK, no sign of any flashing, the PORTB output of one PIC follows the byte set on PORTA of the other PIC, works OK both ways on both PIC's.

Its possible the version of the program you have not posted, the version that uses PORTB as the switch input and LED's on PORTA is at fault.

Please post the FULL version of BOTH programs..:)
and if possible a circuit diagram, showing the interconnection of the two PIC's and the byte select switches.
 
Last edited:
Hi

I will post my schematic for my project and code I use for PIC1 and PIC2. I hope it is visible enough. Only switches, LED, resistors, PICs, power supply and oscillator.

Here is the code for side I call "Transmitter" or PIC1. In the shematic it is upper PIC



list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207

org 00h
goto start


org 04h
;save working and status register
movwf W_Save
swapf STATUS,W
movwf STATUS_Save

;take data and put it on PORTB
banksel RCREG
movf RCREG,W
movwf PORTA

;restore working and status register
banksel W_Save
swapf STATUS_Save,W ; Restore Status and W
movwf STATUS ;
swapf W_Save,F ;
swapf W_Save,W ;
retfie


start
radix dec

cblock 20h
brojac,brojac1,podatak,aktiviraj_transmisiju,STATUS_Save,W_Save
endc

; setting TRIS/A/B/C
banksel TRISB
movlw 00h
movwf TRISA
movlw 0ffh
movwf TRISC
movwf TRISB
;Seting UART
movlw b'00000110' ; all analog pins = digital
movwf ADCON1

banksel SPBRG
movlw 0x0C
movwf SPBRG

movlw b'00100100'
movwf TXSTA

banksel RCSTA
movlw b'10010000'
movwf RCSTA

;Setting interrupts
banksel PIE1
bsf PIE1,RCIE
movlw b'11000000'
movwf INTCON

Main
call Trans ;call routine for sending data
call Pauza ;make a pause
goto Main ;all the time

Trans
banksel PORTA
movf PORTB,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
return


Pauza
movlw 50
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



Here is the code for side I call "Receiver" or PIC2. In the shematic it is lower PIC. Almost the same code as above.



list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207

org 00h
goto start


org 04h
;save working and status register
movwf W_Save
swapf STATUS,W
movwf STATUS_Save

;take data and put it on PORTB
banksel RCREG
movf RCREG,W
movwf PORTB

;restore working and status register
banksel W_Save
swapf STATUS_Save,W ; Restore Status and W
movwf STATUS ;
swapf W_Save,F ;
swapf W_Save,W ;
retfie


start
radix dec

cblock 20h
brojac,brojac1,podatak,aktiviraj_transmisiju,STATUS_Save,W_Save
endc

; setting TRIS/A/B/C
banksel TRISB
movlw 0ffh
movwf TRISA
movwf TRISC
movlw 00h
movwf TRISB
;Seting UART
movlw b'00000110' ; all analog pins = digital
movwf ADCON1

banksel SPBRG
movlw 0x0C
movwf SPBRG

movlw b'00100100'
movwf TXSTA

banksel RCSTA
movlw b'10010000'
movwf RCSTA

;Setting interrupts
banksel PIE1
bsf PIE1,RCIE
movlw b'11000000'
movwf INTCON

Main
call Trans ;call routine for sending data
call Pauza ;make a pause
goto Main ;all the time

Trans
banksel PORTA
movf PORTA,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
return


Pauza
movlw 50
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
 

Attachments

  • Tx Rx UART.JPG
    Tx Rx UART.JPG
    29.2 KB · Views: 125
Actually both sides are both transmitter and receiver, but I name one side "transmitter" and other "receiver" for no special reason
 
hi pic2pic.
Downloaded you latest txrpic1 and rxrpic1 programs, I will reply later today after testing.

IMPORTANT:
On your very blurred drawing I dont see any pullup resistor on the PORTA or PORTB switch inputs.???

In one state the input pins are 'floating' open circuit.???

Is the drawing complete.??
 
Last edited:
The way this schematic works:

The switches I press on side PIC1 is showed on LED on the other PIC2 ,and the other way round, the switches I press on side PIC2 is showed on LED on the other PIC1
 
Yes, there is no resistors for input. Does it no resistors means HIGH input. I was always considered no resistors as high and it worked
 
The way this schematic works:

The switches I press on side PIC1 is showed on LED on the other PIC2 ,and the other way round, the switches I press on side PIC2 is showed on LED on the other PIC1

I understand that.:)

I have two programmed 16F877 pics sending data to each other, using your first program.
It works OK.

but you MUST have a pullup resistor on the switch inputs, a 4.7K or 10K for each switch will be OK.


NOTE:
As a test I have just removed the pull up resistors from my PIC's PORTA....
the mains pick up causes the other PICs PORTB LED's to flash...!!!
 
Last edited:
Pins left floating can mess up alot. Put pull downs on pins that need to go high. Like add pull down resistors to the pic side of the switch if you are testing for a high. If you are testing for lows then add a pull up to the pic side.

When no pull-up/down are used the pin is floating and almost anything can alter the pin state. Even your hand moving close to the button or pin.
 
Last edited:
OK I am going to try. I hope that is. :)

hi,
On some PICs PORTB they have internal pull ups,[which must be enabled] but there are none on PORTA.

I would recommend that whenever you use a switch use an external pull up or pull down resistor, input pins must not be left open..:)
 
Last edited:
hi pic2pic,
I have programmed two 16F877 with the program you have posted, the version that has PORTA has the switched inputs and the LED's on PORTB.

It works OK, no sign of any flashing, the PORTB output of one PIC follows the byte set on PORTA of the other PIC, works OK both ways on both PIC's.

Its possible the version of the program you have not posted, the version that uses PORTB as the switch input and LED's on PORTA is at fault.

Please post the FULL version of BOTH programs..:)
and if possible a circuit diagram, showing the interconnection of the two PIC's and the byte select switches.

The op running the same code he posted?
 
@ericgibbs :))

I can't believe it :)) . It works :)) I had a thought It maybe need pull up resistors, but in my earlier projects it worked with no pull ups, so I consider it not needed.

People thank you all. Really really . You helped me a lot. For weeks I been working on this :)) . Kind of I know the answer, but ...

This can be good advice for beginners :) . Code works, schematic is good except pull up resistors needed.

Ok people see you ...Thanks again :)
 
@ericgibbs :))

I can't believe it :)) . It works :)) I had a thought It maybe need pull up resistors, but in my earlier projects it worked with no pull ups, so I consider it not needed.

People thank you all. Really really . You helped me a lot. For weeks I been working on this :)) . Kind of I know the answer, but ...

This can be good advice for beginners :) . Code works, schematic is good except pull up resistors needed.

Ok people see you ...Thanks again :)

Well done.!:)

Lets know how the project goes when completed.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top