int main(void) { int num; num = asmfunction(); printf("Your function returned %d\n", num); return 0; }
int main(void) //beginning of main function { DDRA=asmfunction(); //set PORTA to write DDRB=0xFF; //set PORTB to write DDRC=0xFF; //set PORTC to write DDRD=0b10111011; //set PIND2 and PIND6 to read and the rest of PORTD to write PORTB=PORTB&0b01111111; //set PINB7 to logic zero (turn on green LED) PORTB=PORTB|0b01000000; //set PINB6 to logic one (turn off red LED) PORTD=0b01000100; //enable pull-up resistors of PIND2 and PIND6 lcd_init(); //initialize LCD display lcd_clear(); //clear LCD display lcd_home(); //set cursor of LCD to the first character position /*The next two lines configure T/C0 and T/C2 to set OCR0 and OCR2, respectively on compare match when the T/C subsystem's respective counting register is counting up and to clear OCR0 and OCR2 when counting down. Configured as Fast PWM, Phase-Correct with a prescalar of one.*/ TCCR2=(1<<WGM20)|(1<<COM21)|(1<<COM20)|(1<<CS20); TCCR0=(1<<WGM00)|(1<<COM01)|(1<<COM00)|(1<<CS00); /*The next two lines configure TCNT1 to increment every clock cycle; Configure Enable Input Capture Interrupt to trigger on rising edge; Enable Input Capture Noise Canceller; Locally enable T/C 1 Input Capture Interrupt and T/C 1 Overflow Interrupt.*/ TCCR1B=(1<<ICES1)|(1<<CS10)|(1<<ICNC1); TIMSK=(1<<TICIE1)|(1<<TOIE1); MCUCR=(1<<ISC00)|(1<<ISC01);//configure external interrupt 1 to trigger on rising edge GICR=(1<<INT0); //locally enable external interrupt 1 sei(); //set global interrupt flag unsigned long int button=0; //unsigned long integer (32 bits--sent by IR remote) uint8_t led=0; //state of LED (used to confirm 34-bit transmission by IR remote) int speed=0; //speed of motors at maximum int lights=off; lcd_printf("Waiting"); //print "Waiting" on LCD (wait for button to be pushed on IR remote) PORTB=PORTB|0b00000010; while(1) //infinite loop { if(bit==34) //wait until bit=34--Input Capture ISR called 34 times (1 start bit, 32 data bits, and 1 stop bit sent by IR remote) { button=decipher(remote); //decipher the 32 data bits as either 1 or 0 depending on TCNT1 values; //pass remote as parameter and set button equal to return value bit=0; //reset bit equal to 0 (prepare to receive a new command) if(led==0) //if the state of led is 0, turn off green LED and turn on red LED { //then switch the state of led to 1 PORTB=PORTB&0b10111111; PORTB=PORTB|0b10000000; led++; } else //if the state of led is not 0 (state is 1), turn off red LED and turn on green LED { //then switch the state of led to 0 PORTB=PORTB&0b01111111; PORTB=PORTB|0b01000000; led--; } switch(button) //check the value of button (button that was pushed on remote) { case up_arrow: //if up arrow was pushed, make robot go forward forward(); break; case down_arrow: //if down arrow was pushed, make robot go backward backward(); break; case left_arrow: //if left arrow was pushed, make robot go left left(); break; case right_arrow: //if right arrow was pushed, make robot go right right(); break; case channel_up: //if channel up was pushed, speed robot up (speed is parameter sent to speed_up function); speed equals returned value speed=speed_up(speed); break; case channel_down: //if channel down was pushed, slow robot down (speed is parameter sent to speed_down function); speed equals returned value speed=slow_down(speed); break; case mute: //if mute was pushed, toggle lights from off to on or on to off; pass lights as parameter and set lights equal to returned value lights=toggle_lights(lights); break; default: //if any other button was pushed, stop robot stop(); break; } OCR0=speed; //set the speed of the left motor depending on value of speed OCR2=speed; //set the speed of the right motor depending on value of speed } } }