[ create a new paste ] login | about

Link: http://codepad.org/LiHl0AML    [ raw code | output | fork ]

C, pasted on Aug 1:
/*
 * Blink and Sleep by Reset  (Test register not initialized by Reset)
 *
 * Created: 2019/xx/xx
 * Author : potesara
 *
 * PoerON->[MODE1]->Reset->[MODE2]->Reset->[MODE3]->Reset->[Sleep]->Reset->[MODE1] (loop)
 *
 * ATtiny13A
 * LED : PB0~PB4
 * Mode Switch : PB5(Reset Pin)
 *
 */
#define    F_CPU    1200000UL      // 1MHz

#include <avr/io.h>
#include <util/delay.h>
#include <avr/sleep.h>

//int dummy;
//#define MODE dummy							// Global Val. not initialized by reset?
#define MODE EEARL						// Register not initialized by reset
#define POWER_ON ((MCUSR & 0b00000001)==1)
#define clr_power_on() (MCUSR&=0b11111110)
void setup(void){
	_delay_ms(30);						// Wait for switch bounce
	DDRB = 0b00011111;					// PB4~PB0 Port OUTPUT Mode
	PORTB = 0b00000000;					// PB4~PB0 LOW

	if(MODE==0 || POWER_ON){			// Reset in MODE0 or PowerON Reset
		clr_power_on();							// Clear POWER ON Flag
		MODE = 1;
	}else if(MODE==1){					// Reset in MODE1
		MODE = 2;
	}else if(MODE==2){					// Reset in MODE2
		MODE = 3;
	}else if(MODE>=3){					// Reset in MODE3 or else
		MODE = 0;
		set_sleep_mode(SLEEP_MODE_PWR_DOWN);
		sleep_mode();
	}
}
int main(void){
	int i;
	
	setup();
    while (1){
		for(i=0;i<MODE;i++){	// Flashes for the number of MODEs
			PORTB = 0b00011111;
			_delay_ms(100);
			PORTB = 0b00000000;
			_delay_ms(200);
		} 
		PORTB = 0b00000000;		// wait 1sec
		_delay_ms(1000);
    }
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Line 19: error: avr/io.h: No such file or directory
Line 23: error: util/delay.h: No such file or directory
Line 22: error: avr/sleep.h: No such file or directory
In function 'setup':
Line 27: error: 'DDRB' undeclared (first use in this function)
Line 27: error: (Each undeclared identifier is reported only once
Line 27: error: for each function it appears in.)
Line 8: error: invalid suffix "b00011111" on integer constant
Line 28: error: 'PORTB' undeclared (first use in this function)
Line 9: error: invalid suffix "b00000000" on integer constant
Line 30: error: 'EEARL' undeclared (first use in this function)
Line 30: error: 'MCUSR' undeclared (first use in this function)
Line 15: error: invalid suffix "b00000001" on integer constant
Line 15: error: invalid suffix "b11111110" on integer constant
Line 39: error: 'SLEEP_MODE_PWR_DOWN' undeclared (first use in this function)
In function 'main':
Line 48: error: 'EEARL' undeclared (first use in this function)
Line 49: error: 'PORTB' undeclared (first use in this function)
Line 11: error: invalid suffix "b00011111" on integer constant
Line 11: error: invalid suffix "b00000000" on integer constant
Line 10: error: invalid suffix "b00000000" on integer constant


Create a new paste based on this one


Comments: