Bluetooth Robot-3

ডিসেম্বর 18, 2014 § মন্তব্য দিন

The final physical looking of the Blueooth robot.

DSC02007DSC02006

This thing looks like a toy, isn’t it? Well, this(robot chassis/mechanism) is taken from two toy cars. Then the extra portion are cut off and glued together and then formed like a chassis. I will post images later. This is done to save some cash and waste more time in thinking and making a chassis on own hand.

DSC02005DSC02004

Due to the reason that i am not capable of spending a lot of money to my projects i have made this myself. The commercially available chassis are of too much costly for me.

DSC02002DSC02001

Though the has 4 wheels, it has no conventional steering. How would it take a turn? The answer is simple. The chassis work in the same basic principle like a tank. When wheels of both side moves on same speed, the car goes straight. When either of the side wheels are slowed down/stopped, it will take turn in that side. It can also take turn on its own position by moving the side wheels in opposite direction.

You see, I have added two optical reflection sensor on both front and back side to avoid collision.  when the car is about to collide a wall in front/back of it, it stops and moves to opposite direction to avoid collision. It can sense approx.1-2 cm distance depends on the wall/obstacle color. I will upload the code with the two sensors and explain about the codes later.

 

Batch script to prepare Windows 7 Bootable Pendrive.

ডিসেম্বর 18, 2014 § মন্তব্য দিন

Its easy to prepare Windows 7 Bootable Pendrive if you know some commands. However, you will forget the commands and their sequence easily when you need to setup windows next time later. To overcome this problem i created a script for myself. I think it will be useful to you also.

Write the following commands to a text file and save it with .bat extension e.g PreparePendrive.bat and then right click on it and click Run as Administrator. But Beware:

  1. Keep a backup of the contents of your pendrive because it will be formatted.
  2. You have one hard disk in your computer and one pendrive. there is no other drive plugged in.

And then copy all the contents of the Windows 7 Bootable DVD to the pendrive. And Its ready to boot..

del DskPrtCmd.txt
REM ECHO DISKPART > DskPrtCmd.txt
ECHO LIST DISK >> DskPrtCmd.txt
ECHO SELECT DISK 1 >> DskPrtCmd.txt
ECHO CLEAN >> DskPrtCmd.txt
ECHO CREATE PARTITION PRIMARY >> DskPrtCmd.txt
ECHO SELECT PARTITION 1 >> DskPrtCmd.txt
ECHO ACTIVE >> DskPrtCmd.txt
ECHO FORMAT FS=NTFS QUICK >> DskPrtCmd.txt
ECHO ASSIGN >> DskPrtCmd.txt
ECHO EXIT >> DskPrtCmd.txt

diskpart /s DskPrtCmd.txt
del DskPrtCmd.txt
pause

Or if you are too lazy, download it from here: https://github.com/khairulhasanmd/Prepare-Win7-Bootable-Pendrive

Bluetooth Robot-2

ফেব্রুয়ারি 16, 2014 § 2 টি মন্তব্য

I will discuss the circuit diagram and mechanical description of the bluetooth robot now.

Here is the previous post that contains the program.

Actually, It’s not a robot. It’s some kind of remote controlled car that can be controlled over bluetooth from a laptop or PC.

The power of the microcontrollers are too low compared to the modern laptop or desktop. There is no huge computing power, no scope for image processing, no scope for huge amount of data logging, no scope for multitasking(Although there is some multitasking OS available for microcontrollers, They are complex, Time consuming, Requires a lot processing power to achieve multitasking.) and other limitations.

So, My concept was Why not build a slave device that is controlled from a central server that has huge processing power.

You can say that why not build such big robot that can carry a whole laptop inside it? Then the answer maybe The CPU requires a lot more power, Adds an extra weight to carry, has restrictions for harsh/rough environments and more…

OK, Enough now i will come to the main point.

The robot chasis is like normal tank principle. It has two treads attached with two geared motors. When both motors move forward, the chasis will go forward, opposite applies for backward movement, and when one motor is running and the other one is stopped, it will take a turn. I will add detailed images about the robot chasis later.

Now, about the circuit..

BT-robo

The heart of the circuit is the atmega8 microcontroller, which gets commands from the hc-06 bluetooth module and drives a l293d motor controller Which controls the speed and direction of the motor. The speed of the motor is controlled by pwm dc motor speed control method. You can get brief of it into the codes.

Oh.. Sorry

A correction. I have drawn this circuit with fritzing. The HC-06 bluetooth module i can’t found in fritzing but used here RN-41 module. The connection is same for HC-06.

