Help me with assembly for PIC!

Status
Not open for further replies.

kaszuky

Newbie level 3
Joined
Nov 2, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,321
I have finished the code for PIC16F887 using assembly language. However, when I send it to the uc, it does not work. I checked again and again, but I don't know where I am wrong. Hope somebody can help me figure out where I am wrong. Thank you very much for helping

My goal in this code is just send the data in the table to IC74HC595.
PIN 0 of PORT E is CLK
PIN 1 of PORT E is Latch
PIN 2 of PORT E is data.
That's all

Here my code:

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LIST P=16F887
INCLUDE P16F887.INC
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _HS_OSC
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CBLOCK 0x20
DELAYH
DELAYM
DELAYL
sended_data
pointer
check_8_bits
ENDC
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ORG 0x00
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MAIN
BANKSEL TRISE
MOVLW 0x00
MOVWF TRISE
MOVWF pointer
BANKSEL PORTE
MOVWF PORTE

read_again
MOVF pointer,0
CALL data_table
MOVWF sended_data
CALL send_595
MOVLW 0xFF
XORWF sended_data,0
BTFSC STATUS,Z
GOTO overflow
INCF pointer,1
CALL DELAY
GOTO read_again
overflow
MOVLW 0x00
MOVWF pointer
BCF STATUS,Z
CALL DELAY
GOTO read_again
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
send_595
BANKSEL PORTE
MOVLW 0x00
MOVWF check_8_bits
check_again
BTFSS sended_data,0
GOTO zero
GOTO one
zero
BCF PORTE,2
NOP
NOP
BSF PORTE,0
NOP
NOP
BCF PORTE,0
NOP
NOP
GOTO exit_595
one
BSF PORTE,2
NOP
NOP
BSF PORTE,0
NOP
NOP
BCF PORTE,0
NOP
NOP
exit_595
RRF sended_data,1
INCF check_8_bits
MOVLW d'8'
XORWF check_8_bits,0
BTFSS STATUS,Z
GOTO check_again

BCF STATUS,Z
BSF PORTE,1
BCF PORTE,1
RETURN
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
data_table
ADDWF PCL,1
RETLW b'00000000'
RETLW b'11111111'

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DELAY
CLRF DELAYL
CLRF DELAYM
MOVLW h'2'
MOVWF DELAYH
WAIT
DECFSZ DELAYL
GOTO WAIT
DECFSZ DELAYM
GOTO WAIT
DECFSZ DELAYH
GOTO WAIT
RETURN
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
END
 

Hi,

Port E defaults to ADC so you must first set it to Digital i/o

Its hard to follow all of your code as you have not put any comments at the side of it.

After you build your code, open MPlab SIM, then min your assembler page and open the View File Registers and open a Watch window for PortE then single step through your code using the F7 key so you can see if it works ok or not.
 

    kaszuky

    Points: 2
    Helpful Answer Positive Rating

Thank you very much! I will try to put comments at the side of it in later code . I will try your solution. Thank you again
 

@wp100 : Once again, I honestly want to say thank you for helping me . I using your debug technique and finally I found what I was wrong . I fixed it . Thank you very much
 

You can simplify your code a little too.

Remember that you can make all TRIS bits zero with CLRF so you don't have to load W then write it to the TRIS registers.

Not a mistake but you can make the code more readable by changing BSF/BCF PORTE bits to the names you define at the top of the program, so foe example BSF PORTE,0 becomes BSF PORTE,CLK. All you have to do is '#define CLK 0' so it associates the name CLK with the number zero. The same applies to the other signals.

Also when posting on Edaboard, if you click the code tag (the box below the subject line) just before your program code and again just after it, the forum will preserve your formatting so it is easier to read.

Brian.
 

    kaszuky

    Points: 2
    Helpful Answer Positive Rating
I use MOVLW and MOVWF instead of CLRF because using CLRF will effect on Z flag in STATUS register. I use this flag for my checking action in program. So if using CLRF, the BCF operand has to follow it. That is the reason why I use MOVLW ...

Thank you for your advice.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…