RS232 Scope V1.02 Test Interface

with 16 bit Table Read

  This routine has been written to check the Excel Worksheet RS232scopeV102.xls .
  It reads 16 bit values from a table, proceeds framing and sends the data to the PC.
  The table was built with the "Automatic Table Generator for MPLAB Assembler"

Download Assembler program source :  scope.asm

For those, who are not familiar with interfacing a PIC to the RS232 using a MAX232 :   RS232-Interface.pdf   (9.7 kB)

;***************************************************************************
;                                                                     
;	RS232 Scope V1 Test Routine for PIC 16XXX
;	=========================================
;
;	written by Peter Luethi, 12.8.1999, Switzerland
;	last update : 20.8.99
;
;	This code and accompanying files may be distributed freely and
;	modified, provided this header with my name and this notice remain
;	intact. Ownership rights remain with me.
;	You may not sell this software without my approval.
;
;	This software comes with no guarantee or warranty except for my
;	good intentions. By using this code you agree to indemnify me from
;	any liability that might arise from its use.
;	
;
;	SPECIFICATIONS:
;	===============
;	Processor:			Microchip PIC 16F84
;	Clock:				4.00 MHz XT
;	Throughput:			1 MIPS
;
;	Required Hardware:		MAX232
;	Required Software:		MS Excel 97
;
;
;	DESCRIPTION:
;	============
;	Developed and tested on PIC 16F84.
;	Demonstrates the RS232 data fetch from an Excel Worksheet with
;	Visual Basic.
;	Routine shows 16 bit Table Read and RS232 Transmission with Framing.
;	The table data contains one half of a 16 bit "Sync"-function
;	(sin(x)/x), which is read alternating top-down and bottom-up to
;	get the entire function with minimal program code.
;	There is a table configuation section where you have to declare,
;	whether to send the top and bottom table item twice on
;	direction change.
;
;
;	REMARKS:
;	========
;	The table was generated with the
;	"Automatic Table Generator for MPLAB Assembler",
;	an Excel Worksheet with Visual Basic macro written by myself.
;
;***************************************************************************

;***** PROCESSOR DECLARATION & CONFIGURATION *****

	PROCESSOR 16F84
	#include "p16F84.inc"
	
	; embed Configuration Data within .asm File.
	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

;***** MEMORY STRUCTURE *****

	ORG     0x00		; processor reset vector
  	goto    MAIN

	ORG     0x04		; interrupt vector location
	goto	MAIN		; no Interrupt Service Routine

;***** HARDWARE DECLARATION *****

	#define	TXport	PORTA,0		; RS232 output port, could be
	#define	TXtris	TRISA,0		; any active push/pull port

;***** CONSTANT DECLARATION *****

	CONSTANT BASE = 0x0C		; Base address of user file registers

;***** REGISTER DECLARATION *****

	LO	equ	BASE+7
	HI	equ	BASE+8
	TXD	equ	BASE+9
	RXD	equ	BASE+10
	TblPtr	equ	BASE+11		; table pointer
	#define TblUpDn	BASE+12,0	; table read direction :
					; top down : 0, bottom up : 1

;***** TABLE CONFIGURATION *****

	#define TABLE_ITEMS	d'46'	; number of 16 bit words
	#define TOP_TWICE	a'F'	; send top/bottom item twice
	#define BOTTOM_TWICE	a'F'	; on direction change

;***** INCLUDE FILES *****

	#include "../../m_wait.asm"
	#include "../../m_rs192.asm"


;***** INTERRUPT SERVICE ROUTINE *****

ISR	; not used	( ISRend necessary for m_rs232.asm )

ISRend	bcf	INTCON,INTF	; clear interrupt flag RB0/INT
	RETFIE			; enable INTCON,GIE



;************** MAIN **************

MAIN	RS232init

	clrf	TblPtr
	bcf	TblUpDn

