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.

P16F88 ADC output not transmitting via serial

Status
Not open for further replies.

kolea

Newbie level 2
Joined
Apr 13, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,297
Hey folks.

I'm new to PIC programming and my project is to take 4 analog samples (2 voltage; 2 current - LT6101) and 1 digital (temperature - DS18S20) sample.

My initial challenge was to get good communication, but I have resolved that and I get good outputs via RS232 (MAX3232) to hyperterminal (HT).

I am now attempting to sample one port for voltage (through a 90.9k/10k divider) and output that value to HT.

With the code below, I get no output to HT (I have a blink subroutine to execute when I think a sample is being taken). Also, after a few cycles the sample 'heartbeat' stays high and no longer pulses.

This code builds with no errors.

I would appreciate any recommendations (and general critique of my code; I'm very new to this and want to learn the proper setup now).

Thank you in advance for any assistance you can provide.

If there is any more information I need to provide please let me know as well.

Code:
        list		p=16f88
	#include 	<P16F88.inc>

	errorlevel	-302

	__CONFIG	_CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
	__CONFIG	_CONFIG2, _IESO_OFF & _FCMEN_OFF

; *** User Registers ***

CNT1	equ		0x20
CNT2	equ		0x21
CNT3	equ		0x22
TEMP	equ		0x23

TXDATA	equ		0x25
RXDATA	equ		0x26

HEXNUM	equ		0x27
AHN		equ		0x28
ALN		equ		0x29

CNT4	equ		0x2A
CNT5	equ		0x2B

; *** Bit Definitions ***

#define		IRP_bit	STATUS,7  ; register bank select (indirect addressing)
#define		RP1_bit	STATUS,6  ; register bank select (direct addressing)
#define		RP0_bit	STATUS,5  ; register bank select (direct addressing)

#define		LED		PORTB,3	  ; LED

; *** Reset Vectors ***

	ORG		0x000
	goto	normal_entry

	ORG		0x020

normal_entry	
	goto	main

; *** Subroutines ****

; *** Delay for 100 ms @ 4 MHz ***

ms100	movlw	D'100'
		movwf	CNT2
loop_a	movlw	D'250'
		movwf	CNT1
loop_b	nop
		decfsz	CNT1,f
		goto	loop_b
		decfsz	CNT2,f
		goto	loop_a
		return
; *** Delay for 200 ms @ 4 MHz ***

ms200	call 	ms100
		call	ms100
		return

; *** Delay for 0.5 s @ 4 MHz ***

halfsec	call	ms200
		call	ms200
		call 	ms100
		return

; *** Delay for 1 s @ 4 MHz ***

onesec 	call	halfsec
		call	halfsec
		return

; *** Delay for 2 s @ 4 MHz ***

twosec	call	onesec
		call 	onesec
		return

; *** Delay for 5 s @ 4 MHz ***

fivesec	call	twosec
		call	twosec
		call	onesec
		return

; *** Delay for 480 us @ 4 MHz ***

us480	movlw	D'120'
		movwf	CNT1
loop4us	nop
		decfsz	CNT1,f
		goto	loop4us
		return

; *** Delay for 60 us @ 4 MHz

us60	movlw	D'15'
		movwf	CNT1
		goto	loop4us

; *** ADC ***

get_ad	movlw   D'100'
        movwf   CNT1  
acquire	decfsz  CNT1,F 
        goto    acquire    
        bsf     ADCON0,GO_DONE  
convert    btfsc   ADCON0,GO_DONE  
        goto    convert
		return     

; *** Hex to ascii convert, convert byte in HEXNUM ***

n2s	clrf	AHN
	swapf	HEXNUM,W	

nibble	andlw	0x0F		
		movwf	ALN		
		sublw	D'9'		
		btfss	STATUS,C	
		goto	hexa2f
		movlw	0x30		
		goto	ascii
hexa2f	movlw	0x37		
ascii	addwf	ALN,f
		movf	AHN,f		
		btfss	STATUS,Z	
		goto	aln_ok
		movf	ALN,W		
		movwf	AHN		
		movf	HEXNUM,W
		goto	nibble

aln_ok	return			; result in AHN and ALN

; *** Calls n2s and then transmits with ser_tx ***

n2s_tx 	call	n2s		

	movf	AHN,W
	movwf	TXDATA	
	call	ser_tx		
	movf	ALN,W
	movwf	TXDATA	
	call	ser_tx		

	return

; *** Read and transmit voltage ***

voltage	call	get_ad
	movf	ADRESH,W
	movwf	HEXNUM
	call	n2s_tx

	return

; *** Blink ***

blink	bsf		LED
		call	twosec
		bcf		LED
		call	twosec
		return

blink_fast	bsf		LED
		call	ms200
		bcf		LED
		call	ms200
		return

; *** Serial port transmit ***

ser_tx	btfss	PIR1,TXIF
		goto	ser_tx
		movf	TXDATA,w
		movwf	TXREG
	
		return

; *** Serial Test ***

;serial_test	
;			movlw	0x21
;			movwf	TXDATA
;			call	ser_tx
;			movlw	0x0D
;			movwf	TXDATA
;			call	ser_tx
;			movlw 	0x0A
;			movwf 	TXDATA
;			call 	ser_tx
;			call	twosec
;			call ser_tx
;			
;			return 

; *** Main Code ***

main	bcf		IRP_bit
		bcf		RP0_bit
		bcf		RP1_bit

		movlw	OSCCON
		movwf	FSR
		movlw	B'01100000'
		iorwf	INDF,f

		movlw	ANSEL
		movwf	FSR
		movlw	B'00010000'
		movwf	INDF

		movlw	TRISA
			movwf	FSR
			movlw	B'01111111'
			movwf	INDF		

		movlw	TRISB
			movwf	FSR
			movlw	B'10110110'
			movwf	INDF

		movlw	ADCON0
			movwf	FSR
			movlw	B'01000001'
			movwf	INDF

		movlw	ADCON1
			movwf	FSR
			movlw	B'01000000'
			movwf INDF

		movlw	TRISB
			movwf	FSR
			movlw	B'00100100'
			iorwf	INDF,f

		movlw	TXSTA
			movwf	FSR
			movlw	B'00100100'
			movwf	INDF
	
			movlw	B'10010000'
			movwf	RCSTA

		movlw	SPBRG
			movwf	FSR
			movlw	D'12'
			movwf	INDF

		clrf	RXDATA
		bcf		LED	
	
		call	onesec
		call	blink

loop	call	voltage
        call    fivesec

		goto	loop

	END
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top