Projects

Atmega8535
iBot
Light_controller
    preAmpli


    Source code

    /*************************************************
    * Description     : UART Test
    * Last update     : 19 november 2005
    * Crystal     : 8 or 16 MHz
    * Email     : geoffroy.lumay@ulg.ac.be
    * OK for avr-libc 1.2 ! (not tested)
    *************************************************/


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

    #define CRYSTAL      16000000                          // Clock frequency
    //#define CRYSTAL      8000000                          // Clock frequency
    #define BAUD          19200                          // baud rate
    #define BAUD_RATE_UBRR (CRYSTAL / (BAUD * 16l) - 1)

    void init(void){
    }

    //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;
    }

    // init uart : emit, receive, receive interrupt
    void init_uart_rx_rxcie_tx(void){
         UBRR=BAUD_RATE_UBRR;
         UCR=(1 << RXEN) | (1 << RXCIE) | (1 << TXEN);
    }

    // emit data
    void uart_emit_char(unsigned char ucar){
         loop_until_bit_is_set(USR, UDRE);
         UDR=ucar;
    }

    // emit "carriage return" + "line feed"
    void uart_emit_crlf(void){
         loop_until_bit_is_set(USR, UDRE);
         UDR=0x0D;
         loop_until_bit_is_set(USR, UDRE);
         UDR=0x0A;
    }

    // emit string
    void uart_emit_str(unsigned char *ubuf, unsigned char usize){
         unsigned char i;
         for (i = 0; i < usize; i++){
              loop_until_bit_is_set(USR, UDRE);
              UDR=ubuf[i];
    }
    }

    int main (void){
         init();
         sei();
         init_uart_rx_rxcie_tx();
         unsigned char i;
         while(1){
              uart_emit_str("Hello",15);
              for(i=0;i<50;i++) //Wait 500 ms
                   delay_10ms();
         }
    }

    SIGNAL(SIG_UART_RECV){ //UART receive interrupt
         unsigned char recVal;
         recVal = UDR;
         uart_emit_str("you have sended :",17);
         uart_emit_char(recVal);
    }

    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