Untuk anda yang ingin membuat sebuah jam digital canggih lengkap dengan jam, menit, dan detik, disini Dewata Elektronik akan membagikan salah satu proyek arduino yang sangat berguna dan cocok digunakan untuk tugas akhir sekolah maupun skripsi elektronika bagi yang sudah kuliah.
Jam digital kali ini berbasiskan arduino yang menggunakan IC ATMEGA8 yang kami beri nama ERULDUINO. Jam digital ini sudah dilengkapi dengan sebuah IC RTC, yaitu sebuah IC yang dapat menyimpan data waktu maupun tanggal walaupun power supply untuk jam itu sendiri mati.
Agar jam digital ERULDUINO ini dapat terus meng-counter waktu pada saat listrik padam, maka diperlukan nya sebuah battery backup untuk tenaga cadangan bagi IC RTC hingga berbulan bulan lamanya tanpa ada arus listrik ke rangkaian jam digital.
Jam digital ERULDUINO ini bisa menggunakan display seven segmen common anoda maupun common catoda tergantung dari pemasangan transistor driver terhadap seven segmen.
Berikut ini adalah source code dari jam digital ERULDUINO ATMEGA8 yang menggunakan IC RTC DS1307.
kode program jam digital
#include <WProgram.h> #include <Wire.h> #include <DS1307.h> #include <Debounce.h> boolean pinstate = true; byte num_array[11]={//This array has all of the number codes B00111111,B0000110,B01011011,B01001111,B01100110,B01101101,B01111101,B00000111,B01111111,B01101111,0}; int rtc[7];//this array is for the data from the RTC /*Some output definitions*/ int dots_1 = 8; int dots_2 = 9; int reset_pin = 10; int clock_pin = 11; int date = 14; int up = 15; int down = 16; int set = 17; int dummy[7]; int display_time[6]; int display_date[6]; int position = 0; int blink_dots = 0; /*For buttom debouncing*/ Debounce DATE = Debounce(20,date); Debounce SET = Debounce (20,set); Debounce UP = Debounce(20,up); Debounce DOWN = Debounce(20,down); void setup(){ /*Setting outputs*/ DDRD=B11111111; pinMode(clock_pin,OUTPUT); pinMode(reset_pin,OUTPUT); pinMode(dots_1,OUTPUT); pinMode(dots_2,OUTPUT); digitalWrite(reset_pin,HIGH);//reseting the 4017 counter digitalWrite(reset_pin,LOW); digitalWrite(dots_1,HIGH);//turning on the dots digitalWrite(dots_2,HIGH); } void loop(){ RTC.get(rtc,true);//get the data form the RTC IC for(int x = 0; x < 7; x++) dummy[x] = rtc[x];//store it in the dummy array for modification dummy[6]=dummy[6]-2000;//Changing to year so that it will be displayed in 2 digits display_time[0] = dummy[2]/10;//Getting the hours (LOW number) display_time[1] = dummy[2] - (display_time[0] * 10) ;//Getting the hours (HIGH number) display_time[2] = dummy[1]/10;//Getting the minutes (LOW number) display_time[3] = dummy[1] - (display_time[2] * 10) ;//Getting the minutes (HIGH number) display_time[4] = dummy[0]/10;//Getting the seconds (LOW number) display_time[5] = dummy[0] - (display_time[4] * 10) ;//Getting the seconds (HIGH number) if(blink_dots != display_time[5]){//blink the dots every second pinstate = !pinstate;// toggle the dots state digitalWrite(dots_1,pinstate); digitalWrite(dots_2,pinstate); blink_dots = display_time[5] ;//update the seconds } for(int y = 0; y < 6; y++){//The main display loop(goes over the 6 digits DATE.update();//read the DATE button SET.update();//read the SET button if(SET.read() == HIGH)//If set is pressed go to the setting time mode set_time(); if(DATE.read() == HIGH)//If data is pressed show the data show_date(); if(position == 6){//If the counter gets to the sixth output reset it digitalWrite(reset_pin,HIGH);//utputing a reset signal to the 4017 counter digitalWrite(reset_pin,LOW); position = 0;//staring the count over } PORTD = num_array[display_time[y]];//outout the digit to be displayed delayMicroseconds(800);//wait so that the human eye can see the lights PORTD = 0;//turn off the display to make sure we don't have a ghosting effect digitalWrite(clock_pin,HIGH);//give a pulse to the clock pin of the 4017 digitalWrite(clock_pin,LOW); position++;//increment the position } } void show_date(){//this function show the date if the DATA button was pressed int position_3 = 0; /*Turn off the upper dots so that the user will know he is in the date mode*/ digitalWrite(reset_pin,HIGH); digitalWrite(reset_pin,LOW); digitalWrite(dots_1,HIGH); digitalWrite(dots_2,LOW); RTC.get(rtc,true);//get the current time data, same as in the main loop for(int a = 0; a < 7; a++) dummy[a] = rtc[a]; dummy[6]=dummy[6]-2000; display_date[0] = dummy[4]/10;//lower day display_date[1] = dummy[4] - (display_date[0] * 10) ;//upper day display_date[2] = dummy[5]/10;//lower month display_date[3] = dummy[5] - (display_date[2] * 10) ;//upper month display_date[4] = dummy[6]/10;//uuper year display_date[5] = dummy[6] - (display_date[4] * 10) ;//lower year for(int DELAY = 0; DELAY < 400; DELAY++){//This loop , loops over the same data to get a delay for(int y = 0; y < 6; y++){//This loops is the same as the in the main loop if(position_3 == 6){ digitalWrite(reset_pin,HIGH); digitalWrite(reset_pin,LOW); position_3 = 0; } PORTD = num_array[display_date[y]]; delayMicroseconds(800); PORTD = 0; digitalWrite(clock_pin,HIGH); digitalWrite(clock_pin,LOW); position_3++; } } digitalWrite(dots_2,HIGH); } void set_time(){//This function is for setting the time and date int set_array[6]; int tag=0; byte pinmode = LOW; int time_mode = 0; delay(500);//A small delay so the user wouldn't exit the function if he still presses the button digitalWrite(dots_1,HIGH);//turn on both of the dots digitalWrite(dots_2,HIGH); RTC.get(rtc,true);//get the RTC data for(int g = 0; g < 7; g++) dummy[g] = rtc[g];//put it in to a dummy array dummy[6]=dummy[6]-2000;//get the year in 2 numbers and not 4 while(pinmode == LOW){//while the set button wasn't pressed again stay in this loop DATE.update();//read the DATE button if(DATE.read() == HIGH){ time_mode++;//If it was pressed go over the modes (seconds,mins,hours etc..) delay(250);//a small delay so you wouldn't go over all of the modes } switch (time_mode){//goes to the right setting case 0://This is for the hours digitalWrite(dots_2,HIGH);//makes sure the upper dots are on so that the user will know he is in the time mode and not the data UP.update();//read the buttons DOWN.update(); if(UP.read() == HIGH){ dummy[2]++;//increment the time if the up button was pressed } if(DOWN.read() == HIGH){ dummy[2]--;//decrement the time if the down button was pressed } if(dummy[2] == -1)//makes sure you stay in the 24 hours range dummy[2] = 23; if(dummy[2] == 24) dummy[2] = 0; set_array[0] = dummy[2]/10;//update the display set_array[1] = dummy[2] - (set_array[0] * 10) ; set_array[2] = 10;//turn off the other digits set_array[3] = 10; set_array[4] = 10; set_array[5] = 10; time_set_display(set_array);//displays the time on the dispay break; case 1: // same as case 0 but for the minuts UP.update(); DOWN.update(); if(UP.read() == HIGH){ dummy[1]++; } if(DOWN.read() == HIGH){ dummy[1]--; } if(dummy[1] == -1) dummy[1] = 59; if(dummy[1] == 60) dummy[1] = 0; set_array[0] = 10; set_array[1] = 10; set_array[2] = dummy[1]/10; set_array[3] = dummy[1] - (set_array[2] * 10); set_array[4] = 10; set_array[5] = 10; time_set_display(set_array); break; case 2://this is for the day of the month digitalWrite(dots_2,LOW);//turn off the upper dots so that the user will know he is the date setting mode UP.update(); DOWN.update(); if(UP.read() == HIGH){ dummy[4]++; } if(DOWN.read() == HIGH){ dummy[4]--; } if(dummy[4] == -1) dummy[4] = 32; if(dummy[4] == 33) dummy[4] = 0; set_array[0] = dummy[4]/10; set_array[1] = dummy[4] - (set_array[0] * 10); set_array[2] = 10; set_array[3] = 10; set_array[4] = 10; set_array[5] = 10; time_set_display(set_array); break; case 3://months here UP.update(); DOWN.update(); if(UP.read() == HIGH){ dummy[5]++; } if(DOWN.read() == HIGH){ dummy[5]--; } if(dummy[5] == -1) dummy[5] = 12; if(dummy[5] == 13) dummy[5] = 0; set_array[0] = 10; set_array[1] = 10; set_array[2] = dummy[5]/10; set_array[3] = dummy[5] - (set_array[2] * 10); set_array[4] = 10; set_array[5] = 10; time_set_display(set_array); break; case 4://years here UP.update(); DOWN.update(); if(UP.read() == HIGH){ dummy[6]++; } if(DOWN.read() == HIGH){ dummy[6]--; } if(dummy[6] == -1) dummy[6] = 99; if(dummy[6] == 100) dummy[6] = 0; set_array[0] = 10; set_array[1] = 10; set_array[2] = 10; set_array[3] = 10; set_array[4] = dummy[6]/10; set_array[5] = dummy[6] - (set_array[4] * 10); time_set_display(set_array); break; case 5: time_mode = 0;//loop the modes over break; } SET.update();//update the SET button pinmode = SET.read();If it was pressed you will exit the while loop } //This is the function to update the RTC RTC.stop(); RTC.set(DS1307_MIN,dummy[1]); RTC.set(DS1307_HR,dummy[2]); RTC.set(DS1307_DATE,dummy[4]); RTC.set(DS1307_MTH,dummy[5]); RTC.set(DS1307_YR,dummy[6]); RTC.start(); digitalWrite(dots_2,HIGH); delay(200); } void time_set_display(int data_array[]){//This fnction just displays 2 digits and it's pretty much the same as the display loop in the main function int position_2 = 0; digitalWrite(reset_pin,HIGH); digitalWrite(reset_pin,LOW); for(int xlk=0;xlk<25;xlk++){//a delay loop for(int j = 0; j < 6; j++){ if(position_2 == 6){ digitalWrite(reset_pin,HIGH); digitalWrite(reset_pin,LOW); position_2 = 0; } PORTD = num_array[data_array[j]]; delayMicroseconds(800); PORTD = 0; digitalWrite(clock_pin,HIGH); digitalWrite(clock_pin,LOW); position_2++; } } } |
0 komentar:
Posting Komentar