;----------------------------------------------------------------------------- ; Full-duplex software UART ; ; This version is for the Scenix SX Microcontroller, and runs on the ; Parallax SX-Key Demo Board. Assemble with Microchip's MPASM assembler. ; ; Copyright 1996, 1998 Eric Smith ; ; Permission is granted to use this code or portions thereof for ; non-commercial purposes provided that the copyright notice is preserved ; intact and that credit is given to the author. For any other use, a ; license may be obtained from the author; send email to eric@brouhaha.com. ; ; $Id: fduart.asm,v 1.3 1998/11/05 06:35:07 eric Exp eric $ ;----------------------------------------------------------------------------- radix dec errorlevel -302 errorlevel -305 processor 16c57 ; really a Scenix SX, but MPASM doesn't ; know about those ;----------------------------------------------------------------------------- ; Scenix SX18AC/SX28AC register definitions ;----------------------------------------------------------------------------- indf equ 00h rtcc equ 01h pcl equ 02h status equ 03h fsr equ 04h porta equ 05h portb equ 06h portc equ 07h ; bits in status: c equ 0 z equ 2 ;----------------------------------------------------------------------------- ; ASCII characters ;----------------------------------------------------------------------------- lf equ 00ah cr equ 00dh ;----------------------------------------------------------------------------- ; Scenix instruction macros ;----------------------------------------------------------------------------- ret macro data 0ch ;RET ;return without destroying W register endm reti macro data 0eh endm retiw macro data 0fh endm pagex macro n ;(MPASM already uses "PAGE") data 10h|n ;PAGE ;write N into bits PA2:PA0 (N = 0-7) endm bankx macro n ;(MPASM already uses "BANK") data 18h|(n>>5) ;BANK ;write N into bits FSR7:FSR5 (N = 0-7) endm mode macro n data 50h|n ;MODE ;write N into MODE register (N = 0-F) endm ;----------------------------------------------------------------------------- ; target-specific definitions ;----------------------------------------------------------------------------- rx_ring_size equ 010h tx_ring_size equ 010h xtalfreq equ 50000000 b115200 equ -145 ; xtalfreq/(3*115200) rxport equ porta rxbit equ 2 rxinv equ 0 txport equ porta txbit equ 3 txinv equ 0 button_port equ portb maxbutton equ 4 porta_init equ 0ffh porta_tris equ (1<only< be used in interrupt handler ser_temp: res 1 ; ser_temp must be global rather than in ser_vars ; ser_temp may not be used in interrupt handler msg_temp: res 1 ; this could be in main_vars temp: res 1 temp2: res 1 temp3: res 1 led_stat: res 1 ; this should be in button_vars, but I got lazy ; and referenced it directly from main org 010h main_vars = $ org 030h button_vars = $ but_press_cnt: res maxbutton but_mask: res 1 but_poll_cnt: res 1 but_stat: res 1 ; button status, 1 bit per button ; mainline code will clear bit to acknowledge org 050h ser_vars = $ uartspeed: res 1 uartstat: res 1 ; bits in uartstat: rbf equ 7 tbf equ 6 rxovr equ 5 rxfrm equ 4 rxphase equ 1 txphase equ 0 rx_ring_ip: res 1 rx_ring_op: res 1 rx_ring_cnt: res 1 tx_ring_ip: res 1 tx_ring_op: res 1 tx_ring_cnt: res 1 rxbits: res 1 rxbitcnt: res 1 rxmask: res 1 txbyte: res 1 txbitcnt: res 1 org 070h rx_ring: res rx_ring_size org 090h tx_ring: res tx_ring_size ;----------------------------------------------------------------------------- ; UART macros ;----------------------------------------------------------------------------- ringadv macro ptr,base,size local pow2,aligned,bit,val pow2 set !(size&(size-1)) aligned set pow2&&((base&(size-1))==0) if aligned val set size bit set 0 while val>1 bit set bit+1 val set val>>1 endw endif incf ptr if aligned&&!(base&(1< 3, return andlw 0fch btfss status,z ret movf but_poll_cnt,w ; must be between 0 and 3 addwf pcl goto but_set_input goto but_read_input goto led_set_output ret led_set_output: movf led_stat,w xorlw 0ffh movwf button_port movlw 0 tris button_port ret but_set_input: movlw (1<>12 ; (PINS, CARRYX, BOR40, BANKS, PAGES) errorlevel +220 ;restore warning message end