Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr\io.h> // Most basic include files
- #include <avr\interrupt.h> // Add thenecessary ones
- #include <avr\signal.h> // here
- //#define F_CPU 11059200U
- #include <util\delay.h>
- #define MOVER(x) (x << 1 | x >> 7)
- #define MOVEL(x) (x >> 1 | x << 7)
- int main(void) {
- DDRE = 0xff;
- DDRA = 0xff;
- PORTE = _BV(PE3);
- PORTA = 1;
- uint8_t state4 = 0;
- uint8_t buttonState4 = 0;
- uint8_t state5 = 0;
- uint8_t buttonState5 = 0;
- uint8_t dir = 1;
- while(1) {
- if(((PIND & _BV(PD4)) == 0) && buttonState4 == 0){
- state4 = !state4;
- buttonState4 = 1;
- }
- if((PIND & _BV(PD4)) != 0)
- buttonState4 = 0;
- if(state4) {
- dir = 0;
- state4 = 0;
- }
- if(((PIND & _BV(PD5)) == 0) && buttonState5 == 0){
- state5 = !state5;
- buttonState5 = 1;
- }
- if((PIND & _BV(PD5)) != 0)
- buttonState5 = 0;
- if(state5) {
- dir = 1;
- state5 = 0;
- }
- _delay_ms(100);
- if(dir)
- PORTA = MOVER(PORTA);
- else
- PORTA = MOVEL(PORTA);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement