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.

PIC 16F877 assembly code

Status
Not open for further replies.

chilly

Newbie level 5
Joined
Sep 16, 2008
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,342
16f877 code

I'm working with a PIC 16F877
My PIC program is reading input from portA then show output in portB
My problem is when portA is 10001 then it will make RB0=1, when portA is 10011 it will make RB1=1
but when portA is 10011 is will make both RB0, RB1=1
How can I solve this problem? I want when portA is 10011 is make RB1=1 only
Thanks for any suggestion.
 

pic16f877a asm

I can't catch the problem, if you copy PORTA on PORTB this will be equal for definition, you write that in your program PORTB is equal to PORTA then where is the problem? If you have 10011 on PORTA (RA0=RA1=1) then you should have RB0=RB1=1.

Try this code (not tested but should be work :D).

Code:
	#include p16F877.inc 
	__config _HS_OSC & _WDT_OFF & _LVP_OFF & _PWRTE_ON 

 ORG     0 

RESET 
 nop             
 goto   START 

 ORG 4 

START 
 bsf     STATUS,RP0         
 movlw   b'11111111' ; Set PORTA direction all input 
 movwf   TRISA       
 movlw   b'00000000' ; Set PORTB direction all output 
 movwf   TRISB       
 bcf   STATUS,RP0 

MAIN 
 movf  PORTA,W ; Copy PORTA to W 
 movwf PORTB   ; Copy W to PORTB 
 goto MAIN 
 end

Bye
Pow
 

pic16f877 asm

my problem is that:when I wrote 10001 in portA RB0=1,when I wrote 10011 on portA I don't want RB0=1, I only want RB1=1
Thanks for your reply
 

pic16f877a sample assembly code

There is more to know, what should be the state of the other pins, unchanged from previous state, forced to 0, forced to 1?

If you don't care of the other pins you may try to use a cascade combination of btfss, btfsc instruction to set or clear the output pin accordling your need.

Bye
Pow
 

pic16f877 assembly

chilly said:
I'm working with a PIC 16F877
My PIC program is reading input from portA then show output in portB
My problem is when portA is 10001 then it will make RB0=1, when portA is 10011 it will make RB1=1
but when portA is 10011 is will make both RB0, RB1=1
How can I solve this problem? I want when portA is 10011 is make RB1=1 only
Thanks for any suggestion.
please quote your source code.
 

pic16f877a assembly code

Thanks for all supports. I got the solution already. Here is my source code

LIST P=16F877,W=-302
__CONFIG 0x3D32 ; HS MODE,WDT OFF

status EQU H'0003'
z EQU H'0002'
PORTA EQU 0x05 ;Bank0
PORTB EQU 0x06

TRISA EQU 0x85 ; Bank1
TRISB EQU 0x86
ADCON1 EQU 0x9F

X EQU 0x70 ; RAM
Y EQU 0x71
Z EQU 0x72
ROUND EQU 0x73
;************************************************************
ORG 0x0000

BANKSEL ADCON1 ; Select ADCON1 <bank1>
MOVLW B'00000111' ; PORTA,PORTE = digital port
; MOVLW B'00000000' ; PORTA,PORTE = analog port
MOVWF ADCON1
MOVLW B'11111111' ; RA3:RA0
MOVWF TRISA
MOVLW B'00000000' ; PORTB = output
MOVWF TRISB

BANKSEL PORTA ; Select PORTA <bank0>

Loop
movlw 0x01 ;w =10001
xorwf PORTA,w
btfsc status,z ;if Z-flag not set, skip return
bsf PORTB,0 ;return if RA0 set
movlw 0x02
xorwf PORTA,w
btfsc status,z
bsf PORTB,1
movlw 0x03
xorwf PORTA,w
btfsc status,z
bsf PORTB,2
goto Loop







DELAY CLRF X ; Delay ~500 ms
CLRF Y
MOVLW .13
MOVWF Z
DECFSZ X,1
GOTO $-1
DECFSZ Y,1
GOTO $-3
DECFSZ Z,1
GOTO $-5
RETURN

END
[/quote]
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top