Interfacing attiny2313 AVR with HD44780 LCD

We will use an attiny2313 AVR microcontroller to display strings on an HD44780 LCD (4-bit mode).

482 bytes of flash written. Using internal oscillator.

## Connections

+-----------------------------------+----------------+
|            HD44780 LCD            | attiny2313 MCU |
+-----------------------------------+----------------+
| PIN 1 (GND)                       |                |
| PIN 2 (+5V)                       |                |
| PIN 3 (contrast/GND)              |                |
| PIN 4 (reg select)                | PIN 2 (PD0)    |
| PIN 5 (R/W)                       | PIN 3 (PD1)    |
| PIN 6 (Enable)                    | PIN 6 (PD2)    |
| PIN 7                             |                |
| PIN 8                             |                |
| PIN 9                             |                |
| PIN 10                            |                |
| PIN 11                            | PIN 12 (PB0)   |
| PIN 12                            | PIN 13 (PB1)   |
| PIN 13                            | PIN 14 (PB2)   |
| PIN 14                            | PIN 15 (PB3)   |
| PIN 15 (220 Omhs resistor to +5V) |                |
| PIN 16 (GND)                      |                |
+-----------------------------------+----------------+

Read more “Interfacing attiny2313 AVR with HD44780 LCD”

Bit Manipulation in C

Bitwise Operators

& AND
| OR
^ XOR
~ NOT

Truth Tables

AND (“&”)

truth table

+--------+--------+-----------------+
| bit a  | bit b  | a & b (a AND b) |
+--------+--------+-----------------+
|     0  |     0  |               0 |
|     0  |     1  |               0 |
|     1  |     0  |               0 |
|     1  |     1  |               1 |
+--------+--------+-----------------+

byte example

     11001000  
   & 10111000 
     -------- 
   = 10001000

Read more “Bit Manipulation in C”

Arduino as ISP

I prefer to develop in pure C instead of using the Arduino framework, for both learning and code size purposes. I use the Arduino board solely as an AVR programmer, using my script qAVR to flash the microcontroller.

## material
– breadboard
– jumper wires
– 10µF capacitor
– 220 ohms resistor
– LED
– Arduino
– Target microcontroller (in our example, attiny2313)

## install dev env
pacman -S avr-gcc avr-libc avrdude
wget https://raw.githubusercontent.com/xdth/qavr/master/qavr (place it in your .bin folder)

Read more “Arduino as ISP”

qAVR – Script to compile a C program, generate the hex and flash the microcontroller

This shell script will compile a C program, generate an hex file and flash it to an AVR microcontroller.

For updates, check my github repository: https://github.com/xdth/qavr


Read more “qAVR – Script to compile a C program, generate the hex and flash the microcontroller”

Datasheets

Useful datasheets compiled for easy access. This list is updated eventually.

PIC microcontrollers
PIC12F629_PIC12F675
PIC16F84A

AVR microcontrollers
ATTINY13A
ATTINY2313_ATTINY4313A
ATTINY24A_ATTINY44A_ATTINY84A
ATTINY25_ATTINY45_ATTINY85
ATTINY25_ATTINY45_ATTINY85_summary
ATmega328-328P

Misc
ADXL335_accelerometer
L293D_H-Bridge
74HC595_74HCT595_shift-register
4N35_4N36_4N37_4N38_optocoupler
NE555

Calculator written in C for the 555 timer IC

+5 ---+---------------+---+
      |               |   |
      R            +----------+
      |            |  8   4   |
  +---+------+-----|7        3|------/\/\/\---+------- Vout
  :          |     |  LMC555  |               |
  C to test  +-----|6         |             -----
  :                |          |             -----
ground       +-----|2        5|----+          |
             |     |    1     |    |        ground
             |     +----------+  0.1 uF
             |          |          |
   Clock ----+        ground     ground
     ^

I needed a quick calculator for the 555 chip and decided to write one in C. Enjoy.
Read more “Calculator written in C for the 555 timer IC”