Tuesday, April 28, 2015

LED 8x8 Matrix Display Interface with ATmega8 "LED Scrolling Display"


This Tutorial will demonstrate How to make Scrolling or Moving message display using 8x8 Matrix LED display. 
8x8 Matrix LED Display

Objective:
1. To make understand 8x8 matrix LED driving
2. How to generate characters on display?
3. Make text scroll horizontally

Circuit Diagram:

8x8 Matrix LED Display Interfacing with ATmega8

Code (AVR Studio 4):

#include <avr/io.h>
#include <avr/interrupt.h>
//#include <math.h>
//#include <avr/sleep.h>
#include <avr/pgmspace.h> 


void delay();
void DisplayChar(char f);
void Scanner();

char Vline[8];
char cc,y,U,P;

/*--------------------------------------------------------------------------------------------------
                                     Character generator

             This table defines the standard ASCII characters in a 3x5 dot format.
--------------------------------------------------------------------------------------------------*/
PROGMEM static const char FontLookup [][6] =
{
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp

    { 0x03, 0x03, 0xff, 0xff, 0x03, 0x03 },   // T
    { 0xf8, 0xfc, 0x07, 0x07, 0xfc, 0xf8 },   // A
    { 0x00, 0x38, 0x44, 0x82, 0x01, 0x8c },   // (
    { 0x9e, 0x92, 0x92, 0xf2, 0x60, 0x00 },   // S
    { 0xfe, 0xfe, 0x08, 0x1c, 0x36, 0x62 },   // K
    { 0x82, 0xc6, 0x6c, 0x38, 0x1c, 0x0e },   // Y
    { 0x06, 0x00, 0x08, 0x08, 0x08, 0x00 },   // Y

    { 0xFF, 0xFF, 0x00, 0xf8, 0x24, 0x22 },   // A
    { 0x24, 0xf8, 0x00, 0xfa, 0x00, 0xfc },   // i
    { 0x08, 0x06, 0x00, 0xfb, 0x01, 0xfb },   // r
    { 0x87, 0x6b, 0x6b, 0xa7, 0xff, 0x01 },   // T
    { 0xff, 0xff, 0x00, 0x08, 0x08, 0x00 },   // e

    { 0xff, 0x81, 0xad, 0xad, 0xd3, 0xff },   // B
    { 0x81, 0xff, 0xc3, 0xbd, 0xad, 0xcb },   // I
    { 0xff, 0x00, 0x02, 0x02, 0x7e, 0x02 },   // G
    { 0x02, 0x00, 0x1e, 0x20, 0x40, 0x20 },   // T
    { 0x1e, 0x00, 0x08, 0x08, 0x08, 0x00 },   // V

    { 0xf8, 0xfc, 0x07, 0x07, 0xfc, 0xf8 },   // 2
    { 0x21, 0x41, 0x45, 0x4B, 0x31, 0x00 },   // 3
    { 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00 },   // 4
    { 0x27, 0x45, 0x45, 0x45, 0x39, 0x00 },   // 5
    { 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x00 },   // 6
    { 0x01, 0x71, 0x09, 0x05, 0x03, 0x00 },   // 7
    { 0x36, 0x49, 0x49, 0x49, 0x36, 0x00 },   // 8
    { 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00 },   // 9
    { 0x00, 0x36, 0x36, 0x00, 0x00, 0x00 },   // :
    { 0x00, 0x56, 0x36, 0x00, 0x00, 0x00 },   // ;
    { 0x08, 0x14, 0x22, 0x41, 0x00, 0x00 },   // <
    { 0x14, 0x14, 0x14, 0x14, 0x14, 0x00 },   // =
    { 0x00, 0x41, 0x22, 0x14, 0x08, 0x00 },   // >
    { 0x02, 0x01, 0x51, 0x09, 0x06, 0x00 },   // ?
    { 0x32, 0x49, 0x59, 0x51, 0x3E, 0x00 },   // @
    { 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00 },   // A
    { 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00 },   // B
    { 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00 },   // C
    { 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00 },   // D
    { 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00 },   // E
    { 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00 },   // F
    { 0x3E, 0x41, 0x49, 0x49, 0x7A, 0x00 },   // G
    { 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00 },   // H
    { 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00 },   // I
    { 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00 },   // J
    { 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00 },   // K
    { 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00 },   // L
    { 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00 },   // M
    { 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00 },   // N
    { 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00 },   // O
    { 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00 },   // P
    { 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00 },   // Q
    { 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00 },   // R
    { 0x46, 0x49, 0x49, 0x49, 0x31, 0x00 },   // S
    { 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00 },   // T
    { 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00 },   // U
    { 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00 },   // V
    { 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00 },   // W
    { 0x63, 0x14, 0x08, 0x14, 0x63, 0x00 },   // X
    { 0x07, 0x08, 0x70, 0x08, 0x07, 0x00 },   // Y
    { 0x61, 0x51, 0x49, 0x45, 0x43, 0x00 },   // Z
    { 0x00, 0x7F, 0x41, 0x41, 0x00, 0x00 },   // [
    { 0x55, 0x2A, 0x55, 0x2A, 0x55, 0x00 },   // 55
    { 0x00, 0x41, 0x41, 0x7F, 0x00, 0x00 },   // ]
    { 0x7F, 0x7F, 0x49, 0x49, 0x41, 0x00 },   // E//{ 0x04, 0x02, 0x01, 0x02, 0x04, 0x00 },   // ^
    { 0x40, 0x40, 0x40, 0x40, 0x40, 0x00 },   // _
    { 0x00, 0x01, 0x02, 0x04, 0x00, 0x00 },    // '   
 { 0x20, 0x54, 0x54, 0x54, 0x78, 0x00 },   // a
    { 0x7F, 0x48, 0x44, 0x44, 0x38, 0x00 },   // b
    { 0x38, 0x44, 0x44, 0x44, 0x20, 0x00 },   // c
    { 0x38, 0x44, 0x44, 0x48, 0x7F, 0x00 },   // d
    { 0x38, 0x54, 0x54, 0x54, 0x18, 0x00 },   // e
    { 0x08, 0x7E, 0x09, 0x01, 0x02, 0x00 },   // f
    { 0x0C, 0x52, 0x52, 0x52, 0x3E, 0x00 },   // g
    { 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00 },   // h
    { 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00 },   // i
    { 0x20, 0x40, 0x44, 0x3D, 0x00, 0x00 },   // j
    { 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00 },   // k
    { 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00 },   // l
    { 0x7C, 0x04, 0x18, 0x04, 0x78, 0x00 },   // m
    { 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00 },   // n
    { 0x38, 0x44, 0x44, 0x44, 0x38, 0x00 },   // o
    { 0x7C, 0x14, 0x14, 0x14, 0x08, 0x00 },   // p
    { 0x08, 0x14, 0x14, 0x18, 0x7C, 0x00 },   // q
    { 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00 },   // r
    { 0x48, 0x54, 0x54, 0x54, 0x20, 0x00 },   // s
    { 0x04, 0x3F, 0x44, 0x40, 0x20, 0x00 }   // t
/*
    { 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00 },   // u
    { 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00 },   // v
    { 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00 },   // w
    { 0x44, 0x28, 0x10, 0x28, 0x44, 0x00 },   // x
    { 0x0C, 0x50, 0x50, 0x50, 0x3C, 0x00 },   // y
    { 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00 }    // z
 */
};

