Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright 2011 Dustin L. Westaby
- ----------------------------------------------------------------------
- Prop Circuit for Attiny45
- ----------------------------------------------------------------------
- Title: cortana.c
- Author: Dustin Westaby
- Date Created: 2/13/11
- Last Modified: 2/13/11
- Purpose: Animated output to LEDs
- Compiled with AVR-GCC WinAVR
- Revisions List:
- 2/13/11 Initial Draft and test circuit
- ----------------------------------------------------------------------
- Fuses:
- ----------------------------------------------------------------------
- BrownOut Disabled
- CKDIV8
- Int RC Osc 8Mhz + 64ms
- ----------------------------------------------------------------------
- Inputs:
- ----------------------------------------------------------------------
- Power up
- ----------------------------------------------------------------------
- Ouputs:
- ----------------------------------------------------------------------
- pin label connections
- ----------------------------------------------------------------------
- 2 PB3 = LED
- 3 PB4 = LED
- 5 PB0 = LED
- 6 PB1 = LED
- 7 PB2 = LED
- ----------------------------------------------------------------------
- Notes:
- ----------------------------------------------------------------------
- -
- */
- //--------------------------------------
- // Global Variables |
- //--------------------------------------
- #define F_CPU 8000000UL/8 /* 8 MHz Internal Oscillator DIV8 */
- enum { up, down };
- //--------------------------------------
- // Includes |
- //--------------------------------------
- #include <avr/io.h>
- #include <util/delay.h>
- //#include <avr/sleep.h>
- #include <inttypes.h>
- //--------------------------------------
- // Delay Subroutines |
- //--------------------------------------
- void delay_ms(uint16_t ms) {
- while ( ms )
- {
- _delay_ms(1);
- ms--;
- }
- }
- void delay_us(uint16_t us) {
- while ( us )
- {
- _delay_us(1);
- us--;
- }
- }
- //--------------------------------------
- // Main |
- //--------------------------------------
- int main (void)
- {
- //variables used for animations
- int i;
- i=0;
- int count_delay;
- count_delay=50;
- int duty_cycle;
- duty_cycle=1000;
- int direction;
- direction=up;
- //port B is an output
- DDRB = 0b00011111;
- //Spin Circle
- count_delay=50;
- for (i = 0; i < 4; i++)
- {
- PORTB = 0b00000001;
- delay_ms(count_delay);
- PORTB = 0b00000010;
- delay_ms(count_delay);
- PORTB = 0b00000100;
- delay_ms(count_delay);
- PORTB = 0b00001000;
- delay_ms(count_delay);
- PORTB = 0b00010000;
- delay_ms(count_delay);
- }
- //ALL ON
- PORTB = 0b00011111;
- delay_ms(800);
- //Blink Blink
- PORTB = 0b00000000;
- delay_ms(100);
- PORTB = 0b00011111;
- delay_ms(10);
- PORTB = 0b00000000;
- delay_ms(100);
- PORTB = 0b00011111;
- delay_ms(100);
- //starts brigth then dims (software PWM)
- int time_on, time_off, max_value, min_value, rate_of_change;
- max_value=500;
- min_value=5;
- time_on=min_value;
- time_off=max_value;
- rate_of_change=2;
- direction=down;
- while(1)
- {
- PORTB = 0b00011111;
- delay_us(time_on);
- PORTB = 0b00000000;
- delay_us(time_off);
- if (direction==up)
- {
- time_on+=rate_of_change;
- time_off-=rate_of_change;
- if (time_on>max_value)
- direction=down;
- }
- else
- {
- time_on-=rate_of_change;
- time_off+=rate_of_change;
- if (time_on<=min_value)
- direction=up;
- }
- }
- while(1); // Ending infinite loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement