;*************************************************************************** ; ; RS232 Scope V1.02 Test Routine for PIC 16XXX ; ============================================ ; ; written by Peter Luethi, 12.08.1999, Dietikon, Switzerland ; http://www.electronic-engineering.ch ; last update: 23.01.2005 ; ; V1.02: Re-structured ISR to comply with latest modules, ; added label _ISR_RS232error ; (19.04.2004) ; ; V1.01: Minor refinements (20.08.1999) ; ; V1.00: Initial release (12.08.1999) ; ; 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 Frequency: 4.00 MHz XT ; Throughput: 1 MIPS ; RS232 Baud Rate: 19200 baud (depends on the module included) ; Serial Output: 19200 baud, 8 bit, no parity, 1 stopbit ; Code Size of entire Program: approx. 204 instruction words ; Required Hardware: MAX232 ; Required Software: MS Excel 97 ; ; ; DESCRIPTION: ; ============ ; Developed and tested on PIC16F84. ; 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. ; ; ; Program shows the implementation and function of the modules ; m_bank.asm, m_wait.asm, and m_rs192.asm on the PIC16F84. ; ; ; REMARKS: ; ======== ; The table was generated with the ; "Automatic Table Generator for MPLAB Assembler", ; an Excel Worksheet with Visual Basic macro written by myself. ; ;*************************************************************************** ;***** COMPILATION MESSAGES & WARNINGS ***** ERRORLEVEL -207 ; found label after column 1 ERRORLEVEL -302 ; register in operand not in bank 0 ;***** PROCESSOR DECLARATION & CONFIGURATION ***** ;PROCESSOR 16F84A ;#include "p16f84a.inc" 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 (ISR) ;***** 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 ***** FLAGreg equ BASE+d'7' #define TblUpDn FLAGreg,0x00 ; table read direction : ; top down: 0, bottom up: 1 LO equ BASE+d'8' HI equ BASE+d'9' TXD equ BASE+d'10' RXD equ BASE+d'11' TblPtr equ BASE+d'12' ; table pointer ;***** TABLE CONFIGURATION ***** #define TABLE_ITEMS d'46' ; number of 16 bit words #define TOP_TWICE a'F' ; a'T' = (true) send top/bottom item #define BOTTOM_TWICE a'F' ; twice on direction change ;***** INCLUDE FILES ***** #include "..\..\m_bank.asm" ; standard macros #include "..\..\m_wait.asm" #include "..\..\m_rs192.asm" ; specify desired RS232 module ;***** INTERRUPT SERVICE ROUTINE ***** ISR ; not used ( ISRend necessary for m_rs232.asm ) _ISR_RS232error ISRend bcf INTCON,INTF ; clear interrupt flag RB0/INT RETFIE ; enable INTCON,GIE ;***** END OF INTERRUPT SERVICE ROUTINE ***** ;************** 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