Same thing as an Arduino Uno but smaller. Let's look at the ATtiny13 MCU. 64bytes of usable RAM and 1kByte flash program storage. Only 6 IOs from PORTB.
It's all you need for a security dongle or a USB reader. Thermostats and washing machines use these.
Sample CodeThis code will run on an Arduino or other board using Atmega processors such as the ATtiny. It toggles bits on PORTB.
#define reps 3
#include <avr/io.h>
#include <util/delay.h>
int main() { DDRB = 0xFF; // PORTB output
while(1) {
// decimal version of PORTB = 1 then PORTB = 0
PORTB = 1; _delay_ms(500); // led on
PORTB = 0; _delay_ms(500); // led off
// decimal version of PORTB = 255 then PORTB = 0
PORTB = 255; _delay_ms(500);
PORTB = 0; _delay_ms(500);
// binary version of PORTB = 1 then PORTB = 0
PORTB = 0b00000001; _delay_ms(500); // led on
PORTB = 0b00000000; _delay_ms(500); // led off
// binary version of PORTB = 255 then PORTB = 0
PORTB = 0b11111111; _delay_ms(500);
PORTB = 0b00000000; _delay_ms(500);
// hexadecimal version of PORTB = 1 then PORTB = 0
PORTB = 0x01; _delay_ms(500); // led on
PORTB = 0x00; _delay_ms(500); // led off
// hexadecimal version of PORTB = 255 then PORTB = 0
PORTB = 0xFF; _delay_ms(500); // led on
PORTB = 0x00; _delay_ms(500); // led off
// shifts single bit from PORTB.0 to PORTB.7
for (int j=0;j < reps;j++) {
for (int i=0; i < 8 ;i++) { PORTB = (1<<i); _delay_ms(4000);}
for (int i=0; i < 8 ;i++) { PORTB = (128>>i); _delay_ms(4000);}
}
// masking of bits with |= and &= operators
for (int j=0;j < reps;j++) {
PORTB |= 0b00000001; _delay_ms(500); // mask to force PORTB.0 = 1
PORTB &= 0b11111110; _delay_ms(500); // mask to force PORTB.0 = 0
}
// alternate pattern
for (int j=0;j < reps;j++) {
PORTB = 0x55; _delay_ms(500); // PORTB = 0b01010101
PORTB = 0xAA; _delay_ms(500); // PORTB = 0b10101010
}
// mathematical inverse of PORTB is put into PORTB
for (int j=0;j < reps;j++) {
PORTB = !PORTB; _delay_ms(500);
}}}
Our ATtiny13 development board has LEDs on pin PB3 and PB4. You may wish to change this code to use those numbers.
Xpress IDE onlineOpen an account at MPLab Xpress IDE online. Create a New Project named at13 and select ATtiny13 MCU. Create a main.c file and enter this code. It will make LEDs blink.
Menu Run->Run Project and a hex file of this code will be delivered to your downloads folder. The first hex file will be at13.hex and the second will be at13(1).hex and so forth. You will have to clean up extra files in your downloads folder.
Download and run SimulIDE electronic simulator program. Donations are welcome.
Open a blank circuit. Find and add an ATtiny13 chip. Find and add buffers and an LED bar. Ground the cathode of the LED bar and connect the 6 pins of the ATtiny to LEDs on the bar until you have something like this.
This circuit simulator works when I add buffers to amplify the current. A real circuit may work with just LEDs.
Load FirmwareRight click directly on the ATtiny processor chip and look at the commands for Load firmware.
Find the hex file we generated from the Online compiler. We can use hex files from Arduino IDE, MPLab, Atmel Studio and many other compilers.
SimulIDE will power off as a safety feature when you make changes to the circuit or software. Click the On/Off power button and Pause button at the top of the screen.
Right click on the MCU and open MCU Monitor. This looks inside the memory of the simulated processor.
Flash shows us all of our demo code fits into about half the storage
Many development boards do not contain a programmer circuit. USBtiny and USBasp are inexpensive devices that work with AVR processors.
Loose wires are an option. If you are using a cable pay attention to pin numbering, connector orientation and keying.
UploadOpen a terminal screen and enter
avrdude -p t13 -c usbasp -U flash:w:at13.hex:i
Avrdude program will upload a hex file to an ATtiny13 using a USBasp programmer. You should see this on your screen, you may see blinking lights on the programmer.
Comments