cwt
Member level 5
registers counting wrong pic16f84
Hi there..
Currently, i am trying on the PIC16F84 to act as a serial to parallel data converter..
I'll enclose my source code here..
There a problem surface when i try my code.
The 8LEDs (represent 8 parallel bits) will not light up accordingly. Sometimes will get the right output, sometimes wont. Most of the time, it is the wrong output.
LIST p=16F84
include "P16F84.inc"
;------------------------------------------------------------------
CBLOCK 0x20 ;starting address of general register
BIT_COUNTER
NEXT_BIT
DELAY_COUNT
TEMP_STORE
ENDC
;------------------------------------------------------------------
BSF STATUS, RP0 ;initialize RA0 as input
MOVLW 0x01
MOVWF TRISA
BCF STATUS, RP0
CLRF PORTA
BSF STATUS, RP0 ;initialise portB as output
MOVLW 0x00
MOVWF TRISB
BCF STATUS, RP0
CLRF PORTB
GOTO START ;go to main program
;------------------------------------------------------------------
START_DELAY MOVLW 0x0C ;subroutine to delay 52us
MOVWF DELAY_COUNT
START_WAIT NOP
DECFSZ DELAY_COUNT, 1
GOTO START_WAIT
RETURN
;-------------------------------------------------------------------
BIT_DELAY MOVLW 0x18 ;subroutine to delay 104us
MOVWF DELAY_COUNT
BIT_WAIT NOP
DECFSZ DELAY_COUNT, 1
GOTO BIT_WAIT
RETURN
;-------------------------------------------------------------------
START BTFSC PORTA, 0 ;detect start bit
GOTO START
CALL START_DELAY ;make sure start bit is still there
BTFSC PORTA, 0
GOTO START
MAIN CLRF PORTB
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 0
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 1
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 2
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 3
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 4
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 5
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 6
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 7
CALL BIT_DELAY
MOVF TEMP_STORE, 0
MOVWF PORTB
GOTO START
END
Hi there..
Currently, i am trying on the PIC16F84 to act as a serial to parallel data converter..
I'll enclose my source code here..
There a problem surface when i try my code.
The 8LEDs (represent 8 parallel bits) will not light up accordingly. Sometimes will get the right output, sometimes wont. Most of the time, it is the wrong output.
LIST p=16F84
include "P16F84.inc"
;------------------------------------------------------------------
CBLOCK 0x20 ;starting address of general register
BIT_COUNTER
NEXT_BIT
DELAY_COUNT
TEMP_STORE
ENDC
;------------------------------------------------------------------
BSF STATUS, RP0 ;initialize RA0 as input
MOVLW 0x01
MOVWF TRISA
BCF STATUS, RP0
CLRF PORTA
BSF STATUS, RP0 ;initialise portB as output
MOVLW 0x00
MOVWF TRISB
BCF STATUS, RP0
CLRF PORTB
GOTO START ;go to main program
;------------------------------------------------------------------
START_DELAY MOVLW 0x0C ;subroutine to delay 52us
MOVWF DELAY_COUNT
START_WAIT NOP
DECFSZ DELAY_COUNT, 1
GOTO START_WAIT
RETURN
;-------------------------------------------------------------------
BIT_DELAY MOVLW 0x18 ;subroutine to delay 104us
MOVWF DELAY_COUNT
BIT_WAIT NOP
DECFSZ DELAY_COUNT, 1
GOTO BIT_WAIT
RETURN
;-------------------------------------------------------------------
START BTFSC PORTA, 0 ;detect start bit
GOTO START
CALL START_DELAY ;make sure start bit is still there
BTFSC PORTA, 0
GOTO START
MAIN CLRF PORTB
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 0
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 1
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 2
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 3
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 4
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 5
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 6
CALL BIT_DELAY
BTFSC PORTA, 0
BSF TEMP_STORE, 7
CALL BIT_DELAY
MOVF TEMP_STORE, 0
MOVWF PORTB
GOTO START
END