What next? search instructables to see if I can burn bootloader to ths chips. Unluckily not working. An error message "avrdude: stk500_getsync(): not in sync: resp=0x00 avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51" shown.
There is a way to solder some pins on Arduino Diecimila to solve the problem but that Arduino is the only one I have so I don't want to change my working board.
Step 1: Open Sketch ArduinoISP and Setup Wires
Connect as captured. First column refers to Arduino Diecimila, second column refers to pin of Atmega328p
Pin 10 -> pin 1 (this is very important for my case, without it the IDE prompted error then failed to burn)
Pins 13, 12, 11 -> pins 19, 18, 17
Pins 10 -> pin 1
Vcc -> pins 7, 20
Gnd -> pins 8, 22
And connecting crystall and capacitors to Atmega328p
Crystal 16Mhz -> pins 9, 10
Capacitor 22pf -> pins 8,9
Capactior 22pf -> pins 8, 10
Now hardward parts set. Then plug the Arudino Diecimila to your computer and following the steps next.
Step 2: Upload ArduionISP Program and Start Burnning Bootloader
First upload program to set my Diecimila as ArduioISP
1. select Tools -> Board -> Arduion Diecimila or Duemilanove w/ ATmega168
2. select Tools -> Programmer -> AVR ISP
3. compile then upload the ArduinoISP sketch. You should see "Done upload"
4. now select Tools-> Board -> Arduino UNO
5. select Tools -> Progammer -> Arduino as ISP
6. click Burn Bootloader. In a minute you should see "Done burning bootloader"
If you are lucky, you easily reach step 6 in one minute. To burn a second Atmega328p, unplug usb cable, swap a new one in your breadboard then plug in usb cable and run step 6 again.
If any error found, check the wirings then follow the steps one by one again.
Step 3: Testing the Bootloaded Atmega328p
1. load the Blink program. Change the LED turn on and off duration so you know this is your unique program when running in atmega328p after upload
2. from Arduino IDE, select Tools -> Board -> Arduino UNO
3. select Tools ->Programmer -> AVR ISP
4. plug in a LED to Gnd and pin 13 of your Arduino
5. swap Atemega168 with Atmega328p. Careful when you unplug the chip. More gentle less chance of damaging the chip. I used two needles to help unplug the chip :)
6. plug the Arduino back to your computer. make sure you hear a beep that computer confirm recognize you board
8. upload. Then you should see LED blink in the way you set in step 1.
If not working, check from step 2 and follow exactly to try again.
To test another Atmega328p, repeat step 5 to 8.
That is all. Enjoy it.