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.

Simple HUART test

Status
Not open for further replies.

ttbuddy

New Member
I am trying the basic serial communication test on ASM, but having this error:

Code:
;
;
;
	list			p=16F88, r=DEC
	errorlevel		-302
	#include 		<p16f88.inc>

	__config 		_CONFIG1, _BODEN_OFF & _WDT_OFF & _LVP_OFF & _MCLR_OFF & _PWRTE_ON & _INTRC_IO

;----------------------
; DECLARE VARIABLES
;----------------------

	UDATA

tmp1 			res 1

;----------------------
; START
;----------------------
main			code
	movlw 		7
	movwf 		CMCON				; CMCON = 7 set comperators off

	banksel		TRISB
	movlw		b'00000100'			; RB2 is RX, and is therefore an input
	movwf		TRISB

	banksel		SPBRG
	movlw		0x19				; 0x19=9600 bps (0x0C=19200 bps)
	movwf		SPBRG
	movlw		b'00100100'			; brgh = high (2)
	movwf		TXSTA				; enable Async Transmission, set brgh

	banksel		RCSTA
	movlw 		b'10010000'			; enable Async Reception
	movwf		RCSTA


	; Provide a settling time for startup
	clrf 		tmp1
settle
	decfsz 		tmp1, f
	goto 		settle

	movf 		RCREG, W			; Flush RX buffer
	movf 		RCREG, W
	movf 		RCREG, W

	; Send a character through the UART
loop
	movlw		'A'
	call		send
	goto		loop
	goto		$


;----------------------
; RECEIVE function
;----------------------
receive
	btfss 		PIR1, RCIF			; Check if data has been received
	goto 		receive
	movf 		RCREG, W            ; Save received data in W
	return

;----------------------
; SEND function
;----------------------
send
	movwf 		TXREG				; Send data which has been stored in W

trans_wt
	banksel		TXSTA
	btfss 		TXSTA, TRMT			; Loop until data is sent
	goto		trans_wt		
	return

	end


The error message:
Code:
----------------------------------------------------------------------
Debug build of project `D:\Test\Test.mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Sun Mar 15 00:33:51 2009
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F88 "f3c2a2afe.asm" /l"f3c2a2afe.lst" /e"f3c2a2afe.err" /d__DEBUG=1
Error[149]   D:\TEST\F3C2A2AFE.ASM 14 : Directive only allowed when generating an object file
Error[149]   D:\TEST\F3C2A2AFE.ASM 21 : Directive only allowed when generating an object file
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `D:\Test\Test.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Sun Mar 15 00:33:52 2009
----------------------------------------------------------------------
BUILD FAILED
 
hi tt,
This is causing your problem

Code:
	UDATA

tmp1 			res 1

;----------------------
; START
;----------------------
main			code

Make it:
; lose the UDATA
tmp1 equ 0x20

....

main; lose the 'code'

Use Build on MPLAB
 
Last edited:
Well, i'd made the changes according to ur reply:

Code:
;
;
;
	list			p=16F88, r=DEC
	errorlevel		-302
	#include 		<p16f88.inc>

	__config 		_CONFIG1, _BODEN_OFF & _WDT_OFF & _LVP_OFF & _MCLR_OFF & _PWRTE_ON & _INTRC_IO

;----------------------
; DECLARE VARIABLES
;----------------------

;	UDATA
tmp1            equ 0x20
;tmp1 			res 1

;----------------------
; START
;----------------------
main			;code
	movlw 		7
	movwf 		CMCON				; CMCON = 7 set comperators off

	banksel		TRISB
	movlw		b'00000100'			; RB2 is RX, and is therefore an input
	movwf		TRISB

	banksel		SPBRG
	movlw		0x19				; 0x19=9600 bps (0x0C=19200 bps)
	movwf		SPBRG
	movlw		b'00100100'			; brgh = high (2)
	movwf		TXSTA				; enable Async Transmission, set brgh

	banksel		RCSTA
	movlw 		b'10010000'			; enable Async Reception
	movwf		RCSTA


	; Provide a settling time for startup
	clrf 		tmp1
settle
	decfsz 		tmp1, f
	goto 		settle

	movf 		RCREG, W			; Flush RX buffer
	movf 		RCREG, W
	movf 		RCREG, W

	; Send a character through the UART
loop
	movlw		'A'
	call		send
	goto		loop
	goto		$


;----------------------
; RECEIVE function
;----------------------
receive
	btfss 		PIR1, RCIF			; Check if data has been received
	goto 		receive
	movf 		RCREG, W            ; Save received data in W
	return

;----------------------
; SEND function
;----------------------
send
	movwf 		TXREG				; Send data which has been stored in W

trans_wt
	banksel		TXSTA
	btfss 		TXSTA, TRMT			; Loop until data is sent
	goto		trans_wt		
	return

	end

well, I just need to know, what is these two meant for?

tmp1 equ 0x20
tmp1 res 1


coz i'd commented out ;tmp1 res 1

Thanks
 
I had a quick glance at your code and a couple of things stood out,

CMCON is in bank 1,
Your are not clearing ANSEL,
Both RX and TX should be set to input.

Apart from that it looks like it should work as expected.

Mike.
 
well, I just need to know, what is these two meant for?

tmp1 equ 0x20
tmp1 res 1

coz i'd commented out ;tmp1 res 1
That sets tmp1 as a variable in RAM. You could just use the number 0x20, but that's not terribly clear. So you use a label and call it a variable.

Another way to do that is like this:
Code:
        cblock  0x20
        tmp1,tmp2,variable3,variable4
        endc
In that little block I've declared a block of four one-byte variables in RAM, starting at 0x20.
 
I had a quick glance at your code and a couple of things stood out,

CMCON is in bank 1,
Your are not clearing ANSEL,
Both RX and TX should be set to input.

Apart from that it looks like it should work as expected.

Mike.

clearing ANSEL?
Sorry .. I am new to assembly...
Why RX n TX s input? Not just RX?
 
When you turn off the comparators it is normal to switch to digital I/O by also clearing ANSEL. In this case it doesn't matter as you aren't using Port A. The RX and TX pins have to be set to input so the UART module can use them - see section 11 of the data sheet.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top