Rabu, 02 Mei 2012

LED light using Code Vision AVR

This post I will provide a tutorial for ATMega 16 microcontroller based LED lights , using the software CodeVision AVR compiler.

First we create a simulation in proteus, as shown below :


LED lights, I connect with port C0-C7 on ATmega16 microcontroller.
The steps are :

1. Run the program CodeVision AVR.
2. Select the menu File>>New, and select the project option, OK.

3. After that will appear as shown below, select Yes.






4.AVR chip options will appear, as it uses ATmega16 then select the option AT90, ATtiny, ATmega, FPSLIC, and select OK.

5.Tab on the chip Chip,select chip ATmega16, and Clock 12 MHz.



6. Select Ports menu and setting the port to be used. Because this LED I plug it into Port C, and of course as a means of output, then change the setting of Port C In to Out.

7. Then select the File menu>> Generate, Save and Exit
8. After emerging area code, do not forget to add the syntax #include <delay.h>
9. To turn on 8 LED simultaneously and turns off after 1 second, type the following syntax:
while (1)
      {
      // 8 LED light code to blink
      PORTC=0xFF;
      delay_ms(1000);
      PORTC=0x00;
      delay_ms(1000);
      }
}
  select Project menu>>Buid All
  10. Then, enter the program to ATmega16 in proteus. After the run will look like this:


  Other syntax example, if we want LED1 on, LED2 off, LED3 on, dst.. 

while (1)
      {
      PORTC=0b01010101;
      delay_ms(1000);
      PORTC=0b10101010;
      delay_ms(1000);
      }
}
It will appear as below
 

Syntax Shift right led

while (1)
      {
      //
      PORTC=1;
      delay_ms(100);
      PORTC=3;
      delay_ms(100);
      PORTC=7;
      delay_ms(100);
      PORTC=15;
      delay_ms(100);
      PORTC=31;
      delay_ms(100);
      PORTC=63;
      delay_ms(100);
      PORTC=127;
      delay_ms(100);
      PORTC=255;
      delay_ms(100);
      }
}
It will appear as below

Tidak ada komentar:

Posting Komentar