Bluetooth Robot

জানুয়ারি 6, 2014 § ১ টি মন্তব্য

I am testing around a bluetooth module. And this is the result of the test.

I have recently bought a HC-06 bluetooth module, and after couple of hours of searching in the internet, I’ve figured out how to use the module. Detailed info and source here.

hc06-top-side

The module runs on 3.3v-5v, default pairing code 1234 and baudrate is 9600, N, 8,1. For only communication purposes, you don’t need to mess about the AT commands(it is in the online also).

hc-06-and-hc-05-source-wavesen-data-sheet

If you want to test the module if it works or not, i have a way, Download PUTTY here, you need another USB>Serial converter(I’ve used PL2303) and a bread board. Then connect TXD(pl-2303)>>RXD(HC-06), RXD(pl-2303)>>TXD(HC-06),  GND(pl-2303)>>GND(HC-06),  VCC 3.3v(pl-2303)>>VCC(HC-06).

jy-mcu-bt_board-v1-05-bottom-side

Run Putty,  from connection type radio button, select serial,  From Serial line, Edit that to com6(in my case), click open. This will open the desired bluetooth com port.  Run putty again, from connection type radio button, select serial,  From Serial line, Edit that to com8(in my case), click open. This will open serial port of pl-2303. And you can transmit and receive your keystrokes.

Here is a slight little problem. You need to know which com port of your pc is used for communicating with which device. Is it a real problem? No. Just right click Computer>manage>device manager>ports (Com & LPT). And here will show the ports. You can identify the pl2303 port because of it named as prolific or similar. And another confusion is which port is used for bluetooth device? The answer is after pairing with HC-06 you need to try each port one by one in putty. And whenever a successful connection is made. The LED of the HC-06 will stop blinking and it will stay on always.

Ok, Enough .. Here comes the code for arduino(atmega8). Will work on other 168/328 too.

int incomingByte;      // a variable to read incoming serial data into
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(11,INPUT);
  pinMode(12,INPUT);
  pinMode(13,INPUT);
  pinMode(14,INPUT);
  pinMode(15,INPUT);
  pinMode(16,INPUT);
  pinMode(17,INPUT);
  pinMode(18,INPUT);
    analogWrite(9,80);
    analogWrite(10,80);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'w') {
      GoForward();
    }
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 's') {
      GoBackward();
    }
    if (incomingByte == 'a') {
      TurnLeft();
    }
    if (incomingByte == 'd') {
      TurnRight();
    }
    if (incomingByte == 'i') {
      analogWrite(9,80);
      analogWrite(10,80);
    }
    if (incomingByte == 'u') {
      analogWrite(9,100);
      analogWrite(10,100);
    }
    if (incomingByte == 'y') {
      analogWrite(9,120);
      analogWrite(10,120);
    }
    if (incomingByte == 't') {
      analogWrite(9,140);
      analogWrite(10,140);
    }
    if (incomingByte == 'r') {
      analogWrite(9,180);
      analogWrite(10,180);
    }
    if (incomingByte == 'o') {
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    }
  }
}

void GoForward()
{
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, HIGH);
}

void GoBackward()
{
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
}

void TurnRight()
{
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, HIGH);
}

void TurnLeft()
{
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}

void HardLeft()
{
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, HIGH);
}

void HardRight()
{
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
}

Most of the functions are self-explaining. And some of them are unused and for later uses. This hardware was made for one of my previous PID Line follower project and that’s another story :D .

The Hardware/Circuit diagram?
You need to wait until my next free time….

Camera Hack

ডিসেম্বর 18, 2013 § মন্তব্য দিন

I have got a couple of webcams, those seems useless to me.

Sometimes i dream to have a binocular which can do video recording and zoom further away just like the spy movies ha ha. So this story is an attempt to make such thing. Not actually the camera in the spy movies, somewhat close to that what i want to build.

So that is the idea, and i started with a couple of magnifying glasses and arranged in series in a line through my window, and started projecting the objects that i can see through my window on a white sheet of paper.

Most of the camera’s uses the same technology to project an image on a slide of film or on a CCD/CMOS camera sensor.

Then I’ve bought a webcam, disassembled it opened the lens and put my magnifying glass on the CMOS sensor and started playing with that level of zoom :D . It gave me an awesome result but also have caused some problem.

The magnifying glass combination was not perfect for me cause i can’t customize their magnifying factor/customized magnifying glasses are not available in the local market, the distance of the glass and sensor can not be controllable via electronics(though controllable by hand)/it is hard to make such hardware for me and it is not compact. So, i have searched for a long time to find commercially available zoom lenses/lense used in SLR camera.

But, those are too pricey for me to use in a project. I kept on searching.

One day my digital camera has some problem and repaired it in local camera repairing store. I asked them would they have any damaged/faulty camera and if they want to sell it. They answered no. it was quite hard for me to hear that answer. They told me that sometimes the old camera parts is very useful for them to repair a new one.

I had a scope. I asked them that if there was any such old camera that’s parts cannot reusable then i am going to buy it. They asked me what i want to do with it. I answered about my project. and they gave me a lens of an old handycam.

I opened it, It has some lenses, two stepper motors, and two sensors(i mean infrared limit switch).

I’ve put my webcam on the CCD slot of the lens unit. For this, i had to cut down my webcam motherboard a little bit. If you are going to do this project then you must understand what parts of your webcam motherboard is safest to cut down. Then i removed the two steppers and started playing with the lens unit.

It gave me awesome result. Maybe 20X zoom capability :D .

And i started to make a project in arduino to control the steppers by a computer.

It was another story, I will tell you later. Till then………..

Atmega32 usbasploader-3

ডিসেম্বর 15, 2013 § মন্তব্য দিন

Description about the hardware part:

DSC00629done

I’m sorry i can’t give you the exact circuit diagram because i have made this project before one year and that was a trial and error based project so no exact schematic had been made. After having success on this project, i was so excited that i had no time to draw a complete circuit diagram. But i will give you some clue and results. The main theory is just combine the usbasploader(here) hardware with my pinouts.

As written in the code,

#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 1
#define USB_CFG_DPLUS_BIT  2

That means the D+ pin is PD2
And the D- pin is PD1 of the Atmega32 microcontroller.

And the board is made on a double layer veroboard :D . Actually it is not a double layer veroboard. It is a bit made of two different slices of veroboard. And i have cut a big hole inside of the top layer to insert the crystal and other parts. I have cut it for my fun only, it’s not essential.  If you can put the crystal and other things on the reverse side of the top layer, then it will be perfect. I have mounted the whole microcontroller circuit on the top layer and added the essential parts to able to run it without the bottom layer.

DSC00617done DSC00619done

The bottom layer has the USB voltage driver/dropper circuit from vusb with a couple of zener diodes, some resistors, a USB-B mini port and some resistors. I mean the USB-B female port is very much essential here. We know that the 4th pin of the USB-B mini port is unused. And we also know that we need a jumper for usbasploader. So,I have disassembled the USB data cable and shorted the 4th pin with the 5th pin or easily saying that 4th pin to ground and the 4th pin of the female jack of the USB-B mini on the circuit board is connected with PD0 as says the following line of the configuration code.

#define JUMPER_BIT 0

So, whenever you inserted the cable, after pressing the reset button, the microcontroller automatically goes to programming mode. Isn’t the feature beautiful and essential? And after removing the cable, the microcontroller always goes to run mode.

DSC00626done DSC00627done DSC00631done DSC00625done DSC00624done

Atmega32 usbasploader-2

ডিসেম্বর 14, 2013 § ১ টি মন্তব্য

Now I will describe the bootloader software part.

I have faced and i know that almost everyone faces problem with the boot-loader. The boot-loader/hardware miss-configuration makes it impossible to work and falls us into frustration. It takes 3 months for me to have a success.

I have compiled these with WINAVR in windows xp/7 successfully.

Download the Winavr from sourceforge, install it. Download the usbasp package, unzip it.

Then you only need to make the following files. The files will be exactly look like-

1. bootloaderconfig.h

</pre>
/* Name: bootloaderconfig.h
 * Project: USBaspLoader
 * Author: Christian Starkjohann
 * Creation Date: 2007-12-08
 * Tabsize: 4
 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt)
 * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
 */

#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__

/*
General Description:
This file (together with some settings in Makefile) configures the boot loader
according to the hardware.

This file contains (besides the hardware configuration normally found in
usbconfig.h) two functions or macros: bootLoaderInit() and
bootLoaderCondition(). Whether you implement them as macros or as static
inline functions is up to you, decide based on code size and convenience.

bootLoaderInit() is called as one of the first actions after reset. It should
be a minimum initialization of the hardware so that the boot loader condition
can be read. This will usually consist of activating a pull-up resistor for an
external jumper which selects boot loader mode.

bootLoaderCondition() is called immediately after initialization and in each
main loop iteration. If it returns TRUE, the boot loader will be active. If it
returns FALSE, the boot loader jumps to address 0 (the loaded application)
immediately.

For compatibility with Thomas Fischl's avrusbboot, we also support the macro
names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
these macros are defined, the boot loader usees them.
*/

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME D
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT 2
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

/* ----------------------- Optional Hardware Config ------------------------ */

/* #define USB_CFG_PULLUP_IOPORTNAME D */
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
 * V+, you can connect and disconnect the device from firmware by calling
 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
 * This constant defines the port on which the pullup resistor is connected.
 */
/* #define USB_CFG_PULLUP_BIT 4 */
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
 * above) where the 1.5k pullup resistor is connected. See description
 * above for details.
 */

/* ------------------------------------------------------------------------- */
/* ---------------------- feature / code size options ---------------------- */
/* ------------------------------------------------------------------------- */

#define HAVE_EEPROM_PAGED_ACCESS 1
/* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
 * compiled in. Whether page mode or byte mode access is used by AVRDUDE
 * depends on the target device. Page mode is only used if the device supports
 * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
 * disabling page mode EEPROM access. Costs ~ 138 bytes.
 */
#define HAVE_EEPROM_BYTE_ACCESS 1
/* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
 * compiled in. Byte mode is only used if the device (as identified by its
 * signature) does not support page mode for EEPROM. It is required for
 * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
 */
#define BOOTLOADER_CAN_EXIT 1
/* If this macro is defined to 1, the boot loader will exit shortly after the
 * programmer closes the connection to the device. Costs ~36 bytes.
 */
#define HAVE_CHIP_ERASE 0
/* If this macro is defined to 1, the boot loader implements the Chip Erase
 * ISP command. Otherwise pages are erased on demand before they are written.
 */
//#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
/* This macro defines the signature bytes returned by the emulated USBasp to
 * the programmer software. They should match the actual device at least in
 * memory size and features. If you don't define this, values for ATMega8,
 * ATMega88, ATMega168 and ATMega328 are guessed correctly.
 */

/* The following block guesses feature options so that the resulting code
 * should fit into 2k bytes boot block with the given device and clock rate.
 * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
 * This requires gcc 3.4.6 for small enough code size!
 */
#if USE_AUTOCONFIG
# undef HAVE_EEPROM_PAGED_ACCESS
# define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
# undef HAVE_EEPROM_BYTE_ACCESS
# define HAVE_EEPROM_BYTE_ACCESS 1
# undef BOOTLOADER_CAN_EXIT
# define BOOTLOADER_CAN_EXIT 1
# undef SIGNATURE_BYTES
#endif /* USE_AUTOCONFIG */

/* ------------------------------------------------------------------------- */

/* Example configuration: Port D bit 3 is connected to a jumper which ties
 * this pin to GND if the boot loader is requested. Initialization allows
 * several clock cycles for the input voltage to stabilize before
 * bootLoaderCondition() samples the value.
 * We use a function for bootLoaderInit() for convenience and a macro for
 * bootLoaderCondition() for efficiency.
 */

#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */

#define JUMPER_BIT 0 /* jumper is connected to this bit in port D, active low */

#ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
# define MCUCSR MCUSR
#endif

static inline void bootLoaderInit(void)
{
 PORTD |= (1 << JUMPER_BIT); /* activate pull-up */
 if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
 leaveBootloader();
 MCUCSR = 0; /* clear all reset flags for next time */
}

static inline void bootLoaderExit(void)
{
 PORTD = 0; /* undo bootLoaderInit() changes */
}

#define bootLoaderCondition() ((PIND & (1 << JUMPER_BIT)) == 0)

#endif /* __ASSEMBLER__ */

/* ------------------------------------------------------------------------- */

#endif /* __bootloader_h_included__ */
<pre>

2. Makefile

</pre>
/* Name: bootloaderconfig.h
 * Project: USBaspLoader
 * Author: Christian Starkjohann
 * Creation Date: 2007-12-08
 * Tabsize: 4
 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt)
 * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
 */

#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__

/*
General Description:
This file (together with some settings in Makefile) configures the boot loader
according to the hardware.

This file contains (besides the hardware configuration normally found in
usbconfig.h) two functions or macros: bootLoaderInit() and
bootLoaderCondition(). Whether you implement them as macros or as static
inline functions is up to you, decide based on code size and convenience.

bootLoaderInit() is called as one of the first actions after reset. It should
be a minimum initialization of the hardware so that the boot loader condition
can be read. This will usually consist of activating a pull-up resistor for an
external jumper which selects boot loader mode.

bootLoaderCondition() is called immediately after initialization and in each
main loop iteration. If it returns TRUE, the boot loader will be active. If it
returns FALSE, the boot loader jumps to address 0 (the loaded application)
immediately.

For compatibility with Thomas Fischl's avrusbboot, we also support the macro
names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
these macros are defined, the boot loader usees them.
*/

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME D
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT 2
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

/* ----------------------- Optional Hardware Config ------------------------ */

/* #define USB_CFG_PULLUP_IOPORTNAME D */
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
 * V+, you can connect and disconnect the device from firmware by calling
 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
 * This constant defines the port on which the pullup resistor is connected.
 */
/* #define USB_CFG_PULLUP_BIT 4 */
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
 * above) where the 1.5k pullup resistor is connected. See description
 * above for details.
 */

/* ------------------------------------------------------------------------- */
/* ---------------------- feature / code size options ---------------------- */
/* ------------------------------------------------------------------------- */

#define HAVE_EEPROM_PAGED_ACCESS 1
/* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
 * compiled in. Whether page mode or byte mode access is used by AVRDUDE
 * depends on the target device. Page mode is only used if the device supports
 * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
 * disabling page mode EEPROM access. Costs ~ 138 bytes.
 */
#define HAVE_EEPROM_BYTE_ACCESS 1
/* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
 * compiled in. Byte mode is only used if the device (as identified by its
 * signature) does not support page mode for EEPROM. It is required for
 * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
 */
#define BOOTLOADER_CAN_EXIT 1
/* If this macro is defined to 1, the boot loader will exit shortly after the
 * programmer closes the connection to the device. Costs ~36 bytes.
 */
#define HAVE_CHIP_ERASE 0
/* If this macro is defined to 1, the boot loader implements the Chip Erase
 * ISP command. Otherwise pages are erased on demand before they are written.
 */
//#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
/* This macro defines the signature bytes returned by the emulated USBasp to
 * the programmer software. They should match the actual device at least in
 * memory size and features. If you don't define this, values for ATMega8,
 * ATMega88, ATMega168 and ATMega328 are guessed correctly.
 */

/* The following block guesses feature options so that the resulting code
 * should fit into 2k bytes boot block with the given device and clock rate.
 * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
 * This requires gcc 3.4.6 for small enough code size!
 */
#if USE_AUTOCONFIG
# undef HAVE_EEPROM_PAGED_ACCESS
# define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
# undef HAVE_EEPROM_BYTE_ACCESS
# define HAVE_EEPROM_BYTE_ACCESS 1
# undef BOOTLOADER_CAN_EXIT
# define BOOTLOADER_CAN_EXIT 1
# undef SIGNATURE_BYTES
#endif /* USE_AUTOCONFIG */

/* ------------------------------------------------------------------------- */

/* Example configuration: Port D bit 3 is connected to a jumper which ties
 * this pin to GND if the boot loader is requested. Initialization allows
 * several clock cycles for the input voltage to stabilize before
 * bootLoaderCondition() samples the value.
 * We use a function for bootLoaderInit() for convenience and a macro for
 * bootLoaderCondition() for efficiency.
 */

#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */

#define JUMPER_BIT 0 /* jumper is connected to this bit in port D, active low */

#ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
# define MCUCSR MCUSR
#endif

static inline void bootLoaderInit(void)
{
 PORTD |= (1 << JUMPER_BIT); /* activate pull-up */
 if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
 leaveBootloader();
 MCUCSR = 0; /* clear all reset flags for next time */
}

static inline void bootLoaderExit(void)
{
 PORTD = 0; /* undo bootLoaderInit() changes */
}

#define bootLoaderCondition() ((PIND & (1 << JUMPER_BIT)) == 0)

#endif /* __ASSEMBLER__ */

/* ------------------------------------------------------------------------- */

#endif /* __bootloader_h_included__ */
<pre>

Then run command prompt, cd to the folder where you unzipped, then type the commands and press enter.
1. To Compile And Upload To Microcontroller-
make flash
2. To Set Fusebits
make fuse
3. To Set Lockbits.
make lock
Issue these commands and enjoy. I will come later with the circuit diagram. But it’s already written in the codes. :D

Ok, And for better help(also less explaining for me :p ) I uploaded complete package zipped, Click here to download it. The .bat scripts helps to avoid the damn command prompt.  You can play with them but be careful(they can blow your PC off :p ).

Follow

Get every new post delivered to your Inbox.

Join 276 other followers

%d bloggers like this: