Você está na página 1de 5

MY PROJECT

PROPOSAL PIC16F876A
SCEMATIC

SOUCRE CODE
/*
'*******************************************************************************
' Project name: PIC16F876A & MAX7219 For 8x8 LED Display
' Description:
'
Trough the current experiment we wish to succed the next task:
'
Display on 8x8 Led matrix, the alphabet. The sequence between letters,
'
will have one second delay.
' Written by:
'
Mark &
'
Aureliu Raducu Macovei, 2011.
' Test configuration:
'
MCU:
PIC16F876A;
'
Test.Board:
WB-106 Breadboard 2420 dots;
'
SW:
MikroC PRO for PIC 2011 (version v4.60);
' Configuration Word:
'
Oscillator:
HS (8Mhz)on pins 9 and 10;
'
Watchdog Timer:
OFF;
'
Power up Timer:
OFF;
'
Browun Out Detect:
ON;
'
Low Voltage Program:
Disabled;
'
Data EE Read Protect:
OFF;
'
Flash Program Write:
Write Protection OFF;
'
Background Debug:
Disabled;
'
Code Protect:
OFF
'*******************************************************************************
*/
// For more space, we don't need byte 0 and byte 7.
// We have stripped them out, if/when we have a need and a bigger PIC,
// then we can put them back if we want.
// Here we define row values for each of the six
// Alphabet, from A through Z.
unsigned const short Alphabet[156]={
0x7f, 0x88,
0xff, 0x91,
0x7e, 0x81,
0xff, 0x81,
0x81, 0xff,
0x81, 0xff,
0x7e, 0x81,
0xff, 0x10,
0x00, 0x81,
0x06, 0x01,
0x81, 0xff,
0x81, 0xff,
0xff, 0x60,
0xff, 0x60,
0x7e, 0x81,
0x81, 0xff,
0x7e, 0x81,

columns corresponding to the

0x88,
0x91,
0x81,
0x81,
0x91,
0x91,
0x81,
0x10,
0xff,
0x81,
0x99,
0x81,
0x18,
0x10,
0x81,
0x89,
0x85,

0x88,
0x91,
0x81,
0x81,
0x91,
0x90,
0x89,
0x10,
0xff,
0xfe,
0x24,
0x01,
0x18,
0x08,
0x81,
0x88,
0x89,

0x88,
0x91,
0x81,
0x81,
0x91,
0x90,
0x89,
0x10,
0x81,
0x80,
0xc3,
0x01,
0x60,
0x06,
0x81,
0x88,
0x87,

0x7f,
0x6e,
0x42,
0x7e,
0x91,
0x80,
0x4e,
0xff,
0x00,
0x00,
0x81,
0x03,
0xff,
0xff,
0x7e,
0x70,
0x7e,

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q

0xff,
0x62,
0xc0,
0xfe,
0xfc,
0xff,
0xc3,
0xc0,
0xc3,
};

0x98,
0x91,
0x81,
0x01,
0x02,
0x02,
0x24,
0x20,
0x85,

0x98,
0x91,
0xff,
0x01,
0x01,
0x04,
0x18,
0x1f,
0x89,

0x94,
0x91,
0xff,
0x01,
0x01,
0x04,
0x18,
0x1f,
0x91,

0x93,
0x91,
0x81,
0x01,
0x02,
0x02,
0x24,
0x20,
0xa1,

0x61,
0x4e,
0xc0,
0xfe,
0xfc,
0xff,
0xc3,
0xc0,
0xc3,

//
//
//
//
//
//
//
//
//

R
S
T
U
V
W
X
Y
Z

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

(
)
[
]
{
}
<
>
/
\

unsigned const short Symbols[114]={


0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x60,
0x42,
0x24,
0x62,
0x66,
0x42,
0x20,
};

0x3c,
0x00,
0x00,
0x00,
0x18,
0x00,
0x18,
0x81,
0x03,
0xc0,
0x00,
0x00,
0x80,
0x24,
0xff,
0x91,
0x99,
0xa4,
0x3f,

0x42,
0x81,
0xff,
0x81,
0xe7,
0x81,
0x24,
0x42,
0x0c,
0x30,
0x00,
0xfd,
0x8d,
0xff,
0x24,
0xff,
0x99,
0x48,
0x20,

// Serial 8x8 Matrix Display connections.


sbit Chip_Select at RC0_bit;
sbit Chip_Select_Direction at TRISC0_bit;
// End Serial 8x8 Matrix Display connections.

