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.

need urgent help in the code

Status
Not open for further replies.

sibycharley

New Member
below i hav written a code that i believe can do the the a/d con version and serially transmit the the conversions to the pc, but while testing the o/p portb where the converted values are given i am not having a stable o/p ie whatever is the analog i/p all pins are are showing low and high values in fast succession. plz someone suggest me way to overcome this problem.

LIST P=16F73
INCLUDE "P16F73.INC"

COUNT1 equ H'23'
COUNT2 equ H'24'

MOVLW D'300'
MOVF COUNT1
MOVLW D'124'
MOVF COUNT2

ORG0X000
GOTO START

START
BCF STATUS,RP0
BCF STATUS,RP1
CLRF PORTA
CLRF PORTB
CLRF PORTC
BSF STATUS,RP0
CLRF TRISB
MOVLW B'00000001'
MOVWF TRISA
MOVLW B'11000000'
MOVWF TRISC
MOVLW B'00000000'
MOVWF ADCON1
MOVLW 1
MOVWF SPBRG
BCF STATUS,RP0
MOVLW B'01000001'
MOVWF ADCON0
MOVLW B'10010000'
MOVWF RCSTA
BSF STATUS,RP0
MOVLW B'00100010'
MOVWF TXSTA
BCF STATUS,RP0


MAIN
BSF ADCON0,2

CHECK
BTFSC ADCON0,2
GOTO CHECK
;BSF STATUS,RP0
MOVF ADRES,W
;BCF STATUS,RP0
MOVWF PORTB
MOVF PORTB,W


DELAY

Loop1
decfsz COUNT2,f
goto Loop1
Loop2
decfsz COUNT1,f
goto Loop2


PR_Loop
BTFSC PIR1,TXIF
GOTO Stuff_Chr
GOTO PR_Loop
Stuff_Chr
MOVWF TXREG
RETURN

GOTO MAIN
END
 
A couple of things.

First, try using the code tag to post code. It is on the advanced page and makes reading code so much easier.

Your code looks to be mainly correct but with a few (very common) mistakes.
You don't allow any time for the capacitor of the ADC to charge. You need to insert a small delay before the label MAIN. Start by inserting 20 nop instructions there and see if it works. Your other mistake is to do a return without doing a call. For now just delete the return instruction.

Mike.
 
Pommie said:
A couple of things.

Start by inserting 20 nop instructions there and see if it works.
Mike.
Or 10 goto $+1 instructions as these take 2 instruction cycles
 
Or,
Code:
	movlw	5
Delay	addlw	0xff
	btfss	STATUS,Z
	goto	Delay

There are lots of ways to do it, the NOP suggestion was the simplest to understand for a beginner.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top