Problem with uploading sketches

Hello,

i have a microcontroller board with a atmega168 on it.
To prgramm it flashes the bootloader over isp and now want to use it with arduino.
The problem is that when i write a programm to the board, the first time it works. the second time i get this error:

avrdude: stk500_getsync(): not in sync: resp=0x7e

where the hexnumber in the end changes from time to time.
To flash a new programm i now always have to first flash the bootloader again, and then upload the programm from arduino again.

in my boards.txt i added the board

##############################################################

emcreprap.name=EMC2RepRap

emcreprap.upload.protocol=arduino
emcreprap.upload.maximum_size=14336
emcreprap.upload.speed=19200

emcreprap.bootloader.low_fuses=0xff
emcreprap.bootloader.high_fuses=0xdd
emcreprap.bootloader.extended_fuses=0x00
emcreprap.bootloader.path=atmega
emcreprap.bootloader.file=ATmegaBOOT_168_ng.hex
emcreprap.bootloader.unlock_bits=0x3F
emcreprap.bootloader.lock_bits=0x0F

emcreprap.build.mcu=atmega168
emcreprap.build.f_cpu=16000000L
emcreprap.build.core=arduino

and i flashed the ATmega_168_ng bootloader using avrdude (from the arduino ide my programmer wont work correctly)

so any ideas why it only works once everytime. looks to me like the boatloader somehow overwrites parts of itself ??

Are you changing the lock-bits before and after uploading the bootloader?

Have you ensured the fuses are set correctly?

where should i change the lockbits?
the fuse bit should be ok, didnt change here anything,

the fuse bit should be ok, didnt change here anything,

How did you come into possession of the processor? Did you purchase it new?

where should i change the lockbits?

Using AVRDUDE, before uploading the bootloader, you "unlock" the processor. Using AVRDUDE, after uploading the bootloader, you "lock" the processor.

I do not know the details. I suspect you can find the details by searching the forum.

i bought the chip from digikey and etched a little board which has some FETs, some pots and a max232 for the serial connection.
I did this before may times. normaly i just programmed the controller in c compiled it with avrgcc and flashed it with avrdude.
now i want to try the arduino ide because it is a nice thing to have a ide where the editor the compiler and the programmer are all in one.

(deleted)

My guess is that your board does not implement auto-reset. You have to hold down the reset, click on the upload button in the IDE, and release the reset when you see the "Binary sketch size:" message in the IDE.