Skip to content

Instantly share code, notes, and snippets.

View NearLinHere's full-sized avatar

Yijin Lin NearLinHere

View GitHub Profile
@NearLinHere
NearLinHere / I2C_sample.c
Last active September 22, 2024 15:51
I2C sample code
#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
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.
#define _BV(x) (1 << x)
#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.
#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
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
/**
*
*/
package com.custom.view;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;