Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #define F_CPU 8000000L
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4.  
  5. // TESTING JARTZA'S MACROS
  6. #include "avr_common_macros.h"
  7. int main(void)
  8. {
  9.     // -------------------------------------------------------------------
  10.     // Setup port directions and make pb0 til pb2 outputs.
  11.     // -------------------------------------------------------------------
  12.  
  13.     BITS_SET(DDRB, PB0, PB1, PB2, PB3, PB4);
  14.    
  15.     // VS some messy code,
  16.    
  17.     //DDRB |= (1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) | (1 << PB4);
  18.    
  19.     while(1)
  20.     {
  21.         // -------------------------------------------------------------------
  22.         // Set one side of the chip high and the oher side of the chip low.
  23.  
  24.         BITS_SET(PORTB, PB0, PB1, PB2);
  25.         BITS_CLEAR(PORTB, PB3, PB4);    
  26.        
  27.         // VS some messy code.
  28.         /*
  29.         PORTB |= (1 << PB0);  
  30.         PORTB |= (1 << PB1);  
  31.         PORTB |= (1 << PB2);
  32.         PORTB &= ~(1 << PB3);
  33.         PORTB &= ~(1 << PB4);
  34.         */
  35.         _delay_ms(500);
  36.        
  37.         // -------------------------------------------------------------------
  38.         // Now do the opposite,
  39.        
  40.         BITS_CLEAR(PORTB, PB0, PB1, PB2);
  41.         BITS_SET(PORTB, PB3, PB4);  
  42.  
  43.         // VS some messy code.
  44.         /*
  45.         PORTB &= ~(1 << PB0);    
  46.         PORTB &= ~(1 << PB1);
  47.         PORTB &= ~(1 << PB2);
  48.         PORTB |= (1 << PB3);
  49.         PORTB |= (1 << PB4);
  50.         */
  51.         _delay_ms(500);
  52.     }    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement