On 05-Jan-12 21:00, Adam Walley wrote: > Here is the code I am using with the MPLAB IDE v8.33 > Sorry for any bad formatting. The code is very crude because I am still > testing and debugging (that is also why there is an eeprom write and the > flashing LEDs - these confirm that my code has run). > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ASM =3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > ;12F675 send 'K' byte to PC via RS232 (GPIO1) > ; as basic as possible to test correct code format > ; > > > #include > errorlevel -302 ; suppress message 302 from list file > > __CONFIG _CP_OFF& _WDT_OFF& _BODEN_OFF& _PWRTE_OFF& > _INTRC_OSC_NOCLKOUT& _MCLRE_ON& _CPD_OFF Your problem is _MCLRE_ON. This connects the internal reset circuitry to=20 external pin #4 which is floating. When you use battery power, your power supply is noise free and this=20 floating input stays at logic level 1 (which is pure luck). As soon as you connect the ground wire, your device starts to receive=20 more RF noise and this changes the MCLR logic level randomly and resets=20 the chip repeatedly. Use _MCLRE_OFF or connect your reset pin #4 to Vcc through a resistor. Djula > > ;***** Reset vector ************************************************* > org 0x00 > nop > goto init > > ;***** Assign Constants Value *************************************** > #define BANK1 banksel 0x80 ;Select Bank1 > #define BANK0 banksel 0x00 ;Select Bank0 > > CLOCK EQU 4000000 ; Set the clock as 4 MHz > > ;***** Assign variables ********************************* > > addr EQU 0x20 ; address for EEPROM access > dat EQU 0x21 ; value for EEPROM I/O > cnt EQU 0x22 ; counter > pins EQU 0x23 ; TRISIO pin status buffer > io_tmp EQU 0x24 ; GPIO status buffer > delay_temp EQU 0x25 ; Required for "delay.inc" > byte EQU 0x28 ; temporary byte buffer > > ;***** MAIN ********************************************* > init > clrf cnt > clrf dat > clrf addr > movlw b'00111001' ; GPIO 1,2 outputs > movwf pins ; store in pin buffer > BANK1 > movwf TRISIO ; set I/O pins > clrf ANSEL ; make all I/O ports digital > BANK0 > movlw 0x07 ; comparator OFF bits > movwf CMCON ; switch it off > bcf ADCON0,ADON ; switch off A/D converter > clrf io_tmp ; turn off i/o pins in buffer > clrf GPIO ; turn off i/o pins > movlw 0x05 ; LOOPS > movwf cnt ; init counter > movlw 0x50 ; initial address value > movwf addr ; set address > call ewrite ; write '00' to EEPROM for start > BANK0 > incf addr,1 ; add 1 to address > > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > call tx_hi ; set TX pin high to begin > > loop > call flash ; FLASH LED > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > > ; ------------------------------------------------ > ; send 'T' at 9600 baud > ; binary: 00101010 LSB->MSB > ; using a 4 MHz chip > ; 1 / 2400 baud =3D 416.6667 cycles per bit > ; 1 / 4800 baud =3D 208.3333 cycles per bit > ; 1 / 9600 baud =3D 104.1667 cycles per bit > > call tx_lo ; START bit [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_lo ; (0)0101010 [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_lo ; 0(0)101010 [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_hi ; 00(1)01010 [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_lo ; 001(0)1010 [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_hi ; 0010(1)010 [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_lo ; 00101(0)10 [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_hi ; 001010(1)0 [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_lo ; 0010101(0) [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > call tx_hi ; STOP bit [ 8] > call delay50 ; [ 58] > call delay20 ; [ 78] > call delay20 ; [ 98] > call delay6 ; [ 104] > > BANK0 ; switch back to Bank0 > decfsz cnt,1 ; dec cnt by 1 > goto loop ; cnt>0, keep looping > goto finish ; > > > ;***** TX on GPIO1 ************************** > tx_hi ; 8 cycles > BANK0 ; for GPIO > bsf io_tmp,1 ; GPIO1 pin ON > movfw io_tmp ; move io_tmp to W > movwf GPIO ; copy new state to GPIO port > return > > tx_lo ; 8 cycles > BANK0 ; for GPIO > bcf io_tmp,1 ; GPIO1 pin OFF > movfw io_tmp ; move io_tmp to W > movwf GPIO ; copy new state to GPIO port > return > > ;***** FLASH LED ************************** > flash > BANK0 ; for GPIO > bsf io_tmp,2 ; GPIO2 pin ON > movfw io_tmp ; move io_tmp to W > movwf GPIO ; copy new state to GPIO port > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > bcf io_tmp,2 ; GPIO2 pin OFF > movfw io_tmp ; update io_tmp > movwf GPIO ; copy new state to GPIO port > movlw 0xc8 ; 200 milliseconds > call delay_ms ; wait > return > > led_on > BANK0 ; for GPIO > bsf io_tmp,2 ; GPIO2 pin ON > movfw io_tmp ; move io_tmp to W > movwf GPIO ; copy new state to GPIO port > return > > led_off > BANK0 ; for GPIO > bcf io_tmp,2 ; GPIO2 pin OFF > movfw io_tmp ; move io_tmp to W > movwf GPIO ; copy new state to GPIO port > return > > ;***** FINISH ***************************** > finish > call tx_lo ; switch off TX pin > movlw 0x64 ; 100 milliseconds > call delay_ms ; wait > call led_on > movlw 0x32 ; 50 milliseconds > call delay_ms ; wait > call led_off > movlw 0x32 ; 50 milliseconds > call delay_ms ; wait > call led_on > movlw 0x32 ; 50 milliseconds > call delay_ms ; wait > call led_off > movlw 0x32 ; 50 milliseconds > call delay_ms ; wait > call flash > ; mark end in EEPROM with 'BB' > movlw 0xBB ; end marker > movwf dat ; prepare for EEPROM > call ewrite ; write to EEPROM > BANK0 > incf addr,1 ; add 1 to address > sleep > > ;***** Include routines ***************************** > include "delays.inc" > include "eeprom_write.inc" > > end > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ASM =3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .