ÇнÀ¸ñÇ¥    1

ÇнÀÁÖÁ¦    1

¿¹½À³»¿ë    1

½Ç½À¹æ¹ý    1

°ú    Á¦    1

LED·Î ÀÚµ¿Â÷ ¼Óµµ¿Í ¹æÇâÇ¥½Ã

ÇнÀ¸ñÇ¥

4°³ÀÇ ³ì»ö LED·Î ÀÚµ¿Â÷ ¼Óµµ¿¡ µû¶ó Á¡¸ê¼Óµµ¸¦ Á¶ÀýÇϰí Àû»ö LED·Î ¹æÇâÀ» Ç¥½ÃÇÑ´Ù.

ÇнÀÁÖÁ¦

 

¿¹½À³»¿ë

 

½Ç½À¹æ¹ý

¸ñ    Â÷

¸®¸ðÄÜÀ¸·Î ¸ðÇü ÀÚµ¿Â÷Á¦¾î ºÎºÐ¿¡ 6°³ÀÇ  LED¸¦ Ãß°¡Çϰí À̸¦ ÇÁ·Î±×·¥¿¡ Ãß°¡ ÇÏ¿´´Ù.

 

º¸±â1  ¸ðÇüÀÚµ¿Â÷ÀÇ ¼Óµµ¿Í ȸÀü Ç¥½Ã

#include <mega128.h>

#include <delay.h> 

       

eeprom char vel;

char mode=0,m_cnt=0x01,iter=0;

 

void main(void)

{         

// A,Dä³Î=ÀÔ·Â

PORTA=0x00;

DDRA=0x00;

PORTD=0x00;

DDRD=0x00;

 

// B,Cä³Î=Ãâ·Â

PORTB=0x00;

DDRB=0xFF;

PORTC=0x00;

DDRC=0xFF;

PORTE=0x00;

DDRE=0xFF;

 

// Global enable interrupts

#asm("sei")

 

// (1) Fast PWM Mode   ATmega128(L) Data Book P100  ÁÖ±âÁ¶Àý

// 16M(ClkTOS)/1024=15625 Hz

TCCR0 = 0x6f;

// ATmega128(L) Data Book P102   µàƼºñÁ¶Àý  ÃʱâµàƼ=50    

OCR0 = vel; 

 

while (1)

      {

       if(PINA.0==1) {

          switch(PIND) {

                       case 0x00 :                          // ÀüÁø

                                      PORTC=0x06;

                                      mode=1;

                                      //m_cnt=0x01;

                                      break;

                       case 0x01 :                          // ÈÄÁø

                                      PORTC=0x09;

                                      mode=1;

                                      //m_cnt=0x01;

                                      break;

                       case 0x02 :                          // ¿ìȸÀü

                                      PORTC=0x0a;

                                      mode=2;

                                      break;

                       case 0x03 :                          // ÁÂȸÀü

                                      PORTC=0x05;

                                      mode=3;

                                      break;

                       case 0x44 :                          // Á¤Áö

                                      PORTC=0x00;

                                      mode=0;

                                      break;

                       case 0x04 :                          // ¼ÓµµÁõ°¡

                                      if(vel!=0xff)

                                                vel++;

                                                OCR0 = vel; 

                                                     break;

                                      case 0x05 :                          // ¼Óµµ°¨¼Ò

                                      if(vel!=0x00)

                                                vel--;

                                                OCR0 = vel; 

                                                     break;

          }

                       delay_ms(10);

            }

            

           // ¼Óµµ¿¡ µû¶ó  Led 4°³ÀÇ Á¡¸ê ¼Óµµ¸¦ ´Ù¸£°Ô Çϰí ÁÂȸÀü ¿ìȸÀüÀ» Ç¥½ÃÇÑ´Ù.?

                             switch(mode) {

                                           case 0 :                 // Á¤Áö 

                                                         PORTE=~0x00;

                       break;

                          case 1 :                 // ÀüÁø , ÈÄÁø

                                       if(iter > (300-vel)) {

                                                    m_cnt<<=1; 

                                     if(m_cnt>=0x10 || m_cnt==0x00)

                                                m_cnt=0x01;

                                      PORTE=~m_cnt;       //m_cntÀÇ º¸¼ö¸¦ Ãâ·Â     

                                       iter=0;

                        }

                        break;

          case 2 :                 // ¿ìȸÀü

                        if(iter > 100) {

                                                                       if(m_cnt != 0x00)

                                                                                      m_cnt=0x00;

                                                                       else

                                                                                      m_cnt=0x20;

                                                                       PORTE=~m_cnt;

                                                                       iter=0;

                                                         }

                                                         break; 

                                           case 3 :                 // ÁÂȸÀü

                        if(iter > 100) {

                                                                       if(m_cnt != 0x00)

                                                                                      m_cnt=0x00;

                                                                       else

                                                                                      m_cnt=0x10;

                                                                       PORTE=~m_cnt;

                                                                       iter=0;

                                                         }

                                                         break;

      }

      iter++;

      delay_ms(1);

 

      }

}

óÀ½

°ú    Á¦