728x90
반응형
SMALL
MAX7219로 알파벳 표시
#include <avr/io.h>
#define F_CPU 16000000UL // 16 MHz
#include <util/delay.h>
#define U08 unsigned char
#define CS_1 PORTC|=4 // PC2=1
#define CS_0 PORTC&=~4 // PC2=0
#define DIN_1 PORTC|=2 // PC1=1
#define DIN_0 PORTC&=~2 // PC1=0
#define CLK_1 PORTC|=1 // PC0=1
#define CLK_0 PORTC&=~1 // PC0=0
U08 Alphabet[156]={
0x7f,0x88,0x88,0x88,0x88,0x7f, // A
0x6e,0x91,0x91,0x91,0x91,0xff, // B
0x42,0x81,0x81,0x81,0x81,0x7E, // C
0x7e,0x81,0x81,0x81,0x81,0xff, // D
0x91,0x91,0x91,0x91,0xff,0x81, // E
0x80,0x90,0x90,0x91,0xff,0x81, // F
0x4e,0x89,0x89,0x81,0x81,0x7e, // G
0xff,0x10,0x10,0x10,0x10,0xff, // H
0x00,0x81,0xff,0xff,0x81,0x00, // I
0x00,0x80,0xfe,0x81,0x01,0x06, // J
0x81,0xc3,0x24,0x99,0xff,0x81, // K
0x03,0x01,0x01,0x81,0xff,0x81, // L
0xff,0x60,0x18,0x18,0x60,0xff, // M
0xff,0x06,0x08,0x10,0x60,0xff, // N
0x7e,0x81,0x81,0x81,0x81,0x7e, // O
0x70,0x88,0x88,0x89,0xff,0x81, // P
0x7e,0x87,0x89,0x85,0x81,0x7e, // Q
0x61,0x93,0x94,0x98,0x98,0xff, // R
0x4e,0x91,0x91,0x91,0x91,0x62, // S
0xc0,0x81,0xff,0xff,0x81,0xc0, // T
0xfe,0x01,0x01,0x01,0x01,0xfe, // U
0xfc,0x02,0x01,0x01,0x02,0xfc, // V
0xff,0x02,0x04,0x04,0x02,0xff, // W
0xc3,0x24,0x18,0x18,0x24,0xc3, // X
0xc0,0x20,0x1f,0x1f,0x20,0xc0, // Y
0xc3,0xa1,0x91,0x89,0x85,0xc3 // Z
};
void SPI_Wr_Byte(U08 num){
U08 t;
CLK_0;
for(t=0;t<8;t++){
if(num&(0x80>>t))
DIN_1;
else
DIN_0;
CLK_1;
CLK_0;}
}
void MAX7219_INIT(){
CS_0; SPI_Wr_Byte(0x09); SPI_Wr_Byte(0x00); CS_1; // Set BCD decode mode // Decode Mode // BCD mode
CS_0; SPI_Wr_Byte(0x0A); SPI_Wr_Byte(0x05); CS_1; // Set display brightness // Intensity register // Set brightness
CS_0; SPI_Wr_Byte(0x0B); SPI_Wr_Byte(0x07); CS_1; // Set display refresh // Scan-Limit register // Select digits DIG0-DIG3
CS_0; SPI_Wr_Byte(0x0C); SPI_Wr_Byte(0x01); CS_1; // Turn on the display
CS_0; SPI_Wr_Byte(0x0F); SPI_Wr_Byte(0x00); CS_1; // Disable Display-Test // Display-Test register // Disable Display-Test
}
void Write_Byte(U08 myColumn,U08 myValue){
CS_0; SPI_Wr_Byte(myColumn);
SPI_Wr_Byte(myValue);
CS_1;
}
void Clear_Matrix(void){ U08 x; for(x=1;x<9;x++)Write_Byte(x,0); }
void Write_Char(U08 myChar){
U08 Column,Start_Byte;
Clear_Matrix();
Start_Byte=(myChar-'A')*6;
for(Column=2;Column<8;Column++)Write_Byte(Column,Alphabet[Start_Byte++]);
}
int main(){
U08 x;
DDRC=0xFF; // GP3 is input only
MAX7219_INIT(); // initialize max7219
while(1){
for(x='A';x<='Z';x++){
Write_Char(x);
_delay_ms(1000);
}
}
}
728x90
반응형
LIST
'Embedded System > AVR' 카테고리의 다른 글
[AVR] JMOD-128-1 (0) | 2022.06.09 |
---|---|
[AVR] 타이머 (Timer) (0) | 2022.06.02 |
[AVR] Timing Diagram (0) | 2022.05.25 |
[AVR] MAX7219 (0) | 2022.05.25 |
[AVR] LED (0) | 2022.05.24 |