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.

What is the different between PORTC and PORTD

Status
Not open for further replies.

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,936
Dear All
Last week in the class we wrote a program for PORTC which LED's drive RC0 to RC7 and back and continue. So it worked well for simulator and then we loarded it in to our project board, unfortunately it is worked only once from RC0 to RC7 and then we removed power and in again and it worked only once RC0 to RC7 again.
Then our instructor examen the problem and inform alter PORTC to PORTD. You won't believe it worked well.Finally instructed informed us that may be happen
Please advice what is this incident
What is the different between PORTC and PORTD

MCU is PIC 16F877a
 

Please post your code

Dear Poorchava,
Thanks for request
please see our assembly program

Code:
status			equ		0x03
portc			equ		0x07
trisc			equ		0x87
delay_1			equ		0x20
delay_2			equ		0x21

__CONFIG 3F39
#include <p16f877a.inc>

start			        clrwdt
				call	sys_init
loop3			        call	rotate_left
				call	rotate_right
				goto	loop3

rotate_left		        movlw	b'00000001'
				movwf	portc
loop			        rlf		portc
				call	delay
				btfss	portc,7
				goto	loop
				return

rotate_right	
loop1			         rrf	        portc
				call	delay
				btfss	portc,0
				goto	loop1
				return

delay			        movlw	        .255
				movwf	delay_1
s2				decfsz	delay_1
				goto	s1
				return

s1				movlw	.200
				movwf	delay_2
s3				decfsz	delay_2
				goto	s3
				goto	s2

sys_init		        bsf		status,5
				clrf	trisc
				bcf		status,5
				clrf	portc
				return

end
 
Last edited:

Hi,


Have you run your code via the Debugger so you can see where its going wrong ?
You use breakpoints around your delay routine so you 'run' though them.

Also wondered why have you got the WatchDog enabled in the Config but then you clear it in the first instruction ?
Its prefereable to disable the Watchdog in the config code, otherwise its easy to forget you have set it.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear wp100,
Thank you very much for reply

I run code via debugger, so it is working well
The problem will exist only in the project board
Later I changed PORTC to PORTD, then it is working fine, using same config code
However I will try with dissabaling watchdog timer with PORTC and let you know
 

Hi,

I think you mis-interpret what I have said.

Using your Pickit2 clone , in MPlab, Debugger you can select the PK2 Debugger function so you can run the program directly in the hardware from MPlab and run and / or single step though the code , watching the registers like PORTC change with each step - see picture.

Have just run your code on a 876A chip ( just a smaller memory to the 877a) and its running fine, both via debugger and programmed direct.

Think you should check your hardware as well. perhaps post your circuit diagram.
 

Attachments

  • ScreenShot002.jpg
    ScreenShot002.jpg
    134.9 KB · Views: 98
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top