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.

Problem in a code for PIC16F84 to act as a data converter

Status
Not open for further replies.

cwt

Member level 5
Member level 5
Joined
May 26, 2004
Messages
80
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
918
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
 

pic16f84 rs232 9600 bps

I am using 9600 bps and 4Mhz crystal oscillator.
 

Re: PIC16F84

cwt said:
Sometimes will get the right output, sometimes wont. Most of the time, it is the wrong output. :(
yes you must re-synchronize
but if you want to build a real RS232 to parallel interface the best way is to change PIC with built-in USART, data flow control lines and program a data buffer
 

PIC16F84

re-synchronize means?i have to alter the delay time?
 

Re: PIC16F84

I got 51us and 99us (excluding CALL instruction) for your 2 delay routines on a rough count. Kindly check them again.
 

Re: PIC16F84

What does your input circuit for RS232 look like?

MAX232 or transistor or direct connection?

How are your configuration fuses for the 16C84?

best regards
 

PIC16F84

i am using max232.
my delay routine is wrong?
 

Re: PIC16F84

Your delay routines should be OK, it does not really matter if you delay for 49 or 51 (or 102 instead of 104) uS :)

But I would check Temp_Store as you forget to clear it after you have received 8 databits ...

CALL BIT_DELAY
MOVF TEMP_STORE, 0
MOVWF PORTB
CLRF TEMP_STORE ;<-- insert this here

GOTO START


best regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top