Kenapa Lonely ? karena dia memang kesepian, sendirian gerak-gerak di layar TV.
sebaiknya membaca dulu pembahasan dasar televisi di: part#1 part#2
Siapkan Bahan-bahan berikut ini:
sebaiknya membaca dulu pembahasan dasar televisi di: part#1 part#2
Siapkan Bahan-bahan berikut ini:
1. Micro-AVR ATTiny 2313
2. Breadboard
3. Power suply 5v , atau adaptor 12v dan diregulasi 7805
4. Resistor 10K, 470
5. Tombol push button
6. Xtal 20Mhz + capasitor 22pF
7. Programer AVR
8. Pesawat TV yg nganggur ( jangan sampai bertengkar dengan sodara yg lagi nonton sinetron)
Kemudian skematik yg digunakan seperti gambar berikut :
Klik pada gambar buat memperjelas gambar
Ntar hasilnya seperti berikut ini :
Listing program dari game lonely pakman sebagai berikut :
SELAMAT MENCOBA
//==========LONENLY PAKMAN=======// by : ahocool@gmail.com// http://aisi555.blogspot.com//=========== 2012 ===============#define F_CPU 20000000UL //xtal yg digunakan#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>#include <avr/pgmspace.h>#define HSYNC PORTB=0; //H sinkronisasi#define BLACK PORTB=1; // warna hitem
//deklarasi variableuint8_t textnya,pakline,arah;static uint16_t x,y,tick;char pakman1[12] = // memory penyimapan data gambar pakman{ //kanan mangap0b00000000,0b01111100,0b11001100,0b11001000,0b11110000,0b11100000,0b11000000,0b11100000,0b11110000,0b11111000,0b01111100,0b00000000,};char pakman2[12] ={ //kanan mingkem0b00000000,0b01111100,0b11001110,0b11001110,0b11111110,0b11111110,0b11111110,0b11111110,0b11000000,0b11111110,0b01111100,0b00000000,};char pakman3[12] ={ //kiri mangap0b00000000,0b01111100,0b01100110,0b00100110,0b00011110,0b00001110,0b00000110,0b00001110,0b00011110,0b00111110,0b01111100,0b00000000,};char pakman4[12] ={ //kiri mingkem0b00000000,0b00111100,0b01100110,0b01100110,0b01111110,0b01111110,0b01111110,0b01111110,0b00000110,0b01111110,0b00111100,0b00000000,};char pakman5[12] ={ //bawah mangap0b00000000,0b01111100,0b11111110,0b11110010,0b11110010,0b11001110,0b11001110,0b11000010,0b10000010,0b10000010,0b10000010,0b00000000,};char pakman6[12] ={ //bawah mingkem0b00000000,0b01111100,0b11111110,0b11110010,0b11110010,0b11111110,0b10111110,0b10111110,0b10111110,0b10111110,0b10111100,0b00000000,};char pakman7[12] ={ //atas mangap0b00000000,0b10000010,0b10000110,0b10000110,0b10000110,0b11011110,0b10110010,0b11110010,0b11111110,0b01111100,0b00000000,};char pakman8[12] ={ //atas mingkem0b00000000,0b10111100,0b10111110,0b10111110,0b10111110,0b10111110,0b11110010,0b11110010,0b11111110,0b01111100,0b00000000,};void timer_init(void){//inisialisasi timer per rasterline 64us (PAL TV)TCCR1B |= (1<<WGM12);TIMSK |= (1<<OCIE1A);OCR1A = 1280; //64 us dengan xtal 20Mhz, untuk 16Mhz= 1024;TCCR1B |= (1<<CS10); //full speed}//interupt timer untuk menampilkan gambarISR (TIMER1_COMPA_vect) {static uint16_t rasterline=0; //barisuint16_t a;uint8_t out=0; // variabel simpan memory byte pakmanHSYNC;//posisi berdasarkan nilai x,y dengan lebar 12 barisif( rasterline > (18 + y) && rasterline <= (30 +y) ) {_delay_us(4);BLACK;_delay_us(7);for(a=0;a<x;a++) asm("nop");// tampilkan sesuai arah dari pakmanif(arah==0){if(tick<5000)out= pakman1[pakline];else out= pakman2[pakline];}else if(arah==1){if(tick<5000)out= pakman3[pakline];else out= pakman4[pakline];}if(arah==2){if(tick<5000)out= pakman5[pakline];else out= pakman6[pakline];}if(arah==3){if(tick<5000)out= pakman7[pakline];else out= pakman8[pakline];}//geser bit untuk tampilkan data gambar ke pakman ke TVPORTB= (out & 0x81) + 1;out <<=1;PORTB= (out & 0x81) + 1;out <<=1;PORTB= (out & 0x81) + 1;out <<=1;PORTB= (out & 0x81) + 1;out <<=1;PORTB= (out & 0x81) + 1;out <<=1;PORTB= (out & 0x81) + 1;out <<=1;PORTB= (out & 0x81) + 1;out <<=1;PORTB= (out & 0x81) + 1;pakline++; //tambahkan index array dari gambar pakman}// Vsync ada disini tanpa membedakan genap ganjilelse if( rasterline >= 0 && rasterline < 5 ) {_delay_us(27);BLACK;_delay_us(5);HSYNC;_delay_us(27);BLACK;} else if( (rasterline >= 5 && rasterline <= 10) ) {_delay_us(2);BLACK;_delay_us(28);HSYNC;_delay_us(2);BLACK;} else if( rasterline >311-6 ) {_delay_us(2);BLACK;_delay_us(28);HSYNC;_delay_us(2);BLACK;} else {_delay_us(3);BLACK;pakline=0;}rasterline++;tick++; //variabel timer untuk mangap & mingkemif(tick >10000) tick=0;if( rasterline > 311 )rasterline = 0; //maksimum baris/raster}void tombol(void) // membaca tombol{if(bit_is_clear(PIND, PIND3)){x--;arah=1;if(x<1)x=125;_delay_ms(50);}else if(bit_is_clear(PIND, PIND4)){x++;arah=0;if(x>125)x=1;_delay_ms(50);}else if(bit_is_clear(PIND, PIND5)){y-=3;arah=3;if(y<3)y=280;_delay_ms(50);}else if(bit_is_clear(PIND, PIND6)){y+=3;arah=2;if(y>280)y=0;_delay_ms(50);}}int main() { //Main Programx=1;y=13;arah=0;DDRD &=~(1<<PD3) & ~(1<<PD4) & ~(1<<PD5) & ~(1<<PD6); //tombolDDRB = (1<<PB7)|(1<<PB0); //PB0=1K, PB7=470 ohmtimer_init();sei();for( ;; )tombol();}
SELAMAT MENCOBA
Mantab tutorialnya.
BalasHapusdownload game