0x81,
0x42,
0x81,
0xff,
0x81,
0xe7,
0x42,
0x24,
0x30,
0x0c,
0x00,
0xfd,
0x8d,
0xff,
0x24,
0xff,
0x66,
0x12,
0x20,

// Here we set the configuration of max7219.


void max7219_init1()
{
Chip_Select = 0;
// SELECT MAX
SPI1_write(0x09);
// BCD mode for digit decoding
SPI1_write(0x00);
Chip_Select = 1;
// DESELECT MAX
Chip_Select = 0;
SPI1_write(0x0A);
SPI1_write(0x0F);
Chip_Select = 1;

// SELECT MAX

Chip_Select = 0;
SPI1_write(0x0B);
SPI1_write(0x07);
Chip_Select = 1;

// SELECT MAX

Chip_Select = 0;
SPI1_write(0x0C);

// SELECT MAX

// Segment luminosity intensity


// DESELECT MAX

// Display refresh
// DESELECT MAX

0x00,
0x3c,
0x00,
0x00,
0x00,
0x18,
0x81,
0x18,
0xc0,
0x03,
0x00,
0x00,
0x90,
0x24,
0xff,
0x91,
0x09,
0x25,
0x3e,

0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x60,
0x42,
0x24,
0x4e,
0x00,
0x42,
0x21,

!
?
*
#
$
&
%
pi

SPI1_write(0x01);
Chip_Select = 1;

// Turn on the display


// DESELECT MAX

Chip_Select = 0;
SPI1_write(0x00);
SPI1_write(0xFF);
Chip_Select = 1;
}

// SELECT MAX
// No test
// DESELECT MAX

// This is write Byte function.


void Write_Byte(unsigned short myColumn, unsigned short myValue)
{
Chip_Select = 0;
// select max7219.
SPI1_write(myColumn); // send myColumn value to max7219 (digit place).
SPI1_write(myValue);
// send myValue value to max7219 (digit place).
Chip_Select = 1;
// deselect max7219.
}
// This is clear matrix function.
void Clear_Matrix(void)
{
unsigned short x;
for(x=1;x<9;x++)
{
Write_Byte(x,0x00);
}
}
void Write_Char(char myChar)
{
unsigned short Column, Start_Byte;
// We will use only uppercase characters, so we will start from 65
// (look at the ascii chart), with an offset of 6, becouse we are using only 6
// bytes for each character.
// Clear the display first.
Clear_Matrix();
// The next line defines our byte, from which to start the array.
Start_Byte = (myChar - 65) * 6;
// 65 represents the letter "A" in ASCII code.
// We are using only columns from 2 through 7 for displaying the character.
for(Column=2;Column<8;Column++)
{
Write_Byte(Column, Alphabet[Start_Byte++]);
}
}
// This is write char function.
void Write_Symbol(char mysymbols)
{
unsigned short Column1, Start_Byte1;
// We will use only uppercase characters, so we will start from 65
// (look at the ascii chart), with an offset of 6, becouse we are using only 6
// bytes for each character.
// Clear the display first.

Clear_Matrix();
// The next line defines our byte, from which to start the array.
Start_Byte1 = (mysymbols-0) * 6 ;
// We are using only columns from 2 through 7 for displaying the character.
for(Column1=2;Column1<8;Column1++)
{
Write_Byte(Column1, Symbols[Start_Byte1++]);
}
}
// Here we have the main function.
void main()
{
unsigned int x,y;
Chip_Select_Direction = 0;
SPI1_init();

// Set RC0 pin as output.


// Initialize SPI1 module.

max7219_init1();

// initialize

do
{

// infinite loop.

max7219.

// You can write the characters this way, one at a time.


/*
Write_Char('R');
Delay_ms(1000);
Write_Char('A');
Delay_ms(1000);
Write_Char('D');
Delay_ms(1000);
Write_Char('U');
Delay_ms(1000);
*/
// or
for(x=65;x<=90;x++)
{
Write_Char(x);
Delay_ms(1000);
}
Clear_Matrix();
delay_ms(500);

// Increment with 1, from 65 until 90.

// This is our delay, between two consecutive character.

// Clear the Matrix display;

for(y=0;y<=18;y++)
{
Write_Symbol(y);
Delay_ms(1000);
}

// This is our delay, between two consecutive character.

}while(1);

// do forever.

Você também pode gostar