PWM TO PPM 소스
#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;
}