; eBASIC PIC16 Code Generator ; Copyright(c) 2004, Compubotics LLC ; www.Compubotics.com ORG 0x0 ; File: hello.bas ; ' Enhanced Hello World Example ; ' eBASIC Compiler example ; ' ; ' This version of "Hello world" uses WHILE..WEND ; ' It prints the text 10 times, then ends ; ; ' We're using a 16F877 at 16MHz ; ' insert your MCU and clock here ; #device "16f877" ; #clock 16000000 ; ; Hello con "Hello world!" ; C var byte ; ; Main: nop clrf 0xa goto _startup ORG 0x4 retfie Hello: retlw 0x48 retlw 0x65 retlw 0x6c retlw 0x6c retlw 0x6f retlw 0x20 retlw 0x77 retlw 0x6f retlw 0x72 retlw 0x6c retlw 0x64 retlw 0x21 retlw 0x0 _startup: movlw 0x83 bsf 0x3,5 movwf 0x81 bcf 0xb,5 movlw 0x39 bcf 0x3,5 movwf 0x10 movlw 0x60 movwf 0x78 call _uartSetup goto Main ; ; c = 0 Main: bcf 0x3,5 bcf 0x3,6 movlw 0x0 movwf 0x20 ; ; while (c < 10) _j000: movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0xa movwf 0x72 movlw 0x0 movwf 0x73 call _lcomplt16 clrf 0x72 clrf 0x73 call _comp16 btfsc 0x3,2 goto _j001 ; debug hello, CR movlw 0x5 movwf 0x70 movlw 0x0 movwf 0x71 call _dbgStr movlw 0xd call _uartTX movlw 0xa call _uartTX ; pause 1000 movlw 0xe8 movwf 0x70 movlw 0x3 movwf 0x71 call _pause ; c = c + 1 bcf 0x3,5 bcf 0x3,6 movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0x1 movwf 0x72 movlw 0x0 movwf 0x73 call _add16a bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x20 ; wend goto _j000 ; ; END _j001: 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 _comp16: movf 0x73,0 subwf 0x71,0 btfss 0x3,2 return movf 0x72,0 subwf 0x70,0 return _lcomplt16: call _comp16 btfss 0x3,0 goto _j002 _j003: clrf 0x70 clrf 0x71 return _j002: movlw 0x1 movwf 0x70 clrf 0x71 return _lcomplteq16: call _comp16 btfss 0x3,2 goto _lcomplt16 goto _j002 _lcompgteq16: call _comp16 btfss 0x3,2 goto _LCOMPGT16 goto _j002 _lcompgt16: call _comp16 btfsc 0x3,2 goto _j003 btfsc 0x3,0 goto _j002 goto _j003 _LCOMPNE16: call _comp16 btfss 0x3,2 goto _j003 goto _j002 _LNOT16: clrf 0x70 clrf 0x71 call _comp16 btfss 0x3,2 goto _j002 goto _j003 _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 _j004 iorlw 0x0 btfsc 0x3,2 return call _uartTX call _inc16 goto _dbgStr _j004: movf 0x71,0 movwf 0xa movf 0x70,0 movwf 0x2 _dec16: decf 0x70,1 incfsz 0x70,0 incf 0x71,1 decf 0x71,1 movf 0x70,0 iorwf 0x71,0 return _pause: bcf 0xb,2 btfss 0xb,2 goto $-1 call _dec16 btfss 0x3,2 goto _pause return _add16a: movf 0x72,0 addwf 0x70,1 movf 0x73,0 btfsc 0x3,0 incf 0x73,0 addwf 0x71,1 return END ; end of code generation