NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Programming SPI like LED-MATRIX Sure Electronics DE-DP14112

January 05, 2015
by ankush_karche
ankush_karche's Avatar

Hello,

Happy New Year to All, hope you had great holidays and have new affirmations for the new year.

I have got Sure Electronics LED Panel DE-DP14112 for 32x16 SPI like. As not much experienced not able to get idea from PIC code how it should be taken further with Nerdkit and ATMEGA-168.

There are loads of Arduino but I don't want it and doesn't understand at the moment.

Does anyone on this great forum have library and example code for the LED matrix ?

I have seen for 32x08 by Rick but there is little tweak for 32x16.

Thanks in advance for your help.

Regards, Ankush

January 05, 2015
by ankush_karche
ankush_karche's Avatar

or can anyone please give outline of the code?

January 06, 2015
by BobaMosfet
BobaMosfet's Avatar

Uses an HT3216C controller. It's SPI. Grab the datasheet from Google for this chip and it will tell you what the command structure is. Grab the datasheet for the Display itself, and it will tell you how to wire it.

BM

January 10, 2015
by ankush_karche
ankush_karche's Avatar

Hi BobMosfet,

Thanks for encouraging me.

I have referred to datasheet sample code from file http://www.robotmarketplace.com/products/images/0-E000013_manual.pdf

and written code like below.

Could experts review the code and let me know if it's right to go ahead ?

What about PWM,DAT, RB1, RB2 ? What is

Not able to unserstand about SPI_ModelConfigure()

Code is as below

Your help is highly appreciated.

Thanks. Ankush

#define F_CPU 14745600

#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "5x8font.h"
#include "delay.h"
#include "ht1632c.h"

#define SPI_SS                     PB2 
#define SPI_SS_PORT                PORTB 
#define SPI_SS_PIN                 PINB 
#define SPI_SS_DDR                 DDRB

#define SPI_MOSI                     PB3 
#define SPI_MOSI_PORT                PORTB 
#define SPI_MOSI_PIN                 PINB 
#define SPI_MOSI_DDR                 DDRB

#define SPI_MISO                     PB4 
#define SPI_MISO_PORT                PORTB 
#define SPI_MISO_PIN                 PINB 
#define SPI_MISO_DDR                 DDRB

#define SPI_SCK                     PB5
#define SPI_SCK_PORT                PORTB
#define SPI_SCK_PIN                 PINB
#define SPI_SCK_DDR                 DDRB

#define HT1632_ID_CMD 4     /* ID = 100 - Commands */
#define HT1632_ID_RD  6     /* ID = 110 - Read RAM */
#define HT1632_ID_WR  5     /* ID = 101 - Write RAM */
#define HT1632_ID_BITS (1<<2)   /* IDs are 3 bits */

#define HT1632_CMD_SYSDIS 0x00  /* CMD= 0000-0000-x Turn off oscil */
#define HT1632_CMD_SYSON  0x01  /* CMD= 0000-0001-x Enable system oscil */
#define HT1632_CMD_LEDOFF 0x02  /* CMD= 0000-0010-x LED duty cycle gen off */
#define HT1632_CMD_LEDON  0x03  /* CMD= 0000-0011-x LEDs ON */
#define HT1632_CMD_BLOFF  0x08  /* CMD= 0000-1000-x Blink ON */
#define HT1632_CMD_BLON   0x09  /* CMD= 0000-1001-x Blink Off */
#define HT1632_CMD_SLVMD  0x10  /* CMD= 0001-00xx-x Slave Mode */
#define HT1632_CMD_MSTMD  0x14  /* CMD= 0001-01xx-x Master Mode */
#define HT1632_CMD_RCCLK  0x18  /* CMD= 0001-10xx-x Use on-chip clock */
#define HT1632_CMD_EXTCLK 0x1C  /* CMD= 0001-11xx-x Use external clock */
#define HT1632_CMD_COMS00 0x20  /* CMD= 0010-ABxx-x commons options */
#define HT1632_CMD_COMS01 0x24  /* CMD= 0010-ABxx-x commons options */
#define HT1632_CMD_COMS10 0x28  /* CMD= 0010-ABxx-x commons options */
#define HT1632_CMD_COMS11 0x2C  /* CMD= 0010-ABxx-x commons options */
#define HT1632_CMD_PWM    0xA0  /* CMD= 101x-PPPP-x PWM duty cycle */
#define HT1632_CMD_BITS (1<<7)

#define CHIP_MAX 4 //Four HT1632Cs on one board
#define CLK_DELAY _delay_ms(900);

#PWM_10

void SystemInit(void); //System Initialization
void SetHT1632C_As3208(void); //Set HT1632Cs work on mode 32*8
void OutputCLK_Pulse(void); //CLK pin outputs a clock pulse
void OutputA_74164(unsigned char x); //CS pin output a level
void ChipSelect(int select); //Chip selection
void CommandWriteHT1632C(unsigned int command); //Write command to ALL HT1632Cs

void AddressWriteHT1632C(unsigned char address);//Write Address to HT1632Cs
void SPI_ModelConfigure(void);
void SPI_DataSend(const unsigned char data);

void main()
{
unsigned char i, j;
SystemInit(); //System Initialization
SetHT1632C_As3208(); //Set all HT1632Cs to work in 32*8 master mode

for(i=1; i<=CHIP_MAX; i++)
 {
   ChipSelect(1); //Chip select the corresponding HT1632C
   AddressWriteHT1632C(0x00); //Get the selected start address of the chip

   //SPI_ModelConfigure(); //Open SPI mode, continuously send data to HT1632C
    for(j=0; j<32; j++) //Take “0x00” as the start address, continuously write data
    {
      SPI_DataSend(0xaa); //Write data as 0xaa
     }
    while(1);
}

/**************************************************************************************************
//Function Name: system initialization
//Function Feature: set corresponding data reading and writing of PORTB and PORTC
//Input Argument: void
//Output Argument: void
//**************************************************************************************************/
void SystemInit(void)
{
SPI_SS_DDR |= (1<=SPI_SS) ; /* SS Output */
  SPI_SS_PORT |= (1<= SPI_SS) ; /* start of  not selected (high) */

  SPI_MOSI_DDR |= (1<=SPI_MOSI); // Output on 
  SPI_MISO_PORT |= (1<=SPI_MISO); //Output
  SPI_SCK_DDR |= (1<=SPI_SCK);  //

  SPCR |= ( 1<< SPR1);  // div 16
  SPCR |= ( 1<< MSTR);  // clockmaster
  SPCR |= ( 1<< SPE);  // enable

}
//**************************************************************************************************
//Function Name: SetHT1632C_As3208
//Function Feature: write basic configuration to HT1632C in command words
//Input Argument: void
//Output Argument: void
//**************************************************************************************************
void SetHT1632C_As3208(void)
{
CommandWriteHT1632C(SYS_EN); //Enable system oscillator
CommandWriteHT1632C(LED_ON); //Turn on LED
CommandWriteHT1632C(RC_MASTER_MODE); //Select on-chip RC as the
clock’s master mode. Select this sentence when HT1632C is changed.
CommandWriteHT1632C(N_MOS_COM8); //N-MOS open-drain output
//and 32 ROW * 8 COM
CommandWriteHT1632C(PWM_10); //PWM 10/16 duty
}
//**************************************************************************************************
//Function Name: OutputCLK_Pulse
//Function Feature: enable CLK_74164 pin to output a clock pulse
//Input Argument: void
//Output Argument: void
//**************************************************************************************************
void OutputCLK_Pulse(void) //Output a clock pulse
{
CLK_74164 = 1;
CLK_DELAY;
CLK_74164 = 0;
CLK_DELAY;
}
//**************************************************************************************************
//Function Name: OutputA_74164
//Function Feature: enable pin A of 74164 to output 0 or 1
//Input Argument: x: if x=1, 74164 outputs high. If x??1, 74164 outputs low.
//Output Argument: void
//**************************************************************************************************
void OutputA_74164(unsigned char x) //Input a digital level to 74164
{
if(x==1)
{
A_74164 = 1;
CLK_DELAY;
}
else
{
A_74164 = 0;
CLK_DELAY;
}
}
//**************************************************************************************************
//Function Name: CommandWriteHT1632C
//Function Feature: Write control commands to all HT1632Cs
//Input Argument: command words written to “command”, specifically stated in “declare”
//function
//Output Argument: void
//Argument Description: compile control commands to all external HT1632Cs for the
//requirement of the project
//**************************************************************************************************
void CommandWriteHT1632C(unsigned int command)
{
unsigned char i;
unsigned int j;
command = command & 0x0fff; //12-bit command word, mask upper four bits
ChipSelect(0); //Disable all HT1632Cs
CLK_DELAY;
ChipSelect(-1); //Enable all HT1632Cs
CLK_DELAY;
for(i=0; i<12; i++) //Write command words in HI1632C register
{
CLK = 0;
CLK_DELAY;
j = command & 0x0800; //Return the MSB
command = command << 1; //Move the control character to the left one
j = j >> 11; //Position the value at the LSB
DAT = j; //Send the value to the data port
CLK_DELAY;
CLK = 1; //Data transmission (data valid on rising edge)
CLK_DELAY;
}
ChipSelect(0); //Disable all HT1632Cs
}
//**************************************************************************************************
//Function Name: AddressWriteHT1632C
//Function Feature: write start address of data to HT1632Cs
//Input Argument: address: address to be written
//Output Argument: void
//**************************************************************************************************
void AddressWriteHT1632C(unsigned char address)
{
unsigned char i,temp;
SSPCON = 0x11;
address = address & 0x7f; //7-bit address, mask the MSB
Appendix
?? 2004-2009 DE-DP14112&DE-DP14211_Ver1.1_Page 20 Sure Electronics Inc
CLK = 0; //Clock line is 0
CLK_DELAY;
DAT = 1; //Send “1” to data port
CLK_DELAY;
CLK = 1; //Data transmission
CLK_DELAY;
CLK = 0;
CLK_DELAY;
DAT = 0; //Send “0” to data port
CLK_DELAY;
CLK = 1; //Data transmission
CLK_DELAY;
CLK = 0;
CLK_DELAY;
DAT = 1; //Send “1” to data port
CLK_DELAY;
CLK = 1; //Data transmission
CLK_DELAY;
for(i=0; i<7; i++) //Write “address” to HT1632C register
{
CLK = 0; //Clock line is 0
CLK_DELAY;
temp = address & 0x40; //Return the MSB
address = address << 1; //Move the control character to the left one
temp = temp >> 6; //Position the value at the LSB
DAT = temp; //Send the value to the data port
CLK_DELAY;
CLK = 1; //Data transmission
CLK_DELAY;
}
}
//**************************************************************************************************
//Function Name: ChipSelect
//Function Feature: enable HT1632C
//Input Argument: select: HT1632C to be selected
// If select=0, select none.
// If s<0, select all.
//Output Argument: void
//**************************************************************************************************
void ChipSelect(int select)
{
unsigned char tmp = 0;
if(select<0) //Enable all HT1632Cs
{

OutputA_74164(0);
CLK_DELAY;
for(tmp=0; tmp<CHIP_MAX; tmp++)
{
 OutputCLK_Pulse();
}
}
 else if(select==0) //Disable all HT1632Cs
{
 OutputA_74164(1);
 CLK_DELAY;
for(tmp=0; tmp<CHIP_MAX; tmp++)
{
 OutputCLK_Pulse();
}
}
 else
{
OutputA_74164(1);
CLK_DELAY;
for(tmp=0; tmp<CHIP_MAX; tmp++)
{
OutputCLK_Pulse();
}
OutputA_74164(0);
CLK_DELAY;
OutputCLK_Pulse();
CLK_DELAY;
OutputA_74164(1);
CLK_DELAY;
tmp = 1;
for( ; tmp<select; tmp++)
{
OutputCLK_Pulse();
}
}
}
//**************************************************************************************************
//Function Name: SPI_ModelConfigure
//Function Feature: configure the corresponding data transfer port of  microcontroller
//for SPI communication
//Input Argument: void
//Output Argument: void
//**************************************************************************************************
Appendix
void SPI_ModelConfigure(void)
{

}
//**************************************************************************************************
//Function Name: SPI_DataSend
//Function Feature: transmit data in SPI mode of  microcontroller
//Input Argument: data: bytes of data to be transmitted
//Output Argument: void
//**************************************************************************************************
void SPI_DataSend(const unsigned char data)
{

// Load data into the buffer
    SPDR = data;

    //Wait until transmission complete
    while(!(SPSR)&(1<<SPIF));

    // Return received data
     return(SPDR);

}

Post a Reply

Please log in to post a reply.

Did you know that an electroluminescent backlight for an LCD panel requires hundreds of volts AC to run? Learn more...