void init(void);
void start(void);
void send(int);
void send(int);
void stop(void);
void setup() {
// put your setup code here, to run once:
init();
start();
send(0x03);
send(0x01);
stop();
}
void loop() {}
// put your main code here, to run repeatedly:
void init(void)
{
volatile char *port_f = 0x30;
*port_f = 0x01;
}
void start(void)
{
volatile long i;
volatile char *slave = 0x31;
volatile char *TWCR1 = 0xbc;
*TWCR1 = 0xa4;
while(*TWCR1 != 0x04)
{
*slave = 0x01;
for(i=0;i<100000;i++);
*slave = 0x00;
for(i=0;i<100000;i++);
break;
}
}
void send(volatile int num)
{
volatile long i;
volatile char *slave = 0x31;
volatile char *TWCR1 = 0xbc;
volatile char *TWDR1 = 0xbb;
*TWCR1 = 0x84;
*TWDR1 = num;
while(*TWCR1 != 0x84)
{
*slave = 0x01;
for(i=0;i<100000;i++);
*slave = 0x00;
for(i=0;i<100000;i++);
break;
}
}
void stop(void)
{
volatile long i;
volatile char *slave = 0x31;
volatile char *TWCR1 = 0xbc;
*TWCR1 = 0x94;
while(*TWCR1 != 0x94)
{
*slave = 0x02;
for(i=0;i<100000;i++);
*slave = 0x00;
for(i=0;i<100000;i++);
break;
}
}