Hi--
I'm trying to adapt Microchip's AN1076 appnote on DMX to use as an assembly language subroutine in PBP. I'm using a PIC18F4520, 16MHz resonator, PBP 2.5a. What the code should do is initialize the LCD, read the DMX data stream, and then display the value present on DMX channel 7 on the LCD. I am feeding in a DMX signal, and I've had a PBP-coded subroutine working just fine on my hardware test board, but I need more speed. Both the SetupSerial subroutine and the DMXloop subroutine compile just fine, but when I call the DMXloop subroutine, that's the last I see of my program's execution, nothing else happens. I assume I'm jumping off into oblivion somehow... my understanding of assembly is limited, so I'd appreciate any commentary.
Thanks in advance--
--Alan
Code:
' for PIC18F4530
DEFINE OSC 16
INCLUDE "modedefs.bas"
include "LCD_defines602.pbp"
' ****************************************
' SETUP
' ****************************************
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000
trisa = %11111101
trisb = %01111111
TRISC = %11101000
trisd = %11001011
ADCON1 = %00001111 'port a is all digital IO
CMCON = 7 'and turn off those pesky comparators
RBPUx VAR INTCON2.7 'port b pull-ups 1 = disabled 0 = enabled
RBPUx = 0
trise.4 =%0 'disable PSP port
' ===================================
' define hardware pins:
' ===================================
BKLT var portd.5 'LCD backlight
' ================================
' define constants & variables:
' ================================
DMXrxbuffer var byte[512]
CountH var byte
CountL var byte
count0 var byte
' ****************************************
' INITIALIZATION
' ****************************************
init:
call SetupSerial 'set up USART and clear DMXrxbuffer
' ****************************************
' MAIN LOOP
' ****************************************
begin: low bklt 'turn on backlight
pause 125 'pause to let LCD initialize
lcdout $fe,1 'clear screen
LCDout " test routine " 'display splashscreen
lcdout $fe,$c0,"S/W Version 6xxx"
pause 1200
low bklt
mainloop:
Call DMXloop
lcdout $fe,1
pause 3
lcdout dec DMXrxbuffer[7]
pause 300
goto mainloop
asm
_DMXloop
; first loop, synchronizing with the transmitter
_WaitBreak
btfsc PIR1,RCIF ; if a byte is received correctly
movf RCREG,W ; discard it
btfss RCSTA,FERR ; else
bra _WaitBreak ; continue waiting until a frame error is detected
movf RCREG,W ; read the Receive buffer to clear the error condition
; second loop, waiting for the START code
_WaitForStart
btfss PIR1,RCIF ; wait until a byte is correctly received
bra _WaitForStart
btfsc RCSTA,FERR
bra _WaitForStart
movf RCREG,W
; check for the START code value, if it is not 0, ignore the rest of the frame
andlw 0xff
bnz _DMXloop ; ignore the rest of the frame if not zero
; init receive counter and buffer pointer
clrf _CountL
clrf _CountH
lfsr 0,_DMXrxbuffer
; third loop, receiving 512 bytes of data
_WaitForData
btfsc RCSTA,FERR ; if a new framing error is detected (error or short frame)
bra _RXend ; the rest of the frame is ignored and a new synchronization
; is attempted
btfss PIR1,RCIF ; wait until a byte is correctly received
bra _WaitForData ;
movf RCREG,W ;
_MoveData
movwf POSTINC0 ; move the received data to the buffer
; (auto-incrementing pointer)
incf _CountL,F ; increment 16-bit counter
btfss STATUS,C
bra _WaitForData
incf _CountH,F
btfss _CountH,1 ; check if 512 bytes of data received
bra _WaitForData
_RXend
return
;****************************************************************
; Setup Serial port and buffers
_SetupSerial
;Clear the receive buffer
lfsr 0,_DMXrxbuffer
_CBloop
clrf POSTINC0 ; clear INDF register then increment pointer
incf _CountL,F
btfss STATUS,C
bra _CBloop
incf _CountH,F
btfss _CountH,1
bra _CBloop
; Setup EUSART
bsf TRISC,7 ; allow the EUSART RX to control pin RC7
bsf TRISC,6 ; allow the EUSART TX to control pin RC6
movlw 0x04 ; Disable transmission
movwf TXSTA ; enable transmission and CLEAR high baud rate
movlw 0x90
movwf RCSTA ; enable serial port and reception
bsf BAUDCON,BRG16 ; Enable UART for 16-bit Asyn operation
clrf SPBRGH
movlw .15 ; Baud rate is 250KHz for 16MHz Osc. freq.
movwf SPBRG
return
endasm
Bookmarks