void initialize_servo_out(void) { //Set Timer 0 in Fast PWM mode, clock prescale of 256. //Gives a frequency of 305.18 and period 3.27ms; 78 steps in 1ms time period //Fast PWM, clear on match SET_BIT(TCCR0A, COM0A1); CLR_BIT(TCCR0A, COM0A0); SET_BIT(TCCR0A, COM0B1); CLR_BIT(TCCR0A, COM0B0); //Fast PWM CLR_BIT(TCCR0B, WGM02); SET_BIT(TCCR0A, WGM01); SET_BIT(TCCR0A, WGM00); //256 Clock prescale factor SET_BIT(TCCR0B, CS02); CLR_BIT(TCCR0B, CS01); CLR_BIT(TCCR0B, CS00); //Set Timer 2 in Fast PWM mode, clock prescale of 256. //Gives a frequency of 305.18 and period 3.27ms; 78 steps in 1ms time period //Fast PWM, clear on match SET_BIT(TCCR2A, COM2A1); CLR_BIT(TCCR2A, COM2A0); SET_BIT(TCCR2A, COM2B1); CLR_BIT(TCCR2A, COM2B0); //Fast PWM CLR_BIT(TCCR2B, WGM22); SET_BIT(TCCR2A, WGM21); SET_BIT(TCCR2A, WGM20); //256 Clock prescale factor //Note that register setup is different from Timer 0 SET_BIT(TCCR2B, CS22); SET_BIT(TCCR2B, CS21); CLR_BIT(TCCR2B, CS20); //Set the pins as output pins GPIO_OUTPUT(SERVO_CH1); GPIO_OUTPUT(SERVO_CH2); GPIO_OUTPUT(SERVO_CH3); GPIO_OUTPUT(SERVO_CH4); }
/*DESCRIPTION * LED亮、灭设置 *ARGUMENTS * number 0:LED0;1:LED1;2:LED2 * value 0:不亮;1: 亮 *RETURN * 0 函数调用成功 *NOTES * */ int SET_LED(int number, int value) { switch(number){ case 0: // LED2 GPIO_OUTPUT(C, 13, value); break; case 1: // LED3 GPIO_OUTPUT(B, 2, value); break; case 2: // 编程灯2(绿) GPIO_OUTPUT(G, 3, value); break; default: ; } return 0; }
void setup() { //Initialize all the global variables gSystemError = 0; gSystemTimerTick = 0; gSystemTime = 0; Serial.begin(115200); Serial.println("Pushpak Quadrotor........"); GPIO_OUTPUT(LED); GPIO_CLEAR(LED); initialize_servo_out(); initialize_servo_in(); initialize_adc(); //Initialize adc at the last as this funtion enable interrupts. timer1_init(); sei(); //enable interrupts // cli(); //Disable interrupts before copying the current RC reciever pulse values }
static INLINE void JTAG0_TDI_SO(void) { GPIO_OUTPUT(JTAG0_TDI_PIO_BIT); GPIO_ENABLE(JTAG0_TDI_PIO_BIT); }
static INLINE void JTAG0_NTRST_SO(void) { GPIO_OPENDRAIN(JTAG0_NTRST_PIO_BIT); GPIO_OUTPUT(JTAG0_NTRST_PIO_BIT); GPIO_ENABLE(JTAG0_NTRST_PIO_BIT); }