This is tutorial to explain how the Dot Matrix Display works

### Code in C Program

#include <mega16.h>

#include <delay.h>

#define xtal 4000000

unsigned char k;

flash unsigned char arr[8]={0x18, 0x3C, 0x66, 0x66, 0x7E,

0x66, 0x66, 0x00};

void main(void)

{

DDRA=0xFF; //set Port A and B to output

DDRB=0xFF;

while (1){

for(k=0;k<=7;k++){

PORTA=arr[k];

PORTB=~(1<<k);

delay_us(100);

}

}

}

### Circuit Diagram

### Description:

First the LEDs of the …. That we would like to be displayed are defined the arr array:

Arr[0] = 0x18 = 000**1 1**000

Arr[1] = 0x3C = 00**11 11**00

Arr[2] = 0x66 = 0**11**0 0**11**0

Arr[3] = 0x66 = 0**11**0 0**11**0

Arr[4] = 0x7E = 0**111 111**0

Arr[5] = 0x66 = 0**11**0 0**11**0

Arr[6] = 0x66 = 0**11**0 0**11**0

Arr[7] = 0x00 = 0000 0000

The leftshift operator is the equivalent of moving all the bits of the variable a specified number of places to the left:

[variable]<<[number of places]

For instance, consider the number 8 written in binary 00001000. If we wanted to shift it to the left 2 places, we’d end up with 00100000; everything is moved to the left two places, and zeros are added as padding. This is the number 32 — in fact, left shifting is the equivalent of multiplying by a power of two.

Every 100 nano second it turns on one row at the time

K = 0 , ~(1 <<K) = 0000 0001

K = 1 , ~(1 <<K) = 0000 0010

K = 2 , ~(1 <<K) = 0000 0100

K = 3 , ~(1 <<K) = 0000 1000

K = 4 , ~(1 <<K) = 0001 0000

K = 5 , ~(1 <<K) = 0010 0000

K = 6 , ~(1 <<K) = 0100 0000

K = 7 , ~(1 <<K) = 1000 0000

For example, when K=0 then Port A = 000**1 1**000 (that is the columns of 4 and 5 from the left) and PortB = 0000 0001 (that is the first row)

Therefore, the LEDs of 4 and 5 from the left top row are on.

Then when K=1 the 4 LEDs at the 3^{rd} to 6^{th} columns (00**11 11**00) in the second row are on.

So at each time that k equals some value the corresponding row is on and the LEDs in that row are on according to the 1 values in the arr[k] value.

Since this is done so quickly (100 nano seconds) we think all of them are on

**Reference:**