int main()
{
 int k;
 cc=0;
 y=0;

 int i,vl;
 char S,Z,g,K,w;
 char M;

 DDRD=0xFF;
 DDRB=0xFF;

 //Initialize scanner
 TCNT0=0xF1;
 TCCR0=0x05;
 TIMSK=0x01;
 SREG=0x80;

    PORTB=0x00;
 PORTD=0x00;

 char String[]="Manoj R. Thakur  ";


 while(1)
 {
  //DisplayChar('a');
   for(vl=0;vl<17;vl++) //115 IS NUMBER OF CHARECTERS
  {
   S=String[vl];
   for(Z=0;Z<6;Z++)
   { 
    Delay();
    U=Vline[0];
    Vline[0]=pgm_read_byte(&FontLookup[S-0x20][Z]);    
    P=Vline[1];
    Vline[1]=U;
    U=Vline[2];
    Vline[2]=P;
    P=Vline[3];
    Vline[3]=U;
    U=Vline[4];
    Vline[4]=P;
    P=Vline[5];
    Vline[5]=U;
    U=Vline[6];
    Vline[6]=P;
    P=Vline[7];
    Vline[7]=U;
    U=Vline[8];
    Vline[8]=P;
    P=Vline[9];
    Vline[9]=U;
    U=Vline[10];
    Vline[10]=P;
    P=Vline[11];
    Vline[11]=U;
    U=Vline[12];
    Vline[12]=P;
    P=Vline[13];
    Vline[13]=U;
    U=Vline[14];
    Vline[14]=P;
    P=Vline[15];
    Vline[15]=U;
    U=Vline[16];
    Vline[16]=P;
    P=Vline[17];
    Vline[17]=U;
    U=Vline[18];
    Vline[18]=P;
    P=Vline[19];
    Vline[19]=U;
    U=Vline[20];
    Vline[20]=P;                                                               

   }

  }
 }
}


void delay()
{
 int k; 
 for(k=1;k<16000;k++)
 {
 }
}

SIGNAL(TIMER0_OVF_vect)
{
 cc=cc++;
 Scanner();
 TCNT0=0xFE;
}

void Scanner()
{
switch(cc)
{
case 1:
  PORTD=0xFF;
  PORTB=0x80;
  PORTD=~Vline[0];
  break;
case 2:
  PORTD=0xFF;
  PORTB=0x40;
  PORTD=~Vline[1];
  break;
case 3:
  PORTD=0xFF;
  PORTB=0x20;
  PORTD=~Vline[2];
  break;
case 4:
  PORTD=0xFF;
  PORTB=0x10;
  PORTD=~Vline[3];
  break;
case 5:
  PORTD=0xFF;
  PORTB=0x08;
  PORTD=~Vline[4];
  break;
case 6:
  PORTD=0xFF;
  PORTB=0x04;
  PORTD=~Vline[5];
  break;
case 7:
  PORTD=0xFF;
  PORTB=0x02;
  PORTD=~Vline[6];
  break;
case 8:
  PORTD=0xFF;
  PORTB=0x01;
  PORTD=~Vline[7];
  cc=0;
}
}

/*********************************************************************************/
/*         Display Char                           */
/*********************************************************************************/
void DisplayChar(char f)
{
char g;
f=f-0x20;
 for(g=4;g>=0;g--)
 {
  Vline[y]=pgm_read_byte(&FontLookup[f][g]);
  y=y++;
 }
  Vline[y]=0x00;
  y=0;//y++;
}

void Delay()
{
 int t;
  for(t=0;t<4000;t++);
}








2 comments:

  1. hi
    where should we connect battery ?!!!

    ReplyDelete
  2. nice one, please can you show me how to construct an led matrix of 40 by 120 using avr microcontroller

    ReplyDelete