#pragma GCC optimize "-Og"
#include "ArduinoTrace.h"
volatile byte dato;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//PORTD=PORTD|(1<<PD4); //board pin 4 pull-up resistor
//asm volatile
// (
// "lds r24,%1 \n"
// "ori r24,0x10 \n"
// "sts %1 ,r24"
// :"=m" (PORTD)
// :"m" (PORTD)
// );
asm volatile
(
"lds r24,%[aPORTD] \n"
"ori r24,0x10 \n"
"sts %[aPORTD],r24"
:[aPORTD]"=m" (PORTD)
:"0" (PORTD)
);
//DDRB=DDRB|(1<<PB0); //led pin output
asm volatile
(
"sbi %0,0"
:
:"I" (_SFR_IO_ADDR(DDRB))
);
}
void loop() {
// put your main code here, to run repeatedly:
//dato=PIND&0x10; //aislar bit 4 de PIND
asm volatile
(
"in r24,%0 \n"
"andi r24,0x10 \n"
"sts dato,r24"
:
:"I" (_SFR_IO_ADDR(PIND))
);
if(dato==0) //si pulsador oprimido (bit 4 de PIND en 0)
{
//PORTB=PORTB|(1<<PB0); //led on
asm volatile
(
"sbi %0, 0"
:
:"I" (_SFR_IO_ADDR(PORTB))
);
}
else //sino:
{
//PORTB=PORTB&~(1<<PB0); //led off
asm volatile
(
"cbi %0, 0"
:
:"I" (_SFR_IO_ADDR(PORTB))
);
}
}