Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8x8 dot Matrix not displaying proper message

Status
Not open for further replies.

kel

Newbie level 4
Joined
May 21, 2006
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,321
Gentlemen,
I'm having problem displaying message on my 8x8 dot matrix display. I've modified a small c code rewriting it in C using CCS C compiler. In as far as my hardware is concern, I'm using a pic16f877a, a 74HC595, NPN transistors and a CD4017.As you would note in code, the serial data pin is connected to PIN_D2 and a function has been written to emulate serial port. Scrolling is as expected except that the message being displayed is unrecognizable and random.The code is as attached below. Would you kindly assist.
Appreciate your help in advance.

Code:
#include <16F877A.h>
#include <string.h>

//#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=20000000)
#define mask 0x01
#define Shift 8

#define ButInput PIN_E0
// Define LCD module connections.
/* sbit Serial_Data at LATC2_bit;
SH_Clk at LATC6_bit;
ST_Clk at LATC7_bit;
CD4017_Clk at LATA2_bit;
CD4017_RST at LATA1_bit;*/
#define SH_CLK     PIN_D0
#define ST_CLK     PIN_D1
#define SER_DATA   PIN_D2
#define CD4017_CLK PIN_D3
#define CD4017_RST PIN_D4

char columns [8] ={1,2,4,8,16,32,64,128};
//char const pat[8]={0x3f,0x02,0x04,0x02,0x3f,0xff,0x06, 0x0f}; 
const unsigned char CharData[][8] ={
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001010, 0b00001010, 0b00001010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010},
{0b00000111, 0b00001100, 0b00010100, 0b00001100, 0b00000110, 0b00000101, 0b00000110, 0b00011100},
{0b00011001, 0b00011010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001011, 0b00010011},
{0b00000110, 0b00001010, 0b00010010, 0b00010100, 0b00001001, 0b00010110, 0b00010110, 0b00001001},
{0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000010, 0b00000100, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000100, 0b00000010},
{0b00001000, 0b00000100, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000100, 0b00001000},
{0b00010101, 0b00001110, 0b00011111, 0b00001110, 0b00010101, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00011111, 0b00000100, 0b00000100, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000100},
{0b00000001, 0b00000010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010011, 0b00010001, 0b00010101, 0b00010001, 0b00011001, 0b00001110},
{0b00000100, 0b00001100, 0b00010100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00011111},
{0b00001110, 0b00010001, 0b00010001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00011111},
{0b00001110, 0b00010001, 0b00000001, 0b00001110, 0b00000001, 0b00000001, 0b00010001, 0b00001110},
{0b00010000, 0b00010000, 0b00010100, 0b00010100, 0b00011111, 0b00000100, 0b00000100, 0b00000100},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00000001, 0b00000001, 0b00000001, 0b00011110},
{0b00000111, 0b00001000, 0b00010000, 0b00011110, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00011111, 0b00000001, 0b00000001, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00001110, 0b00010001, 0b00010001, 0b00001111, 0b00000001, 0b00000001, 0b00000001, 0b00000001},
{0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00000000},
{0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00001000},
{0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00001000, 0b00000100, 0b00000010, 0b00000001},
{0b00000000, 0b00000000, 0b00000000, 0b00011110, 0b00000000, 0b00011110, 0b00000000, 0b00000000},
{0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000010, 0b00000100, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00000010, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001110, 0b00010001, 0b00010001, 0b00010101, 0b00010101, 0b00010001, 0b00010001, 0b00011110},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001, 0b00010001},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010001, 0b00010001, 0b00010001, 0b00011110},
{0b00000111, 0b00001000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00001000, 0b00000111},
{0b00011100, 0b00010010, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010010, 0b00011100},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00011111},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00010000},
{0b00001110, 0b00010001, 0b00010000, 0b00010000, 0b00010111, 0b00010001, 0b00010001, 0b00001110},
{0b00010001, 0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00010001},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00011111},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00010100, 0b00001000},
{0b00010001, 0b00010010, 0b00010100, 0b00011000, 0b00010100, 0b00010010, 0b00010001, 0b00010001},
{0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00011111},
{0b00010001, 0b00011011, 0b00011111, 0b00010101, 0b00010001, 0b00010001, 0b00010001, 0b00010001},
{0b00010001, 0b00011001, 0b00011001, 0b00010101, 0b00010101, 0b00010011, 0b00010011, 0b00010001},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00010011, 0b00001111},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010100, 0b00010010, 0b00010001, 0b00010001},
{0b00001110, 0b00010001, 0b00010000, 0b00001000, 0b00000110, 0b00000001, 0b00010001, 0b00001110},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001010, 0b00000100},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00010101, 0b00001010},
{0b00010001, 0b00010001, 0b00001010, 0b00000100, 0b00000100, 0b00001010, 0b00010001, 0b00010001},
{0b00010001, 0b00010001, 0b00001010, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00011111, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00010000, 0b00011111},
{0b00001110, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001110},
{0b00010000, 0b00001000, 0b00001000, 0b00000100, 0b00000100, 0b00000010, 0b00000010, 0b00000001},
{0b00001110, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00001110},
{0b00000100, 0b00001010, 0b00010001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111},
{0b00001000, 0b00000100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00010010, 0b00010010, 0b00010010, 0b00001111},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00011100, 0b00010010, 0b00010010, 0b00011100},
{0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00010000, 0b00010000, 0b00010000, 0b00001110},
{0b00000000, 0b00000001, 0b00000001, 0b00000001, 0b00000111, 0b00001001, 0b00001001, 0b00000111},
{0b00000000, 0b00000000, 0b00000000, 0b00011100, 0b00010010, 0b00011110, 0b00010000, 0b00001110},
{0b00000000, 0b00000011, 0b00000100, 0b00000100, 0b00000110, 0b00000100, 0b00000100, 0b00000100},
{0b00000000, 0b00001110, 0b00001010, 0b00001010, 0b00001110, 0b00000010, 0b00000010, 0b00001100},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00011100, 0b00010010, 0b00010010, 0b00010010},
{0b00000000, 0b00000000, 0b00000100, 0b00000000, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00000000, 0b00000010, 0b00000000, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00001100},
{0b00000000, 0b00010000, 0b00010000, 0b00010100, 0b00011000, 0b00011000, 0b00010100, 0b00010000},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00010101, 0b00010001, 0b00010001, 0b00010001},
{0b00000000, 0b00000000, 0b00000000, 0b00010100, 0b00011010, 0b00010010, 0b00010010, 0b00010010},
{0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00010010, 0b00010010, 0b00010010, 0b00001100},
{0b00000000, 0b00011100, 0b00010010, 0b00010010, 0b00011100, 0b00010000, 0b00010000, 0b00010000},
{0b00000000, 0b00001110, 0b00010010, 0b00010010, 0b00001110, 0b00000010, 0b00000010, 0b00000001},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00001100, 0b00001000, 0b00001000, 0b00001000},
{0b00000000, 0b00000000, 0b00001110, 0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00011110},
{0b00000000, 0b00010000, 0b00010000, 0b00011100, 0b00010000, 0b00010000, 0b00010000, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00010010, 0b00010010, 0b00010010, 0b00010010, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00010001, 0b00001010, 0b00000100},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00001010},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00001010, 0b00010001},
{0b00000000, 0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00001000, 0b00001000, 0b00010000},
{0b00000000, 0b00000000, 0b00000000, 0b00011111, 0b00000010, 0b00000100, 0b00001000, 0b00011111},
{0b00000010, 0b00000100, 0b00000100, 0b00000100, 0b00001000, 0b00000100, 0b00000100, 0b00000010},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00001000, 0b00000100, 0b00000100, 0b00000100, 0b00000010, 0b00000100, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00011110, 0b00010100, 0b00000000, 0b00000000}
};                  


void send_data(unsigned char tmp);
unsigned char DisplayBuffer[]={0,0,0,0,0,0,0,0};
unsigned int speed;
char i, l, k, ShiftAmount, scroll, temp, shift_step=1, StringLength;
char message[]="SCROLLING MESSAGE ON LED DOT-MATRIX DISPLAY FROM WWW.EMBEDDED-LAB.COM ";
char index;

void main()
{
  //unsigned int8 i,j,k;
  unsigned int16 cnt;
  unsigned char num, column, repeat, count;
  
  set_tris_b(0b00000000);           //all output 0b00000000
  set_tris_d(0b00000000);           //all output 0b00000000
  set_tris_e(0b00000001);           //PORTE bit 0 is input
  
  cnt = 0L;
  k = 0;
  output_b(0x00);
  output_d(0x00);
  StringLength = strlen(message) ;
   while(TRUE)
   {   
   
      //loops();
     for (k=0; k<StringLength; k++)
     {
      for (scroll=0; scroll<(8/shift_step); scroll++) 
      {
         for (ShiftAmount=0; ShiftAmount<8; ShiftAmount++)
         {
            index = message[k];
            temp = CharData[index-32][ShiftAmount];
            //DisplayBuffer[ShiftAmount] = temp;
            //DisplayBuffer[ShiftAmount] = (temp << shift_step)| (temp >> ((8-shift_step)-scroll*shift_step));
            DisplayBuffer[ShiftAmount] = (DisplayBuffer[ShiftAmount] << shift_step)| (temp >> ((8-shift_step)-scroll*shift_step));
         }

        speed = 5; //55;//+ADC_Read(0)/10;
        for(l=0; l<speed;l++)
        {

           for (i=0; i<8; i++) 
           {
               //send_data_serially(DisplayBuffer[i]);
               send_data(DisplayBuffer[i]);
               //send_data(CharData[i]);
               output_high(CD4017_CLK);
               output_low (CD4017_CLK);
               Delay_ms(1);
            }  // i
               output_high(CD4017_RST);//CD4017_RST = 1;
               output_low (CD4017_RST); //CD4017_RST = 0;
               for(i = 0; i < 8; i++)
               DisplayBuffer[i]=0;
         } // l
       } // scroll
      } // 
   }
}

void send_data(unsigned char tmp)
{
   unsigned int16 Flag;
   unsigned char t;
   unsigned int16 msk;
   msk = 0x0001;
  for (t=0; t<8; t++)
  {
      Flag = tmp & msk;
      if(Flag==0) output_low(SER_DATA);   //Serial_Data = 0;
      else output_high(SER_DATA);          //Serial_Data = 1;
      output_high(SH_CLK); //SH_CLK = 1;
      output_low(SH_CLK); //SH_CLK = 0;
      msk = msk << 1;
  }
  // Apply clock on ST_Clk
  output_high(ST_CLK);  //ST_CLK = 1;
  output_low (ST_CLK);  //ST_CLK = 0;

}
 

Attachments

  • Schematic.png
    Schematic.png
    67.4 KB · Views: 115

Gents,
Can anyone sends me or post a simple code in c (ccs c preferably) that I may test for 74HC595 and pic16f877A. My code as above is not currently working and I'm almost giving up.
Appreciate your help in advance.
:oops:
 

Gents,
I finally got something happening on my display.
However, how do I rotate message on a 16x8 dot matrix so it is scrolled from left to right or vice versa? I'm simulating my work using proteus.
A sample of my c code and schematic are as attached. Please note that I intentionally left out segment of the array for brevity's sake.

Code:
#include <16F877A.h>
#device adc=10
#include <string.h> 

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=20000000)

#BYTE PORT_B = 0X06     //define location of register port_b
#BYTE PORT_D = 0X08     //define location of register port_d
#BYTE TRIS_B = 0X86     //define location of register TRIS_B
#BYTE TRIS_D = 0X88     //define location of register TRIS_D
//#use FIXED_IO( D_outputs=PIN_D4,PIN_D3,PIN_D2,PIN_D1,PIN_D0 )
#define CLR          PIN_B0
#define Latch        PIN_B1
#define Data_In      PIN_B2
#define CLK          PIN_B3

const unsigned char CharData[95][8] ={
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001010, 0b00001010, 0b00001010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010},
{0b00000111, 0b00001100, 0b00010100, 0b00001100, 0b00000110, 0b00000101, 0b00000110, 0b00011100},
{0b00011001, 0b00011010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001011, 0b00010011},
...................................};//

void send_data(unsigned char tmp);
void Clear_Shift_Register();
void display_Message();

void main()
{     
      unsigned char count, column,num, repeat;
      TRIS_B = 0b00000000; // Set PORTB direction to be output
      TRIS_D = 0b00000000; // Set PORTB direction to be output
      PORT_B = 0b00000000; // Turn OFF LEDs on PORTB
      PORT_D = 0b00000000; // Turn OFF LEDs on PORTB
      
      //count = 0;
      Clear_Shift_Register();
   while(1)
   {
      //DO THE FOLLOWING
      display_Message();
    }
}


void Clear_Shift_Register()
{
      output_low (CLR);                       //Clear shift register
      output_high(CLR);                      //Clear shift register
}
void send_data(unsigned int16 tmp)
{
   unsigned int16 Flag;
   unsigned char t;
   unsigned int16 msk;
   msk = 0x001;
  for (t=0; t<16; t++)
  {
      Flag = tmp & msk;
      if(Flag==0) output_low(Data_In);    //Serial_Data = 0;
      else output_high(Data_In);           //Serial_Data = 1;
      output_high(CLK); //SH_CLK = 1;
      output_low(CLK); //SH_CLK = 0;
      msk = msk << 0x001;
  }
  // Apply clock on ST_Clk
  output_high(Latch);  //ST_CLK = 1;
  output_low (Latch);  //ST_CLK = 0;

}

void display_Message()
{
      unsigned char i, l, k, ShiftAmount, scroll, temp, shift_step=1, StringLength;
      unsigned char count, column,num, repeat;
      unsigned char index; 
      unsigned int speed;
      char message[]="SCROLLING MESSAGE ON LED DOT-MATRIX DISPLAY "; 
      StringLength = strlen(message); 
      
      for (k=0; k<StringLength; k++)
      {
         for (scroll=0; scroll<(8/shift_step); scroll++)
        {
         for (ShiftAmount=0; ShiftAmount<8; ShiftAmount++)
         {
            index = message[k];
            temp = CharData[index-32][ShiftAmount];
            DisplayBuffer[ShiftAmount] = (DisplayBuffer[ShiftAmount] << shift_step)| (temp >> ((8-shift_step)-scroll*shift_step));
         }

        speed = 10; 

        for(l=0; l<speed;l++)
        {
         for (repeat = 0; repeat <2; repeat++)
         {
           PORT_D =0x80;
           for (i=0; i< 8; i++)
           {
                send_data(~DisplayBuffer[i]);
               delay_ms(1);
               PORT_D =PORT_D >>1;
            } 
               Clear_Shift_Register();
         } // l
        }
       } // scroll
      } //
   }
 

Attachments

  • schem3.png
    schem3.png
    33.1 KB · Views: 94
  • schem4.png
    schem4.png
    44.1 KB · Views: 89

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top