Pengetahuan dasar Pemrograman Led Matrix

Scan

ledmatrix

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.

ledmatrix2.jpg

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
*****************************************************/

#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);

// 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
};

void main(void)
{
// 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 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;

// 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;

// 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”)

while (1){
// 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

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);

//=====================
}

Advertisements

About pccontrol

Berisi Tutorial Menggunakan PC untuk mengontrol Peralatan dengan cara mudah & praktis untuk pemula.

Posted on 11/02/2016, in AVR, Daftar isi, Pemrograman C untuk AVR dgn CodeVision. Bookmark the permalink. 2 Comments.

  1. untuk mentranfer data ke banyak kolom gmna z ms. sya pake driver ic cd4017 dan HC595 menggunakan arduino uno. dngn program seprti ini.Dasar C Arduino

    int latchPin = 10;
    int clockPin = 13;
    int dataPin = 11;
    int clock = 9;
    int Reset = 8;
    int latchPinPORTB = latchPin – 8;
    int clockPinPORTB = clockPin – 8;
    int dataPinPORTB = dataPin – 8;
    int i = 0;
    long scrolling_word[16];
    int array_turn=0;
    byte your_text[26][9]={BS,BE,BL,BA,BM,BA,BT,SPC,BD,BA,BT,BA,BN,BG,SPC,BD,ii,SPC,BJ,a,v,a,SPC,BN,e,tt};//MASUKAN TEKS MU DI SINI

    void setup(){
    Serial.begin(9600);
    pinMode(dataPin,OUTPUT);
    pinMode(clockPin,OUTPUT);
    pinMode(latchPin,OUTPUT);
    pinMode(clock,OUTPUT);
    pinMode(Reset,OUTPUT);
    digitalWrite(Reset,HIGH);
    digitalWrite(Reset,LOW);
    setupSPI();
    }

    void display_word(int loops,byte word_print[][9],int num_patterns,int delay_langth){// this function displays your symbols
    i = 0;// resets the counter fot the 4017
    for(int g=0;g<9;g++)//resets the the long int where your word goes
    scrolling_word[g] = 0;
    for(int x=0;x<num_patterns;x++){//main loop, goes over your symbols
    // you will need to find a better way to make the symbols scroll my way is limited for 24 columns

    for(int r=0;r<9;r++)//puts the buildes the first symbol
    scrolling_word[r] |= word_print[x][r];
    for (int z=0;z<9;z++){//the sctolling action
    for(int p=0;p<9;p++)
    scrolling_word[p] = scrolling_word[p] << 1;
    // end of the scrolling funcion
    for(int t=0;t<delay_langth;t++){// delay function, it just loops over the same display
    for(int y=0;y<9;y++){// scaning the display
    if(i == 9){// counting up to 6 with the 4017
    digitalWrite(Reset,HIGH);
    digitalWrite(Reset,LOW);
    i = 0;
    }
    latchOff();
    spi_transfer(make_word(0x010000000,y));// sending the data
    spi_transfer(make_word(0x000100000,y));
    spi_transfer(make_word(0x000001000,y));
    spi_transfer(make_word(0x000000010,y));
    latchOn();
    delayMicroseconds(800);//waiting a bit
    latchOff();
    spi_transfer(0);// clearing the data
    spi_transfer(0);
    spi_transfer(0);
    spi_transfer(0);
    spi_transfer(0);
    latchOn();
    digitalWrite(clock,HIGH);//counting up with the 4017
    digitalWrite(clock,LOW);
    i++;
    }
    }
    }
    }
    finish_scroll(delay_langth);
    }

    void finish_scroll(int delay_scroll){// this function is the same as the funcion above, it just finishing scrolling
    for (int n=0;n<40;n++){
    for(int h=0;h<9;h++)
    scrolling_word[h] = scrolling_word[h] << 1;
    for(int w=0;w<delay_scroll;w++){
    for(int k=0;k<9;k++){
    if(i == 9){
    digitalWrite(Reset,HIGH);
    digitalWrite(Reset,LOW);
    i = 0;
    }
    latchOff();
    spi_transfer(make_word(0x010000000,k));
    spi_transfer(make_word(0x000100000,k));
    spi_transfer(make_word(0x000001000,k));
    spi_transfer(make_word(0x000000010,k));
    latchOn();
    delayMicroseconds(800);
    latchOff();
    spi_transfer(0);
    spi_transfer(0);
    spi_transfer(0);
    spi_transfer(0);
    spi_transfer(0);
    latchOn();
    digitalWrite(clock,HIGH);
    digitalWrite(clock,LOW);
    i++;
    }
    }
    }
    }

    byte make_word (long posistion,byte turn){
    byte dummy_word = 0;
    for(int q=0;q<9;q++){
    if(scrolling_word[turn] & (posistion<<q))
    dummy_word |= 0x01<<q;
    }
    return dummy_word;
    }

    void loop() {

    display_word(1,your_text,26,9);//11 = JUMLAH KARAKTER, 14 = KECEPATAN GESER TEKS NYA, BISA DI ATUR SESUKA MU

    }

    void latchOn(){
    bitSet(PORTB,latchPinPORTB);
    }

    void latchOff(){
    bitClear(PORTB,latchPinPORTB);
    }

    void setupSPI(){
    byte clr;
    SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
    //SPCR |= ( (1<<SPR1) | (1<<SPR0) ); // set prescaler bits
    SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
    clr=SPSR; // clear SPI status reg
    clr=SPDR; // clear SPI data reg
    SPSR |= (1<<SPI2X); // set prescaler bits
    //SPSR &= ~(1<<SPI2X); // clear prescaler bits

    delay(10);
    }
    byte spi_transfer(byte data)
    {
    SPDR = data; // Start the transmission
    while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
    {
    };
    return SPDR; // return the received byte, we don't need that
    }

Komentar ,Saran atau Pertanyaan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: