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.

Strange PIC problem as I can't get the output from port b

Status
Not open for further replies.

tijoseymathew

Member level 4
Joined
May 13, 2007
Messages
77
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
1,755
hi
I am trying to code a simple program like this
W equ 00h
STATUS equ 03h ;Address of the STATUS register
TRISB equ 86h ;Address of the tristate register for port A
PORTB equ 06h ;Address of Port A

;****Set up the port****

bsf STATUS,5
movlw 00h ;Set the Port A pins
movwf TRISB ;to output.
bcf STATUS,5
Start
movlw b'11111111'
movwf PORTB
goto Start
end
I am programming using a jdm programmer and the pic gets verified correctly.
but when i put it in breadboard i am not getting an o/p from port b. I hvae checked everything and tried changing parts also in the circuit.
i have previously used this programmer succesfully on many programs
I cant understand wht is wrong this time
 

Strange PIC problem

Firstly use an include statement instead of manually defining the registers.
Secondly which PIC are you using? Do you have a crystal (assuming it needs one)
 

Re: Strange PIC problem

Start
movlw b'11111111'
movwf PORTB
goto Start
end
1. You have mentioned that you are not getting an output. If the PIC is executing the code, the o/p will always be high as per your code.
2. If you have enabled WDT in the configuration fuses, the watchdog will reset the PIC since you are not clearing the WDT.

Cheers

Ravi
 

Strange PIC problem

1. i will try the include statement and come back
2. yes i use a crystal i set it in icprog when programming the pic
3. i used PIC16F84A and PIC16F870
4. The output is that PortB Pin shd be high. But I dont get anything in PORTB Pins
5. i have disabled WDT in icprog.

Added after 11 minutes:

I tried the include option but to no avail
here is the new code
#include<C:\Program Files\Microchip\MPASM Suite\P16F84A.INC>
bsf STATUS,5
movlw 00h
movwf TRISB
bcf STATUS,5
Start
movlw b'11111111'
movwf PORTB
goto Start

end
and here is the hex file
:020000040000FA
:0E0000008316003086008312FF30860004282D
:00000001FF
 

Re: Strange PIC problem

Your program is working fine on PIC Simulator with the posted new code

Code:
	#include <C:\Program Files\Microchip\MPASM Suite\P16F84A.INC>
	bsf STATUS,5
	movlw 00h
	movwf TRISB
	bcf STATUS,5
Start
	movlw b'11111111'
	movwf PORTB
	goto Start

hex code :
Code:
:0E0000008316003086008312FF30860004282D
:02400E00013F70
:00000001FF

Assebly listing:
Code:
---------------------------------------------
PIC ASSEMBLER LISTING
Line    Address Opcode  Instruction
---------------------------------------------
0001    0000            ;Line removed by MPASMWIN preprocessor: 	#include <C:\Program Files\Microchip\MPASM Suite\P16F84A.INC>
0002    0000    1683    	bsf STATUS,5
0003    0001    3000    	movlw 00h
0004    0002    0086    	movwf TRISB
0005    0003    1283    	bcf STATUS,5
0006    0004            Start
0007    0004    30FF    	movlw b'11111111'
0008    0005    0086    	movwf PORTB
0009    0006    2804    	goto Start
---------------------------------------------
Number of errors = 0

try the hex i provided since it differs from your post

Hope this helps

Nishal
 

Re: Strange PIC problem

tijoseymathew said:
1. i will try the include statement and come back
2. yes i use a crystal i set it in icprog when programming the pic
3. i used PIC16F84A and PIC16F870
4. The output is that PortB Pin shd be high. But I dont get anything in PORTB Pins
5. i have disabled WDT in icprog.
One issue, check if the oscillator is actually oscillating. At 4MHz, you should be able to check with a scope.

Cheers

Ravi
 

Re: Strange PIC problem

tijoseymathew said:
hi
I am trying to code a simple program like this
W equ 00h
STATUS equ 03h ;Address of the STATUS register
TRISB equ 86h ;Address of the tristate register for port A
PORTB equ 06h ;Address of Port A

;****Set up the port****

bsf STATUS,5
movlw 00h ;Set the Port A pins
movwf TRISB ;to output.
bcf STATUS,5

I highlighted your line above. The address 00h occupied by INDF register and cannot be assigned to other file.

On the other hand, your code does not change status of the output port pins.
 

Re: Strange PIC problem

nguyennam said:
tijoseymathew said:
hi
I am trying to code a simple program like this
W equ 00h
STATUS equ 03h ;Address of the STATUS register
TRISB equ 86h ;Address of the tristate register for port A
PORTB equ 06h ;Address of Port A

;****Set up the port****

bsf STATUS,5
movlw 00h ;Set the Port A pins
movwf TRISB ;to output.
bcf STATUS,5
I highlighted your line above. The address 00h occupied by INDF register and cannot be assigned to other file.
No, if you declare it in the source code or not, W has the value of 00.

It is implemented as follows ---> movf counter,w

You can use movf counter,0 ... it still remains the same.

On the other hand, your code does not change status of the output port pins.
The original issue is that the output DOES NOT go high. The code is ok. It runs well on the simulator.

Please check the oscillator to see if it is running. Device could be ok but the crystal or capacitor could be bad.

Cheers

Ravi
 

Re: Strange PIC problem

nguyennam said:
The address 00h occupied by INDF register and cannot be assigned to other file.
W equ 00h ... isn't adress, it is constant, and this definition is in all original Microchip Pxxxx.inc files.
This isn't error.
 

Re: Strange PIC problem

Try this. It has the __CONFIG and LIST directives plus the important and missing ORG statement and it does work with a 4MHz crystal.

Code:
	list	p=16F84A
	include <p16F84A.INC>
	__CONFIG _XT_OSC & _WDT_OFF
	org	0x000		; reset vector
	bsf 	STATUS,RP0
	movlw 	00h
	movwf 	TRISB
	bcf 	STATUS,RP0
Start	movlw 	b'11111111'
	movwf 	PORTB
	goto 	$		; loop forever
	END
 

Re: Strange PIC problem

Hi check the following is your TOCKI and MCLR pulled high? on bread boards it is always a good move to place a 10mf cap directly between Vss and Vdd, I always use a 10mf 16v tant across the chip as close to the 2 pins as possible
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top