This file contains 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
#define SCL TRISB4 // I2C bus | |
#define SDA TRISB1 // | |
#define SCL_IN RB4 // | |
#define SDA_IN RB1 // | |
// initialize | |
SDA = SCL = 1 ; | |
SCL_IN = SDA_IN = 0 ; | |
// make master wait |
This file contains 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
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin 13 as an output. | |
pinMode(13, OUTPUT); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(1000); // wait for a second |
This file contains 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
/* | |
Rework original sample with AVR-GCC. | |
*/ | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin 13 as an output. | |
DDRB |= (1 << 5); // pinMode(13, OUTPUT); | |
} |
This file contains 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
PORTC |= (1 << 0); // Set bit 0 only | |
PORTC &= ~(1 << 1); // Clear bit 1 only | |
PORTC ^= (1 << 4); // Toggle bit 4 only. | |
PORTC |= (1 << 7); // Set bit 7 only. |
This file contains 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
#define _BV(x) (1 << x) |
This file contains 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
#include <avr/io.h> | |
PORC |= _BV(0); //PORTC |= (1 << 0); // Set bit 0 only | |
PORCT &= ~_BV(1); //PORTC &= ~(1 << 1); // Clear bit 1 only | |
PORTC ^= _BV(4); //PORTC ^= (1 << 4); // Toggle bit 4 only. | |
PORTC |= _BV(7); //PORTC |= (1 << 7); // Set bit 7 only. |
This file contains 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
#include <avr/io.h> | |
PORTC |= (_BV(0) | _BV(1) | _BV(2)); // Set bits 0, 1, 2 | |
PORTC &= ~(_BV(3) | _BV(4) | _BV(5)); // Clear bits 3, 4, 5 | |
PORTC ^= (_BV(6) | _BV(7)); // Toggle bits 6, 7 | |
//without using MACRO _BV() would looks like this |
This file contains 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
/* | |
Rework original sample with AVR-libc. | |
*/ | |
#include <avr/io.h> | |
#include <util/delay.h> | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin 13 as an output. | |
DDRB |= _BV(5); // pinMode(13, OUTPUT); |
This file contains 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
void setup() { | |
// put your setup code here, to run once: | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} |
OlderNewer