Skip to content

Instantly share code, notes, and snippets.

@nuttt
Created July 4, 2013 07:59
Show Gist options
  • Save nuttt/5925760 to your computer and use it in GitHub Desktop.
Save nuttt/5925760 to your computer and use it in GitHub Desktop.
AVR Lab 3-3
#include <avr/io.h>
#define F_CPU 1600000UL
#include <util/delay.h>
#define PORT_LED PORTB
#define DIR_LED DDRB
#define LED1 1
#define LED2 2
#define BTN 0
#define t 200
void delay_ms(unsigned int time){
while(time-- > 0){
_delay_ms(100.0);
}
}
int main(void){
DIR_LED |= (1<<LED1);
DIR_LED |= (1<<LED2);
// Internal Pull up
PORTB |= (1<<BTN);
//Set up timer
TCCR1B |= (1 << CS10);
int cnt = 0;
int cnt2 = 0;
int l1 = 0;
int l2 = 0;
while(1){
if( TCNT1 >= 49999) {
//PORTB ^= (1<<LED2);
cnt++;
cnt2++;
TCNT1 = 0;
}
if(cnt > t && l1 == 0){
l1 = 1;
}
if(l1){
PORTB |= (1 << LED1);
}
if(cnt > t << 1){
l1 = 0;
PORTB ^= (1 << LED2);
PORTB &= ~(1 << LED1);
cnt = 0;
}
//PORTB ^= (1<<LED1);
//delay_ms(100);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment