Kita akan breakdown scriptnya secara satu persatu agar pembaca semakin mengerti (atau tambah mumet .....mungkin looo). SIlahkan Baca Penjelasan disela-sela script.
>>> Header <<
#define F_CPU 20000000UL //Frekuensi xtal yg digunakan, ubah fusebit untuk mengaktifkan
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define FONTHEIGHT 12 //Tinggi font yg diwakili lebar array font
#define HSYNC PORTB=0; //PORTB=0 sebagai bit sinkronisasi horizontal atau penghasil 0 volt
#define BLACK PORTB=1;//PORTB=0 sebagai warna putih
//Berikut ini rumus untuk menampilkan warna dot putih di televisi berdasarkan array
#define COL(r) textnya=word[r][fontzoom];
static uint8_t fontline = 0; //variabel fontline
static uint8_t fontzoom = 0; //variabel zoom font untuk besar karakter yg ditampilkan
//BERIKUT INI ARRAY DOT YG MEWAKILI ANGKA 0 - 9 :
const unsigned char font[12][FONTHEIGHT] PROGMEM = {
{ //0
0b00000000,
0b01111100,
0b11000110,
0b11001110,
0b11011110,
0b11010110,
0b11110110,
0b11100110,
0b11000110,
0b01111100,
0b00000000,
0b00000000,
},
{//1
0b00000000,
0b00010000,
0b00110000,
0b11110000,
0b00110000,
0b00110000,
0b00110000,
0b00110000,
0b00110000,
0b11111100,
0b00000000,
0b00000000,
},
{//2
0b00000000,
0b01111000,
0b11001100,
0b11001100,
0b00001100,
0b00011000,
0b00110000,
0b01100000,
0b11001100,
0b11111100,
0b00000000,
0b00000000,
},
{//3
0b00000000,
0b01111000,
0b11001100,
0b00001100,
0b00001100,
0b00111000,
0b00001100,
0b00001100,
0b11001100,
0b01111000,
0b00000000,
0b00000000,
},
{//4
0b00000000,
0b00001100,
0b00011100,
0b00111100,
0b01101100,
0b11001100,
0b11111110,
0b00001100,
0b00001100,
0b00011110,
0b00000000,
0b00000000,
},
{//5
0b00000000,
0b11111100,
0b11000000,
0b11000000,
0b11000000,
0b11111000,
0b00001100,
0b00001100,
0b11001100,
0b01111000,
0b00000000,
0b00000000,
},
{//6
0b00000000,
0b00111000,
0b01100000,
0b11000000,
0b11000000,
0b11111000,
0b11001100,
0b11001100,
0b11001100,
0b01111000,
0b00000000,
0b00000000,
},
{//7
0b00000000,
0b11111110,
0b11000110,
0b11000110,
0b00000110,
0b00001100,
0b00011000,
0b00110000,
0b00110000,
0b00110000,
0b00000000,
0b00000000,
},
{//8
0b00000000,
0b01111000,
0b11001100,
0b11001100,
0b11101100,
0b01111000,
0b11011100,
0b11001100,
0b11001100,
0b01111000,
0b00000000,
0b00000000,
},
{//9
0b00000000,
0b01111000,
0b11001100,
0b11001100,
0b11001100,
0b01111100,
0b00011000,
0b00011000,
0b00110000,
0b01110000,
0b00000000,
0b00000000,
},
{//:
0b00000000,
0b00000000,
0b00000000,
0b00110000,
0b00110000,
0b00000000,
0b00000000,
0b00110000,
0b00110000,
0b00000000,
0b00000000,
0b00000000,
},
{//blank
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
}};
uint8_t word[7][12]; //array dari dot
int tick; //variabel untuk mendapatkan pulse tiap sync
uint8_t jam,menit,detik,textnya;//variabel jam dan text
>>> TIMER <<
void timer_init(void){ //timer untuk menentukan pewaktu Hsync 64us
TCCR1B |= (1<<WGM12);
TIMSK |= (1<<OCIE1A);
OCR1A = 1280; //64 (us)* 20(Mhz) sesuaikan dengan xtal yg dipakai
TCCR1B |= (1<<CS10);
}