This is an optimised set of C libraries for ATtiny
last update : 2013/05/01
Direct link to the zip file : http://balbarie.com/arduino/TinyLibrariesSet.zip
The provided example run on 16 MHz clock ATtiny45 (internal oscillator).
TinyIrqHandler.h
Full management of PCINT0 . Only one function to install your interrupts routines. Nothing else to handle.
IRQvecteur(byte irq, void (*adresse)())
example:
void MyPin1Routine()
{
// your code here
}
void MyPin2Routine()
{
// your code here
}
void MyPin3Routine()
{
// your code here
}
etc...
void setup
{
IRQvecteur(1, MyPin1Routine);
IRQvecteur(2, MyPin2Routine);
IRQvecteur(3, MyPin3Routine);
}
The library saves the value of micros() at the start of interrupt in the data IRQmicros. I's interesting to enable interrupts at the start or inside your routine by the Arduino's function interrupts(), but if you have to use the value IRQmicros you have to save it before enable interrupts to ensure the value doesn't change because of another interrupt. The provided libraries TinyIRrc5 & TinySerialPlus are always doing this to let the timer's routine execute as soon as possible in order to keep a good synchro on serial transmit.
TinyIRrc5.h
Infrared receive of RC5 codes under interrupts. This library contains 2 functions and one flag data.
IRdemarre(pin number)
int IRdecode()
The repeat bit of RC5 protocole is automatically managed. If the key is a repeat then the high bit of the return is set if not this bit is clear.
Variable IRok indicate an available key.
example:
IRdemarre(1);
byte car;
// Avec suppression de la répétition
for (;;)
{
if (IRok)
{
car = IRdecode();
if (car < 0x800) // Test for no repeat key
{
switch(car)
{
case 0x41:
// your code
break;
etc..
// Avec répétition
for (;;)
{
if (IRok)
{
car = IRdecode() & 0x7FF; // suppress the repeat bit
switch(car)
{
case 0x41:
// your code
break;
etc..
TinySerialPlus.h
Asynchronous send and receive up to 19200 bauds on any pins. The library provides some additional functions to display values and strings and manage blinking of up to 5 independent leds (period is in mS, eg 1000 for 1 Hz with a resolution equal the duration of one bit * 8 (that to say 52 uS * 8 = 416 uS for a serial speed of 19200 bauds).
19200 bauds is the speed limit. If you want to use IR receive during a continuous flow on serial receive you must set the speed to 9600 bauds. At 9600 bauds you can use the IR continuously without any lost or corrupt on serial (with xon/xoff for no lost).
Sending and receiving can be start and use independently but if you want to use xon/xoff on receive you have to start the transmitter (and start the receiver if you want to use xon/xoff on transmit). Without handshaking you can use only one wire to send order or only one wire to receive report.
Defines at the top of the library are useful to set easily clock frequency (in practice 8 or 16 MHz) and speed of the link. Defines can also set the size of the receive buffer and set the Xon/Xoff handshaking for each way. You can also by uncomment the associated define implement serial transmit as AVR stdout (in order to use the AVR printf function)
TXdemarre(byte pin) // start sending
TXwrite(byte) // write a byte
TXprint(char *str, boolean crlf) // write a string with CRLF if crlf true
HEXprint(unsigned int valeur, byte digits) // write in hexa with the number of digits specified (1 to 4)
DECprint(unsigned int valeur) // write in decimal
ledperiode(byte pin, unsigned int periode) // define blink period for a led
ledstate(byte pin, boolean value) // start or stop the blinking
RXdemarre(byte pin) // start receiving
byte RXget() // read a byte of the buffer (don't call if RXcount = 0)
Variable RXcount provides the number of bytes in the buffer.
example:
void setup
{
RXdemarre(0);
TXdemarre(2);
ledperiode(3, 1000);
ledperiode(4, 1000);
ledstate(3, true); // Two leds in alternate blinking
delay(500);
ledstate(4, true);
}
void loop()
{
TXprint("Ready", true);
for(;;)
{
HEXprint(PINB, 1);
TXprint("", true);
delay(500);
if (RXcount)
{
if (RXget() == 27)
{
break;
}
}
}
Available functions of the example are started by the same keys on both the keyboard and the remote control.
0 --> Display available ram
1 --> Dump Tiny's registers
2 --> Dump Tiny's ram
3 --> Dump Tiny's EEPROM
4 --> Live echo (exit function only by remote control press)
5 --> Hexadecimal echo (ditto)
6 --> Display the RC5 code received (exit function only by keyboard press)
And now the main fact... The link to download : http://balbarie.com/arduino/TinyLibrariesSet.zip
WARNING : The file TinyLibrariesSet.zip can be updated without notification. In order to use the last version you have to compare datim of this file with the one you are using.
JLB