loop	movfw	TblPtr
	call	Table			; get Hi-Byte
	movwf	HI
	incf	TblPtr,1		; increment table pointer
	movfw	TblPtr
	call	Table			; get Lo-Byte
	movwf	LO

	;*** Table Read : top down ***
	btfsc	TblUpDn			; checks indicator, skip if clear
	goto	bottom_up		; if set -> bottom up
	incf	TblPtr,1		; increment table pointer

	;*** Check for end of Table ***
	movlw	(TABLE_ITEMS * 2)	; index of bottom LO
	subwf	TblPtr,0		; TblPtr - w -> w
	skpz				; check zero bit, skip if zero
	goto	xmit			; EXIT
	bsf	TblUpDn			; end of table, change direction
	IF BOTTOM_TWICE == a'T'
		incf	TblPtr,1
	ELSE
		decf	TblPtr,1
	ENDIF

bottom_up
	;*** Table Read : bottom up ***
	movlw	d'3'
	subwf	TblPtr,1
		
	;*** Check for top of Table ***
	movlw	d'1'-d'3'		; index of top LO - 3 (->subwf)
	subwf	TblPtr,0		; TblPtr - w -> w
	skpz				; check zero bit, skip if zero
	goto	xmit			; EXIT
	bcf	TblUpDn			; top of table, change direction
	clrf	TblPtr			; reset table pointer to top
	IF TOP_TWICE != a'T'
		incf	TblPtr,1
		incf	TblPtr,1
	ENDIF

xmit
	;*** FRAMING: start sequence ***
	SEND	'T'
	SEND	'X'

	;*** DATA: HI & LO Byte ***
	movfw	HI
	SENDw
	movfw	LO
	SENDw

	;*** FRAMING: stop sequence ***
	SEND	'/'
	SEND	'T'

	WAITX	d'7',d'7'
	goto	loop

Table 
	addwf	PCL,1
	retlw	0x38		; Hi-Byte
	retlw	0x4B		; Lo-Byte
	retlw	0x36
	retlw	0x78
	retlw	0x32
	retlw	0xE1
	retlw	0x2E
	retlw	0x29
	retlw	0x29
	retlw	0x37
	retlw	0x25
	retlw	0x06
	retlw	0x22
	retlw	0x79
	retlw	0x22
	retlw	0x2B
	retlw	0x24
	retlw	0x48
	retlw	0x28
	retlw	0x87
	retlw	0x2E
	retlw	0x29
	retlw	0x34
	retlw	0x21
	retlw	0x39
	retlw	0x3D
	retlw	0x3C
	retlw	0x68
	retlw	0x3C
	retlw	0xDE
	retlw	0x3A
	retlw	0x59
	retlw	0x35
	retlw	0x28
	retlw	0x2E
	retlw	0x29
	retlw	0x26
	retlw	0xA6
	retlw	0x20
	retlw	0x1A
	retlw	0x1B
	retlw	0xEE
	retlw	0x1B
	retlw	0x2B
	retlw	0x1E
	retlw	0x45
	retlw	0x24
	retlw	0xF1
	retlw	0x2E
	retlw	0x29
	retlw	0x38
	retlw	0x4E
	retlw	0x41
	retlw	0x67
	retlw	0x47
	retlw	0x7C
	retlw	0x48
	retlw	0xFA
	retlw	0x45
	retlw	0x02
	retlw	0x3B
	retlw	0xB0
	retlw	0x2E
	retlw	0x29
	retlw	0x1E
	retlw	0x8F
	retlw	0x0F
	retlw	0xB3
	retlw	0x04
	retlw	0xB9
	retlw	0x00
	retlw	0x94
	retlw	0x05
	retlw	0x8C
	retlw	0x14
	retlw	0xCE
	retlw	0x2E
	retlw	0x29
	retlw	0x4F
	retlw	0xF9
	retlw	0x77
	retlw	0x45
	retlw	0xA0
	retlw	0x1E
	retlw	0xC6
	retlw	0x1B
	retlw	0xE4
	retlw	0xEF
	retlw	0xF9
	retlw	0x06
	retlw	0xFF
	retlw	0xFF

	END



If you see only this page in your browser window,
click here
to get the entire site.