-
-
Save ilsubyeega/f451e946c0ef28518ef107713555f347 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* main.c | |
* | |
* Created: 4/2/2024 11:15:32 AM | |
* Author: DatNgo | |
*/ | |
#include <xc.h> | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
typedef unsigned char byte; | |
#define cbi(REG8, BITNUM) REG8 &= ~(_BV(BITNUM)) | |
#define sbi(REG8, BITNUM) REG8 |= _BV(BITNUM) | |
#define ITERATION_BORDERLINE 5 // when iteration counts exceed this value, will reset to one and changes the led_state. | |
byte iteration_count = ITERATION_BORDERLINE; | |
byte led_state_1 = 0, led_state_2 = 0; | |
ISR(TIMER0_OVF_vect) { | |
// if iteration count is over borderline, set iteration count to one. | |
(iteration_count++ > ITERATION_BORDERLINE && !(iteration_count = 1)) && | |
( // and then | |
// shift led_state_1 to left, led_state_2 to right. if both states are zero, reset to initial state. | |
(!(led_state_1 <<= 1 + led_state_2 >>= 1)) && (led_state_1 = 0x01, led_state_2 = 0x80) | |
// merge both state to PORTB. | |
+ (PORTB = led_state_1 | led_state_2) | |
) | |
} | |
int main(void) | |
{ | |
DDRB = 0xff; | |
PORTB = 0x00; | |
TCCR0 = 0x07; | |
sbi(TIMSK, 0); | |
sei(); // SREG |= 0x80; | |
TCNT0 = 0x00; | |
while(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment