; eBASIC PIC16 Code Generator ; Copyright(c) 2004, Compubotics LLC ; www.Compubotics.com ORG 0x0 ; File: stdio.bas ; ' Standard IO functions ; ' ; ' eBASIC Example program ; ' www.compubotics.com ; ' ; #include "rc40.inc" ; ; ' store chars ; ch var byte ; ; ' standard console chars ; CH_LF CON 11 ; CH_CR CON 13 ; CH_ESC CON 27 ; ; Main: nop clrf 0xa goto _startup ORG 0x4 retfie _STR001: retlw 0x50 retlw 0x72 retlw 0x65 retlw 0x73 retlw 0x73 retlw 0x20 retlw 0x45 retlw 0x53 retlw 0x43 retlw 0x20 retlw 0x74 retlw 0x6f retlw 0x20 retlw 0x65 retlw 0x6e retlw 0x64 retlw 0x0 _STR002: retlw 0x44 retlw 0x6f retlw 0x6e retlw 0x65 retlw 0x21 retlw 0x0 _startup: movlw 0x83 bsf 0x3,5 bcf 0x3,6 movwf 0x81 bcf 0x3,5 bcf 0xb,5 bsf 0xb,6 movlw 0x31 movwf 0x10 movlw 0x60 movwf 0x78 call _uartSetup goto Main ; ; debug "Press ESC to end", CR Main: movlw 0x5 movwf 0x70 movlw 0x0 movwf 0x71 call _dbgStr movlw 0xd call _uartTX movlw 0xa call _uartTX ; ; ' if using the RC40 and host is expecting flow control, ; ' tell host we are receiving. delete next two lines if ; ' not using flow control. Our RTS is his CTS, and vice-versa ; ' for out "echo" program, we don't need anything since I can't ; ' type fast enough to overrun the buffer, so just tell host "OK" ; trisrts = 0 bsf 0x3,5 bcf 0x3,6 bcf 0x86,6 ; rts = 0 bcf 0x3,5 bcf 0x6,6 ; ; while (1) ; ' get next char ; if (inchar) then _j000: btfss 0xc,5 goto _j002 movlw 0x1 movwf 0x70 movlw 0x0 movwf 0x71 goto _j003 _j002: clrf 0x70 clrf 0x71 _j003: clrf 0x72 clrf 0x73 call _comp16 btfsc 0x3,2 goto _j004 ; getchar ch call _uartRX bcf 0x3,5 bcf 0x3,6 movwf 0x20 ; else goto _j005 ; continue _j004: goto _j000 ; endif ; ; ; ' if ESC, exit ; if (ch = CH_ESC) then break _j005: movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0x1b movwf 0x72 movlw 0x0 movwf 0x73 call _comp16 btfsc 0x3,2 goto _j006 clrf 0x70 clrf 0x71 goto _j007 _j006: movlw 0x1 movwf 0x70 movlw 0x0 movwf 0x71 _j007: clrf 0x72 clrf 0x73 call _comp16 btfsc 0x3,2 goto _j008 goto _j001 ; ; ' echo char back to sender ; putchar ch _j008: bcf 0x3,5 bcf 0x3,6 movf 0x20,0 movwf 0x70 clrf 0x71 movf 0x70,0 call _uartTX ; ; ' if CR, send LF also ; if (ch = CH_CR) then bcf 0x3,5 bcf 0x3,6 movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0xd movwf 0x72 movlw 0x0 movwf 0x73 call _comp16 btfsc 0x3,2 goto _j009 clrf 0x70 clrf 0x71 goto _j010 _j009: movlw 0x1 movwf 0x70 movlw 0x0 movwf 0x71 _j010: clrf 0x72 clrf 0x73 call _comp16 btfsc 0x3,2 goto _j011 ; putchar CH_LF movlw 0xb movwf 0x70 movlw 0x0 movwf 0x71 movf 0x70,0 call _uartTX ; endif ; ; wend _j011: goto _j000 ; ; debug CR, "Done!", cr _j001: movlw 0xd call _uartTX movlw 0xa call _uartTX movlw 0x16 movwf 0x70 movlw 0x0 movwf 0x71 call _dbgStr movlw 0xd call _uartTX movlw 0xa call _uartTX ; ; end sleep goto $-1 _uartSetup: movlw 0x67 bsf 0x3,5 bcf 0x3,6 movwf 0x99 bsf 0x98,2 bsf 0x98,5 bcf 0x3,5 bsf 0x18,4 bsf 0x18,7 return _uartTX: bcf 0x3,5 bcf 0x3,6 btfss 0xc,4 goto $-1 movwf 0x19 return _inc16: incfsz 0x70,0 decf 0x71,1 incf 0x71,1 movwf 0x70 iorwf 0x71,0 return _dbgStr: call _j012 iorlw 0x0 btfsc 0x3,2 return call _uartTX call _inc16 goto _dbgStr _j012: movf 0x71,0 movwf 0xa movf 0x70,0 movwf 0x2 _comp16: movf 0x73,0 subwf 0x71,0 btfss 0x3,2 return movf 0x72,0 subwf 0x70,0 return _uartRX: bcf 0x3,5 bcf 0x3,6 btfss 0xc,5 goto $-1 movf 0x1a,0 return END ; end of code generation