ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • PWM TO PPM 소스
    RC 2010. 6. 13. 20:17
    소스입니다. 몇라인 안됩니다. 어셈블리어 잘하시는 분이 최적화 해주셨으면 하네용 

    #include <avr/io.h>

    #define sbi(PORT,BIT)  PORT|=_BV(BIT)  //set bit
    #define cbi(PORT,BIT)  PORT&=~_BV(BIT)  //clear bit

    // use 20MHz clock for high resolution..

    void send_100us()
    {
     register unsigned char i;
     for(i=0;i<11;i++)
     {
      asm volatile("PUSH R0");
      asm volatile("POP R0");
      asm volatile("PUSH R0");
      asm volatile("POP R0");
     }
    }

    int main()
    {
     unsigned char pd;
     unsigned char pb;

     // out port : PB4
     // input port : PB,PD except PD4
     DDRB =0x10; 
     DDRD = 0x00;

    // asm volatile("cli");
    // asm volatile("sei");
     PORTB = 0xef; // for internal pull up
     PORTD = 0Xff;
     pb = PINB;
     pd = PIND;
     while(1) {
      if(pd != PIND) {
       sbi(PORTB,4);
       send_100us();
       cbi(PORTB,4);
       pd = PIND;
      } else if(pb != PINB) {
       sbi(PORTB,4);
       send_100us();
       cbi(PORTB,4);
       pb = PINB;
      }
     }
     return 1;
    }


    댓글

Designed by Tistory.