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.

[PIC] PIC+MAX7219 Dot matrix Led Display

Status
Not open for further replies.

HAMAYOUN AHMAD BHATTI

Junior Member level 1
Junior Member level 1
Joined
Jul 2, 2013
Messages
19
Helped
1
Reputation
2
Reaction score
0
Trophy points
1
Activity points
142
Hi
I am trying to interface PIC+MAX7219 Dot matrix Led Display.
but until now i can not build any library for 7219 display.:cry:
can anyone help me in building a library for PIC16f877a+MAX7219 Dot matrix Led Display.
 

Header:
Code:
#define CS														GPIOA, GPIO_Pin_2

#define MAX7219_NoOperation						0xA0
#define MAX7219_DecodeMode						0xA9
#define MAX7219_Intensity							0xAA
#define MAX7219_ScanLimit							0xAB
#define MAX7219_ShutDown							0xAC
#define MAX7219_DisplayTest						0xAF


typedef struct
{
	unsigned char DecodeMode;
	unsigned char Intensity;
	unsigned char ScanLimit;
	unsigned char ShutDown;
}MAX7219Init_TypeDef;

unsigned char MAX7219_Init (MAX7219Init_TypeDef * MAX7219_InitStruct);
void MAX7219_StructInit (MAX7219Init_TypeDef * MAX7219_InitStruct, unsigned char DigitsPerChip);
void MAX7219_DrawDigitSerial (unsigned char * Digit);
void MAX7219_DisplayTestVoid (unsigned char Enable);
void MAX7219_SetIntensity (unsigned char Intensity);
void MAX7219_Power (unsigned char PowerState);
void MAX7219_DrawCharSerial (unsigned char CHAR, const unsigned long (*FONT)[]);
and code:
Code:
#include "MAX7219.h"

#define MAX7219_SPI								SPI1		//interface definition
#define MAX7219_MaxCountValue			12			//maximum vaule of chips in serial to scan

/* You can manualy assign the value of chips in serialy connected here*/
unsigned char ChipsInSerial=8;	//otherwise search procedure will be needed and loop must be closed

unsigned char DigitsPerChip=8;

unsigned char MAX7219_WriteReg (unsigned char Reg, unsigned char Data);

unsigned char MAX7219_WriteReg (unsigned char Reg, unsigned char Data)
{
	unsigned char cnt=0;
	unsigned char tmp=0;
	
	if (ChipsInSerial==0) 
	{
		PIN_OFF(CS);
		for (tmp=0;tmp!=MAX7219_MaxCountValue;tmp++) SPI_SendByte(MAX7219_SPI, MAX7219_NoOperation);
		PIN_ON(CS);
		PIN_OFF(CS);
		tmp=0;
		while ((tmp!=Reg)&(cnt<MAX7219_MaxCountValue)) 
		{	
			tmp=SPI_ReadByte(MAX7219_SPI, Reg);
			SPI_SendByte(MAX7219_SPI, Data);
			cnt++;
		}
		PIN_ON(CS);
		ChipsInSerial = cnt-1;
	}
	else
	{
		PIN_OFF(CS);
		for (tmp=0;tmp!=ChipsInSerial;tmp++)
		{
			SPI_SendByte(MAX7219_SPI, Reg);
			SPI_SendByte(MAX7219_SPI, Data);
		}
		PIN_ON(CS);
	}
	return ChipsInSerial;
}

unsigned char MAX7219_Init (MAX7219Init_TypeDef * MAX7219_InitStruct)
{
	MAX7219_DisplayTestVoid(0);
	DigitsPerChip = MAX7219_InitStruct->ScanLimit+1;
	MAX7219_WriteReg(MAX7219_DecodeMode, MAX7219_InitStruct->DecodeMode);
	MAX7219_WriteReg(MAX7219_Intensity, MAX7219_InitStruct->Intensity);
	MAX7219_WriteReg(MAX7219_ScanLimit, MAX7219_InitStruct->ScanLimit);
	return MAX7219_WriteReg(MAX7219_ShutDown, MAX7219_InitStruct->ShutDown);
}

void MAX7219_StructInit (MAX7219Init_TypeDef * MAX7219_InitStruct, unsigned char DigitsPerChip)
{
	MAX7219_InitStruct->DecodeMode=0xFF;	//code B 0..7
	MAX7219_InitStruct->Intensity=8;	//0...16
	MAX7219_InitStruct->ScanLimit=(DigitsPerChip-1);
	MAX7219_InitStruct->ShutDown=1;
}

void MAX7219_DrawDigitSerial (unsigned char * Digit)
{
	unsigned char ChipCNT;
	unsigned char DigitCNT = DigitsPerChip;

	for (DigitCNT=0;  DigitCNT!=DigitsPerChip; DigitCNT++)
	{
		PIN_OFF(CS);
		for (ChipCNT=0; ChipCNT!=ChipsInSerial; ChipCNT++)
		{
				SPI_SendByte(MAX7219_SPI, (DigitCNT+1));
				SPI_SendByte(MAX7219_SPI, Digit[(ChipsInSerial-ChipCNT-1)*DigitsPerChip+DigitCNT]);			
		}
		PIN_ON(CS);
	}
}

void MAX7219_DisplayTestVoid (unsigned char Enable)
{
	MAX7219_WriteReg(MAX7219_DisplayTest, Enable);
}

void MAX7219_SetIntensity (unsigned char Intensity)
{
	MAX7219_WriteReg(MAX7219_Intensity, Intensity&0x0F);
}

void MAX7219_Power (unsigned char PowerState)
{
	MAX7219_WriteReg(MAX7219_ShutDown, PowerState);
}

void MAX7219_DrawCharSerial (unsigned char CHAR, const unsigned long (*FONT)[])
{
	unsigned char DigitArray[8];
	CHAR=CHAR<<1;
	DigitArray[0]=((*FONT)[CHAR]&0xFF000000)>>24;
	DigitArray[1]=((*FONT)[CHAR]&0x00FF0000)>>16;
	DigitArray[2]=((*FONT)[CHAR]&0x0000FF00)>>8;
	DigitArray[3]=((*FONT)[CHAR]&0x000000FF);
	DigitArray[4]=((*FONT+1)[CHAR]&0xFF000000)>>24;
	DigitArray[5]=((*FONT+1)[CHAR]&0x00FF0000)>>16;
	DigitArray[6]=((*FONT+1)[CHAR]&0x0000FF00)>>8;
	DigitArray[7]=((*FONT+1)[CHAR]&0x000000FF);
	MAX7219_DrawDigitSerial(DigitArray);
}
 
Thanks Easyrider83 for replying kindly also tel me about compiler???

- - - Updated - - -

Thanks for replying.
Sir tel me about best compiler for this code.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top