Programming ATMega168 STK500 and hex file

Hi,

I'm trying to update a bunch of older devices that where programmed in basic. I've got access to the programming header and used an AVRISP MKII to program it with the old program.

Now I’m trying to write the new program in the Arduino and make a hex file for it.
Making just a switch relays every second program and sending it makes the relay buzzing instead of a 1 second delay and I cannot find the problem.
The atmega168 uses an external 16MHZ crystal on PB6 and PB7

In the IDE I use: MiniCore ATmega 168

Board ATmega168
Clock external 16MHZ
BOD: 2.7V
EEPROM not retained
LTO disabled
Variant 168P / 168PA
No bootloader

CTRL + ALT + S makes the hex file

and with "STK500.exe -cUSB -dATmega168 -if"test.HEX" -e -pf -vf i" I'm programming it . . . no errors

Just uploading the older hex (created with Bascom a long time ago) works.

Any tips about what I'm missing here to get the test relay program working

The test program
Making the delay 10000000 has no effect... still buzing.
Using an other port witch controls a led.. led seems to be on all the time

void setup() {
 pinMode(PIN_PB2, OUTPUT);
}
void loop() {
  digitalWrite(PIN_PB2, HIGH);  
  delay(1000);                       
  digitalWrite(PIN_PB2, LOW);    
  delay(1000);                      
}

Simplified / diagnosed it down a little.

I've made an Arduino UNO the ISP and using this in the arduino IDE to program.

I can upload the program by selecting variant 168 / 168A, but still buzzing sound on relay.

I cannot upload the bootloader to the mega168

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\arduino-1.8.13 - ATMega168\portable\packages\MiniCore\hardware\avr\2.0.9/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega168P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no        512    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     16384  128    128  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

Fout bij het branden van de bootloader.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9406 (probably m168)
avrdude: Expected signature for ATmega168P is 1E 94 0B
         Double check chip, or use -F to override this check.

It seems that the processor is wrong..? Peeling down the labels revealed the processor.
It says ATMEL MEGA 168 20 MU1006

Can this be used in combination with arduino ide?

The signature is different. It is 168, not 168P. The difference is in micro power feature, but has no impact to the bootloader. Exact MCU type must be used. However, it seems like 168P is set in the config - boards.txt.
You can try it from CMD, just use command from the log.