Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F84

Status
Not open for further replies.

cwt

New Member
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.:cry:


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
 
I am using 9600 bps and 4Mhz crystal oscillator.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top