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.

help me in code pic assembly

Status
Not open for further replies.

alaalwi11

Member level 1
Joined
Nov 30, 2010
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Al khurtum-Sudan
Activity points
1,626
:roll:Hi hello anyone i m new to this site so help me in my problem
my broblem i program pic 16f84 to read data from port a and display in port b
but there is one pin dosn't out signal
please help me
source code in pic assembly:

;F.ALI HASSAN
;specify SFRS

status equ 03
porta equ 05
trisa equ 85
portb equ 06
trisb equ 86
optio equ 81

org 00
;Initilize
start bsf status,5 ;select memory bank 1
movlw B'00011000'
movwf trisa ;porta according above pattern
movlw b'00000000'
movwf trisb ;all port B output
bcf status,5;select bank 0
bsf optio,5
;the "main"program starts her
clrf porta ;clear all bits in ports A
loop movf porta,0 ;move port A to W REGISTER
movwf portb ;move w register to port B
goto loop
end
 

Hi friend,

If do you have another piece of Pic16f84 controller,
then check that second controller using same code, and observe that same problem exist or not,

Because, i have experience that some time only one pin is burn out or bad and controller work OK.

Hope this is help you
Shyam
 

Hi,

Well a good try for your first attempt, but you have gone wrong on a few things.

Have changed your code so it will now work ok and PortA bit3 and 4 will be reflected on PortB bits 3 and 4.

Some points to mention;-

Always specify in your code what chip you are using with the LIST instruction.

Always specify the chips .inc file with the Include statement - if you look at the 16F84.inc file in the MPASM directory you will see its specifes all the System Registers so you do not need to specify them again in your code.

When you write your code, all System Registers should be in Capitals as shown in the .inc file.

When changing ram / data banks it is a lot easier to the the Banksel directive - just loook at the Help, MPASM, serach Banksel for details



Code:
;F.ALI HASSAN
;specify SFRS



	LIST P=16F84,r=DEC,n=80,x=off,st=off			; RADIX = DECIMAL !
	errorlevel -302

	#include <P16F84.INC>	



	org 00
;Initilize
start bsf STATUS,5 ;select memory bank 1
	movlw B'00011000'                       ; THIS MAKES ONLY PORTA BITS 3 AND 4 AS INPUTS THE REST ARE OUTPUTS ..?
	movwf TRISA ;porta according above pattern
	movlw b'00000000'
	movwf TRISB;all port B output

	bsf OPTION_REG,5

	bcf STATUS,5;select bank 0

;    or    banksel,0

;the "main"program starts her
	clrf PORTA ;clear all bits in ports A
loop movf PORTA,W ;move port A to W REGISTER
	movwf PORTB ;move w register to port B
	goto loop
	end
 

Attachments

  • led.jpg
    led.jpg
    108.1 KB · Views: 125

Shyam is correct. Your code works with a simulator so there must be a fault on your chip. Check your soldering also in case of some shorting between pins.
 
  • Like
Reactions: fs789

    fs789

    Points: 2
    Helpful Answer Positive Rating
There are changes to the code to be made, like:
Code:
;F.ALI HASSAN

   LIST P=16F84A ;Tell compiler which PIC is used
   #INCLUDE <P16F84A.INC> ;Tell compiler to load associated header/include file
                          ; so that you don't need to specify the SFRs manually

   __CONFIG 0x3FF1        ; You HAVE to specify configuration bits, check datasheet for this

;Specifying SFRs not required as you included *.inc file

org 00 ;Initialize

start     

bsf     STATUS,5 ;select memory bank 1          Write SFR in CAPS so that compiler loads them
movlw   b'00011000'
movwf   TRISA ;porta according above pattern
movlw   b'00000000'
movwf   TRISB ;all port B output
bcf     STATUS,5;select bank 0    STATUS,5 can be written as STATUS,RP0
bsf     OPTION_REG,5

;the "main"program starts her

clrf    PORTB
clrf    PORTA ;clear all bits in ports A

loop 

movf    PORTA,w ;move port A to W REGISTER       Use w instead of 0 for ease of understanding
movwf   PORTB ;move w register to port B
goto    loop

end
Hope this helps.
Tahmid.

---------- Post added at 10:47 ---------- Previous post was at 10:44 ----------

And make sure if it's 16F84 or 16F84A.
 
Assuming you are using MPLAB's assembler, thee is also another way to simplify your code:
Instead of using "bcf STATUS,5" and "bsf STATUS,5" to switch banks, use the directive "banksel" instead. For example:
banksel PORTB
which tells the compiler to produce the correct bsf/bcf for you. It makes the program easier to read but more importantly, if you change to another processor with different bank switching bits, the code will still compile correctly for it.
Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top