Code: Select all
#include <avr/io.h> // this contains all the IO port definitions
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <util/delay.h>
void delay_ms( uint16_t milliseconds)
{
for( ; milliseconds > 0; milliseconds--)
{
_delay_ms( 1);
}
}
#define TIMER1_PRESCALE_1 1
#define TIMER1_PRESCALE_8 2
#define TIMER1_PRESCALE_64 3
#define TIMER1_PRESCALE_256 4
#define TIMER1_PRESCALE_1024 5
#define HEX__(n) 0x##n##UL
#define B8__(x) ((x&0x0000000FLU)?1:0) \
+((x&0x000000F0LU)?2:0) \
+((x&0x00000F00LU)?4:0) \
+((x&0x0000F000LU)?8:0) \
+((x&0x000F0000LU)?16:0) \
+((x&0x00F00000LU)?32:0) \
+((x&0x0F000000LU)?64:0) \
+((x&0xF0000000LU)?128:0)
#define B8(d) ((unsigned char)B8__(HEX__(d)))
onst static int image[] = {
B8(11111111),
B8(00000000)
};
#define NUM_ELEM(x) (sizeof (x) / sizeof (*(x)))
int imagesize = NUM_ELEM(image);
uint8_t j = 0;
SIGNAL( SIG_TIMER1_COMPA ) {
if (j == 1)
if (j >= imagesize)
j = 0;
PORTB = image[j];
j++;
}
int main(void) {
DDRB = 0xFF;
TCCR1B = (1 << WGM12) | TIMER1_PRESCALE_1;
OCR1A = 228;
TIMSK |= 1 << OCIE1A;
sei();
while (1);
}
i tried guessing at what i might have to do to change the code to work for the 45. i don't know if it works.
Code: Select all
#include <avr/io.h> // this contains all the IO port definitions
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <util/delay.h>
#define TIMER1_PRESCALE_1 1
#define TIMER1_PRESCALE_8 2
#define TIMER1_PRESCALE_64 3
#define TIMER1_PRESCALE_256 4
#define TIMER1_PRESCALE_1024 5
int j = 0;
SIGNAL( SIG_TIMER1_COMPA ) {
if (j == 1)
{
PORTB.B1 = 1;
j = 0;
}
else if (j == 0)
{
PORTB.B1 = 0;
j = 1;
}
}
int main(void) {
DDRB = 0xFF;
TCCR1B = (1 << WGM12) | TIMER1_PRESCALE_1;
OCR1A = 228;
TIMSK |= 1 << OCIE1A;
sei();