; eBASIC PIC16 Code Generator ; Copyright(c) 2004, Compubotics LLC ; www.Compubotics.com ORG 0x2100 DE 0x41 DE 0x42 DE 0x43 DE 0x44 DE 0x45 DE 0x46 DE 0x47 DE 0x48 DE 0x49 DE 0x4a ORG 0x0 ; File: eeprom.bas ; ' EEPROM Data Manipulation ; ' eBASIC Compiler Examples ; ' ; ' Compubotics ; ' ; ; #device "16f877" ; #clock 16000000 ; #romsize 8192 ; ; ' store some static data in EEPROM ; data @0,$41,$42,$43,$44,$45,$46,$47,$48,$49,$4a ; ; c var byte ; d var word ; ; main: nop clrf 0xa goto _startup ORG 0x4 retfie _STR001: retlw 0x53 retlw 0x74 retlw 0x61 retlw 0x74 retlw 0x69 retlw 0x63 retlw 0x20 retlw 0x64 retlw 0x61 retlw 0x74 retlw 0x61 retlw 0x3a retlw 0x0 _STR002: retlw 0x20 retlw 0x0 _STR003: retlw 0x20 retlw 0x43 retlw 0x6f retlw 0x6d retlw 0x70 retlw 0x6c retlw 0x65 retlw 0x74 retlw 0x65 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 ; ; Debug cr, "Static data:" main: movlw 0xd call _uartTX movlw 0xa call _uartTX movlw 0x5 movwf 0x70 movlw 0x0 movwf 0x71 call _dbgStr ; ; ' read the "static" EEPROM data ; for c = 0 to 9 movlw 0x0 movwf 0x70 movlw 0x0 movwf 0x71 _j000: bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x20 ; read c, d movf 0x20,0 movwf 0x70 clrf 0x71 call _readData bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x21 movf 0x71,0 movwf 0x22 ; debug d movf 0x21,0 movwf 0x70 movf 0x22,0 movwf 0x71 call _dbgChar ; next _j002: movlw 0x9 movwf 0x70 movlw 0x0 movwf 0x71 movf 0x70,0 call _push movf 0x71,0 call _push bcf 0x3,5 bcf 0x3,6 movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0x1 movwf 0x72 movlw 0x0 movwf 0x73 call _add16a call _pop movwf 0x73 call _pop movwf 0x72 call _comp16 btfsc 0x3,2 goto _j000 btfsc 0x3,0 goto _j001 goto _j000 bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x20 ; ; debug " ",cr _j001: movlw 0x12 movwf 0x70 movlw 0x0 movwf 0x71 call _dbgStr movlw 0xd call _uartTX movlw 0xa call _uartTX ; ; mainloop: ; ; ' write some new EEPROM data ; for c = 0 to 20 mainloop: movlw 0x0 movwf 0x70 movlw 0x0 movwf 0x71 _j003: bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x20 ; ; write c, (c + $30) movf 0x20,0 movwf 0x70 clrf 0x71 movf 0x70,0 movwf 0x70 movf 0x71,0 movwf 0x71 movf 0x70,0 call _push movf 0x71,0 call _push movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0x30 movwf 0x72 movlw 0x0 movwf 0x73 call _add16a call _writeData ; ; next _j005: movlw 0x14 movwf 0x70 movlw 0x0 movwf 0x71 movf 0x70,0 call _push movf 0x71,0 call _push bcf 0x3,5 bcf 0x3,6 movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0x1 movwf 0x72 movlw 0x0 movwf 0x73 call _add16a call _pop movwf 0x73 call _pop movwf 0x72 call _comp16 btfsc 0x3,2 goto _j003 btfsc 0x3,0 goto _j004 goto _j003 bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x20 ; ; ' read the EEPROM data back again ; for c = 0 to 20 _j004: movlw 0x0 movwf 0x70 movlw 0x0 movwf 0x71 _j006: movf 0x70,0 movwf 0x20 ; ; read c, d movf 0x20,0 movwf 0x70 clrf 0x71 call _readData bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x21 movf 0x71,0 movwf 0x22 ; debug d movf 0x21,0 movwf 0x70 movf 0x22,0 movwf 0x71 call _dbgChar ; ; next _j008: movlw 0x14 movwf 0x70 movlw 0x0 movwf 0x71 movf 0x70,0 call _push movf 0x71,0 call _push bcf 0x3,5 bcf 0x3,6 movf 0x20,0 movwf 0x70 clrf 0x71 movlw 0x1 movwf 0x72 movlw 0x0 movwf 0x73 call _add16a call _pop movwf 0x73 call _pop movwf 0x72 call _comp16 btfsc 0x3,2 goto _j006 btfsc 0x3,0 goto _j007 goto _j006 bcf 0x3,5 bcf 0x3,6 movf 0x70,0 movwf 0x20 ; ; debug " Complete", CR _j007: movlw 0x14 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 ; ; goto mainloop goto mainloop _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 _j009 iorlw 0x0 btfsc 0x3,2 return call _uartTX call _inc16 goto _dbgStr _j009: movf 0x71,0 movwf 0xa movf 0x70,0 movwf 0x2 _readData: bcf 0x3,5 bsf 0x3,6 movf 0x70,0 movwf 0x10d bsf 0x3,5 clrf 0x18c bsf 0x18c,0 btfsc 0x18c,0 goto $-1 bcf 0x3,5 movf 0x10c,0 movwf 0x70 return _dbgChar: movf 0x70,0 call _uartTX return _push: bcf 0xb,7 movwf 0x79 movf 0x78,0 movwf 0x4 movf 0x79,0 movwf 0x0 incf 0x78,1 bsf 0xb,7 return _add16a: movf 0x72,0 addwf 0x70,1 movf 0x73,0 btfsc 0x3,0 incf 0x73,0 addwf 0x71,1 return _pop: bcf 0xb,7 decf 0x78,1 movf 0x78,0 movwf 0x4 movf 0x0,0 bsf 0xb,7 return _comp16: movf 0x73,0 subwf 0x71,0 btfss 0x3,2 return movf 0x72,0 subwf 0x70,0 return _writeData: bsf 0x3,5 bsf 0x3,6 btfsc 0x18c,1 goto $-1 bcf 0x3,5 call _pop call _pop movwf 0x10d movf 0x70,0 movwf 0x10c bsf 0x3,5 bcf 0x18c,7 bsf 0x18c,2 movlw 0x55 movwf 0x18d movlw 0xaa movwf 0x18d bsf 0x18c,1 btfsc 0x18c,1 goto $-1 bcf 0x18c,2 return _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 END ; end of code generation