Projects

Atmega8535
iBot
Light_controller
    preAmpli


    Connections

    Source code

    /*************************************************
    * Description     : Alphanumeric LCD Test
    * Last update     : 18 november 2005
    * Crystal     : 8 or 16 MHz
    * Email     : geoffroy@lumay.be
    * OK for avr-libc 1.2 ! (tested)
    *************************************************/


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

    #define CRYSTAL      16000000 // Clock frequency
                                             //#define CRYSTAL      8000000 // Clock frequency
    #define LCD_PORT      PORTC     // LCD data port
    #define     LCD_DI          0 // LCD Data/instruction selecting line
    #define     LCD_RW          1 // LCD read/write selecting line
    #define     LCD_E          2 // LCD enable line

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

    void init(void){
         DDRC=0xFF;      // set LCD_PORT as output
         LCD_PORT=0x00; // reset LCD_PORT
    }

    // 10 microsec delay
    void delay_10us(void){
         unsigned char test = 1;
         TCCR0=0x02;
         TCNT0=0xEB; //for 16 MHz
                        //TCNT0=0xF5; //for 8 MHz
         while (test){
              test = ~TIFR & 0x01;
    }
         TIFR=0x01;
    }

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

    // write an instruction on LCD
    void LCDwriteInstruction(unsigned char lcar){
         unsigned char temp;
         temp = lcar;
         lcar &= 0xF0;
         lcar |= 0x04;
         cbi(LCD_PORT, LCD_DI);
         LCD_PORT=lcar;               // write high bits
         cbi(LCD_PORT, LCD_E);
         sbi(LCD_PORT, LCD_E);
         lcar = temp;
         lcar <<= 4;
         lcar |= 0x04;
         LCD_PORT=lcar;               // write low bits
         cbi(LCD_PORT, LCD_E);
         sbi(LCD_PORT, LCD_E);
         delay_10ms();
         sbi(LCD_PORT, LCD_DI);
    }

    // write a char on LCD
    void LCDWriteChar(unsigned char lcar){
         unsigned char temp;
         temp = lcar;
         lcar &= 0xF0;
         lcar |= 0x05;
         sbi(LCD_PORT, LCD_DI);
         LCD_PORT=lcar;               // write high bits
         cbi(LCD_PORT, LCD_E);
         sbi(LCD_PORT, LCD_E);
         lcar = temp;
         lcar <<= 4;
         lcar |= 0x05;
         LCD_PORT=lcar;               // write low bits
         cbi(LCD_PORT, LCD_E);
         sbi(LCD_PORT, LCD_E);
         delay_10us(); delay_10us(); delay_10us(); delay_10us();
         cbi(LCD_PORT, LCD_DI);
    }

    // write a string on LCD
    void lcd_string(unsigned char *buf, unsigned char size){
         unsigned char i;
         for (i = 0; i < size; i++){
              LCDWriteChar(buf[i]);
    }
    }

    void lcd_addr(unsigned char lcar){
         lcar |= 0x80;
         LCDwriteInstruction(lcar);
    }

    //initialize the LCD
    void lcd_init(void) {
         LCDwriteInstruction(0x33);
         LCDwriteInstruction(0x32);
         LCDwriteInstruction(0x28);
         LCDwriteInstruction(0x28);
         LCDwriteInstruction(0x0C);
         LCDwriteInstruction(0x06);
         LCDwriteInstruction(0x01);
    }

    int main (void){
         init();
         lcd_init();
         lcd_string("*** HELLO WORLD! ***", 20);
         lcd_addr(0x40);
         lcd_string("powered by GL      ", 20);
         while (1){
         }
    }

    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