RGB LED MAX7219 PIC18F4550


usb - MAX7219 Test Software


OS : Windows 9x/2000/XP (etc)
Compiler : VC++ 6
//---------------------------------------------------------------------------

#include <stdio.h>
#include "windows.h"
#include "mpusbapi.h"                   // MPUSBAPI Header File

//---------------------------------------------------------------------------
// Global Vars
char vid_pid[]= "vid_04d8&pid_000c";    // Default Demo Application Firmware
char out_pipe[]= "\\MCHP_EP1";
char in_pipe[]= "\\MCHP_EP1";

DWORD temp;

HINSTANCE libHandle;
HANDLE myOutPipe;
HANDLE myInPipe;

//---------------------------------------------------------------------------
// Prototypes
void GetSummary(void);
void LoadDLL(void);
void GetUSBDemoFWVersion(void);
DWORD SendReceivePacket(BYTE *SendData, DWORD SendLength, BYTE *ReceiveData,
                    DWORD *ReceiveLength, UINT SendDelay, UINT ReceiveDelay);
void CheckInvalidHandle(void);

//Custom Functions
void Raw7219(BYTE addr,BYTE data);
void LoadHigh();
int SendString(BYTE *send_buf,BYTE len);
void MakeRGBMap(BYTE *map, char *string);


#include "io_cfg.h"
#include "usb.h"

int main(int argc, char* argv[])
{
    if(argc <= 2)
	{
		printf("\r\n- USAGE : mdb.exe <id><len><string>");
		return 1;
	}
	
	
	BOOLEAN bQuit;
    DWORD selection=7;
    bQuit = false;

    // Load DLL when it is necessary, i.e. on start-up!
    LoadDLL();
	LoadMap();
	
	setRGB[0][0]=&setR1Col;
	setRGB[0][1]=&setR2Col;
	setRGB[0][2]=&setR3Col;
	setRGB[0][3]=&setR4Col;

	setRGB[1][0]=&setG1Col;
	setRGB[1][1]=&setG2Col;
	setRGB[1][2]=&setG3Col;
	setRGB[1][3]=&setG4Col;

	setRGB[2][0]=&setB1Col;
	setRGB[2][1]=&setB2Col;
	setRGB[2][2]=&setB3Col;
	setRGB[2][3]=&setB4Col;


    // Always a good idea to initialize the handles
    myOutPipe = myInPipe = INVALID_HANDLE_VALUE;

	int i,j;
	BYTE color,rg_b,b_b;
	char string[23];
	printf("Enter the string to be displayed : ");
	gets(string);
	printf("Enter the color : \n");
	printf(" 1. Red \n");
	printf(" 2. Green \n");
	printf(" 4. Blue \n");
	printf("  : > ");
	scanf("%d", &color);

	printf("Displaying %s with colour %d ",string,color);
	printf("RG,B Brightness [0-15] : ");
	scanf("%d%d",&rg_b,&b_b);
//g_b=b_b=15;
	//strcpy(string,"11");
	//string[1]=255;
	//string[1]='+';
	//string[1]=0;
	BYTE send_buf[64];
	const int num_boards = 8;
	int offset=0;
	//color=7;

	while(1)

	{
	
		//for(string[0]='A';string[0]<='Z';string[0]++,color++)
	
		{
	i=0;
	color%=8;
	if(!color)color=1;
	//ClearBuffer(send_buf,64);
	ClearAll7219();
	BYTE ic1=0,ic2=num_boards>>1;
	
	int k=0,p=offset;
	while(string[i])
	{	
		while(map[string[i]][k?k-1:0])
		{
			if(ic2 == 32)goto EOI;
			
			if(p >= 0)
			{
				(*setRGB[0][(p)%4])(ic1,ic2,(color & 1)?map[string[i]][k]:0);
				(*setRGB[1][(p)%4])(ic1,ic2,(color & 2)?map[string[i]][k]:0);
				(*setRGB[2][(p)%4])(ic1,ic2,(color & 4)?map[string[i]][k]:0);

				if(p && p%4==0)
				{
					ic1++;
					ic2++;
				}
				
			}
			k++;
			p++;
		}

		i++;
		k=0;
	}

EOI:
	{
	
		
		InitMax7219(num_boards,send_buf,rg_b,b_b);

		
		for(j=0;j<4;j++)
		{
			Shift7219(offset-1);
			
			for(int n=0;n<num_boards;n++)
			{
				if(num_boards-n-1 == 4)
					max[num_boards-n-1].exportByteInverse(j,send_buf+2+4*n);
				else if((num_boards-n-1 == 5) || (num_boards-n-1 == 6))
					max[num_boards-n-1].exportByteHalfInverse(j,send_buf+2+4*n);
				else
					max[num_boards-n-1].exportByte(j,send_buf+2+4*n);
				
			}
			
			SendString(send_buf,num_boards*4);
		}
		
		
		Sleep(300);
		//offset--;
		
	}
	//for(i=2;i<2+32;i++)
	//	printf("%02x ",send_buf[i]);
	//printf("\n");
	}	}
    
	// Always check to close all handles before exiting!
    if (myOutPipe != INVALID_HANDLE_VALUE) MPUSBClose(myOutPipe);
    if (myInPipe != INVALID_HANDLE_VALUE) MPUSBClose(myInPipe);
    myOutPipe = myInPipe = INVALID_HANDLE_VALUE;

    // Always check to close the library too.
    if (libHandle != NULL) FreeLibrary(libHandle);

    return 0;
}//end main
Download the entire project (with dsw and dsp) here

Comments

Submit

Name
Comment
4 / 2 =
 

Recent Comments