Projects

Atmega8535
iBot
Light_controller
    preAmpli


    Connections

    Source code

    /*************************************************
    * Description     : PWM Test
    * Last update     : 13 november 2005
    * Crystal     : 8 or 16 MHz
    * Email     : geoffroy@lumaybe
    * OK for avr-libc 1.2 ! (tested)
    *************************************************/


    #include <avr/io.h>
    #include <avr/io8535.h>
    #include <avr/interrupt.h>

    #define CRYSTAL      16000000 // Clock frequency
                                             //#define CRYSTAL      8000000 // Clock frequency
    #define OCR1 OCR1AL

    //We redefine some deprecated functions
    #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
    #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

    //Global declarations
    unsigned char valPWM;

    void init(void){
         DDRD = 0xFF;
         TCCR1A = _BV(PWM10) | _BV(COM1A1);
         TCCR1B = _BV(CS10);
         OCR1=0x00;
    }

    //10 millisec delay
    void delay_10ms(void){
         unsigned char test = 1;
         TCCR0=0x05;
         TCNT0=0x63; //for 16 MHz
                        //TCNT0=0xB1; //for 8 MHz
         while (test){
              test = ~TIFR & 0x01;
    }
         TIFR=0x01;
    }

    int main (void){
         init();
         sei();
         while (1){
              for (valPWM = 0; valPWM < 256; valPWM++){
                   delay_10ms();
                   OCR1=valPWM;
              }
         }
    }

    MakeFile

    #Makefile writen by Geoffroy Lumay
    #Path for avr-gcc
    AVRPATH=/usr/local/atmel/bin
    MCU=at90s8535
    CC=$(AVRPATH)/avr-gcc
    OBJCOPY=$(AVRPATH)/avr-objcopy
    # optimization
    CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues
    #*****************************************************
    all: ProgAtmel.hex
    ProgAtmel.hex : ProgAtmel.out
    $(OBJCOPY) -R .eeprom -O ihex ProgAtmel.out ProgAtmel.hex
    ProgAtmel.out : ProgAtmel.o
    $(CC) $(CFLAGS) -o ProgAtmel.out -Wl,-Map,ProgAtmel.map ProgAtmel.o
    ProgAtmel.o : ProgAtmel.c
    $(CC) $(CFLAGS) -Os -c ProgAtmel.c
    #******************************************************
    load: ProgAtmel.hex
    # erase before loading the program.
    uisp -dlpt=/dev/parport0 --erase -dprog=dapa
    # load (program) the software into the eeprom:
    uisp -dlpt=/dev/parport0 --upload if=ProgAtmel.hex -dprog=dapa -v=3 --hash=32
    #*******************************************************
    clean:
    rm -f *.o *.map *.out
    #*******************************************************
    fuse:
    #fusing the atmega8535 for quartz
    uisp -dlpt=/dev/parport0 -dprog=dapa --wr_fuse_e=0xFF --wr_fuse_l=0xEF --wr_fuse_h=0xC9
    #********************************************************
    readfuse:
    #Read the fuse
    uisp -dlpt=/dev/parport0 -dprog=dapa --rd_fuses


    To compile the project, type make
    To load the hex file in the controler, type (as su) #make load
    To read the fuses, type (as su) #make readfuse
    To change the fuses of the Atmega8535, type (as su) #make fuse