- Dapatkan link
- X
- Aplikasi Lainnya
Pengetahuan dasar Pemrograman Led Matrix
Scan
Untuk menampilkan karakter ke sebuah segment kita harus menyalakan led per kolom secara bergantian(scanning) terus menerus. Karena frekwensi scanning cepat sehingga semua led terlihat seolah menyala bersamaan.

untuk karakter A maka kode untuk tiap kolom yg akan di scan adalah
kolom ke-1=0x7E , ke-2 : 0x09, ke-3 :0x09, ke-4: 0x7E, & kolom ke-5:0x7E
step/urutan menampilkan huruf A
kirim 0x7E aktifkan kolom ke-1
kirim 0x09 aktifkan kolom ke-2
kirim 0x09 aktifkan kolom ke-3
kirim 0x7E aktifkan kolom ke-4
berikut Contoh Program
/*****************************************************
Chip type : ATmega16
Program type : Application
Clock frequency : 11,059200 MHz
*****************************************************/
Chip type : ATmega16
Program type : Application
Clock frequency : 11,059200 MHz
*****************************************************/
#include <mega16.h>
#include <delay.h>
// External Interrupt 0 service routine
unsigned short count, column, num, repeat,i;
unsigned char data[4]={‘A’,’B’,’C’,’0′};
void displayLEDmatrix(char huruf);
#include <delay.h>
// External Interrupt 0 service routine
unsigned short count, column, num, repeat,i;
unsigned char data[4]={‘A’,’B’,’C’,’0′};
void displayLEDmatrix(char huruf);
// Declare your global variables here
unsigned short Alphabets[130]={ 0x7E, 0x09, 0x09, 0x7E, 0xFF, // A
0x7f, 0x49, 0x49, 0x49, 0x36, // B
0x3e, 0x41, 0x41, 0x41, 0x22, // C
0x7f, 0x41, 0x41,0x22, 0x1c,
0x7f, 0x49, 0x49, 0x49, 0x63,
0x7f, 0x09, 0x09, 0x09, 0x01,
0x3e, 0x41, 0x41, 0x49, 0x7a,
0x7f, 0x08, 0x08, 0x08, 0x7f,
0x00, 0x41, 0x7f, 0x41, 0x00, // I
0x20, 0x40, 0x41, 0x3f, 0x01,
0x7f, 0x08, 0x14, 0x22, 0x41,
0x7f, 0x40, 0x40, 0x40, 0x60,
0x7f, 0x02, 0x04, 0x02, 0x7f,
0x7f, 0x04, 0x08, 0x10, 0x7f,
0x3e, 0x41, 0x41, 0x41, 0x3e,
0x7f, 0x09, 0x09, 0x09, 0x06,
0x3e, 0x41, 0x51, 0x21, 0x5e,
0x7f, 0x09, 0x19, 0x29, 0x46,
0x46, 0x49, 0x49, 0x49, 0x31, // S
0x01, 0x01, 0x7f, 0x01, 0x01,
0x3f, 0x40, 0x40, 0x40, 0x3f,
0x1f, 0x20, 0x40, 0x20, 0x1f,
0x3f, 0x40, 0x30, 0x40, 0x3f,
0x63, 0x14, 0x08, 0x14, 0x63,
0x07, 0x08, 0x70, 0x08, 0x07,
0x61, 0x51, 0x49, 0x45, 0x43 // Z
};
unsigned short Alphabets[130]={ 0x7E, 0x09, 0x09, 0x7E, 0xFF, // A
0x7f, 0x49, 0x49, 0x49, 0x36, // B
0x3e, 0x41, 0x41, 0x41, 0x22, // C
0x7f, 0x41, 0x41,0x22, 0x1c,
0x7f, 0x49, 0x49, 0x49, 0x63,
0x7f, 0x09, 0x09, 0x09, 0x01,
0x3e, 0x41, 0x41, 0x49, 0x7a,
0x7f, 0x08, 0x08, 0x08, 0x7f,
0x00, 0x41, 0x7f, 0x41, 0x00, // I
0x20, 0x40, 0x41, 0x3f, 0x01,
0x7f, 0x08, 0x14, 0x22, 0x41,
0x7f, 0x40, 0x40, 0x40, 0x60,
0x7f, 0x02, 0x04, 0x02, 0x7f,
0x7f, 0x04, 0x08, 0x10, 0x7f,
0x3e, 0x41, 0x41, 0x41, 0x3e,
0x7f, 0x09, 0x09, 0x09, 0x06,
0x3e, 0x41, 0x51, 0x21, 0x5e,
0x7f, 0x09, 0x19, 0x29, 0x46,
0x46, 0x49, 0x49, 0x49, 0x31, // S
0x01, 0x01, 0x7f, 0x01, 0x01,
0x3f, 0x40, 0x40, 0x40, 0x3f,
0x1f, 0x20, 0x40, 0x20, 0x1f,
0x3f, 0x40, 0x30, 0x40, 0x3f,
0x63, 0x14, 0x08, 0x14, 0x63,
0x07, 0x08, 0x70, 0x08, 0x07,
0x61, 0x51, 0x49, 0x45, 0x43 // Z
};
void main(void)
{
// Declare your local variables here
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTA=0x7F;
DDRA=0xFF;
// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTA=0x7F;
DDRA=0xFF;
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=1 State2=1 State1=1 State0=1
PORTB=0x0F;
DDRB=0xFF;
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=1 State2=1 State1=1 State0=1
PORTB=0x0F;
DDRB=0xFF;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=P State2=P State1=P State0=P
PORTD=0x0F;
DDRD=0x00;
// Global enable interrupts
#asm(“sei”)
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=P State2=P State1=P State0=P
PORTD=0x0F;
DDRD=0x00;
// Global enable interrupts
#asm(“sei”)
while (1){
// huruf A mulai index array 0-5
//huruf B mulai index array 6-11
//dst
// huruf A mulai index array 0-5
//huruf B mulai index array 6-11
//dst
for(i=0;i<5;i++ )
{
{
displayLEDmatrix(data[i]);
}
};
}
void displayLEDmatrix(char huruf)
{
//=====================
num=huruf-65;
// Display 26 alphabets
}
void displayLEDmatrix(char huruf)
{
//=====================
num=huruf-65;
// Display 26 alphabets
for (repeat=0; repeat<100; repeat++)
{
column = 1;
for(count = num*5;count < (num*5+6);count++) //num=0,5,10,15,dst…
{
PORTB = ~Alphabets[count];
PORTA = column;
delay_ms(5);
column = column<<1;
}
}
delay_ms(10);
{
column = 1;
for(count = num*5;count < (num*5+6);count++) //num=0,5,10,15,dst…
{
PORTB = ~Alphabets[count];
PORTA = column;
delay_ms(5);
column = column<<1;
}
}
delay_ms(10);
//=====================
}
}

Komentar
Posting Komentar