Rabu, 04 Januari 2012

RANCANG BANGUN JAM DIGITAL DENGAN MENGGUNAKAN LCD NOKIA 3310 BERBASIS MIKROKONTROLER

GAMBAR RANGKAIAN
Jika ingin men-download file proteus disini

Jika ingin men-download file orcad disini


LISTING PROGRAM
1. Uji RTC (Real Time Clock)



/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date    : 7/23/2011
Author  :
Company :
Comments:


Chip type           : ATmega8
Program type        : Application
Clock frequency     : 11.059200 MHz
Memory model        : Small
External RAM size   : 0
Data Stack size     : 256
*****************************************************/

#include <mega8.h>

// I2C Bus functions
#asm
   .equ __i2c_port=0x15 ;PORTC
   .equ __sda_bit=0
   .equ __scl_bit=1
#endasm
#include <i2c.h>

// DS1307 Real Time Clock functions
#include <ds1307.h>

// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>

// Declare your global variables here

void main(void)
{
    //unsigned char tanggal = 0, bulan = 0, tahun = 0;
    unsigned char tanggal_t = 0, bulan_t = 0, tahun_t = 0;
    //unsigned char jam = 0, menit = 0, detik = 0;
    unsigned char jam_t = 0, menit_t = 0, detik_t = 0;

// Input/Output Ports initialization
// Port B 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
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// 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=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// I2C Bus initialization
i2c_init();

// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 32768Hz
    rtc_init(3,1,0);
    // pengaturan tanggal: Kamis, 8 Desember 2011
    rtc_set_date(8, 12, 11);
    // pengaturan waktu: 21:00:00
    rtc_set_time(11, 0, 0);

while (1)
      {
      rtc_get_date(&tanggal_t, &bulan_t, &tahun_t); delay_ms (10);
         
      printf("Tanggal: %d-%d-%d\n", tanggal_t, bulan_t, tahun_t); delay_ms (1000);
         
      rtc_get_time(&jam_t, &menit_t, &detik_t);
         
      printf("Waktu: %d:%d:%d\n", jam_t, menit_t, detik_t);

   
      };
}

dapat di download disini

2. Uji Serial
    Uji ini akan diperlukan apabila kita ingin menguji RTC melalui serial (jika LCD tidak dapat berfungsi, rusak, atau memang tidak menggunakan LCD). Program ini hanya akan menguji serial pada rangkaian apakah berfungsi atau tidak. Setelah program berfungsi, maka untuk menguji RTC lewat serial tetap menggunakan program uji RTC di atas. Berikut listing programnya :

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 12/16/2011
Author  : Eva Listiyani
Company : Jangan gunakan software bajakan!
Comments: 


Chip type               : ATmega8L
Program type            : Application
AVR Core Clock frequency: 11.059200 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega8.h>

// Standard Input/Output functions
#include <stdio.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here
    unsigned char data_rx;

// Reset Source checking
if (MCUCSR & 1)
   {
   // Power-on Reset
   MCUCSR=0;
   // Place your code here

   }
else if (MCUCSR & 2)
   {
   // External Reset
   MCUCSR=0;
   // Place your code here

   }
else if (MCUCSR & 4)
   {
   // Brown-Out Reset
   MCUCSR=0;
   // Place your code here

   }
else
   {
   // Watchdog Reset
   MCUCSR=0;
   // Place your code here

   }

// Input/Output Ports initialization
// Port B 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 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// 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=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

printf("\n PROGRAM RTEST KOMUNIKASI SERIAL");
printf("\n KIRIM DATA DARI KOMPUTER KE ATMEGA16");
printf("\n TERIMA DATA DAN KEMBALIKAN DATA KE KOMPUTER");
printf("\n SILAHKAN TEKAN TOMBOL SEMBARANG TOMBOL KEYBOARD");

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

while (1)
      {
      // Place your code here
      data_rx=getchar(); // terima data dari komputer
      printf("\n keyboard:%c",data_rx); // kirim data kembali ke komputer
      };
}

dapat di download disini

3. Program Lengkap (Jam digital dengan LCD Nokia 3310)
Program di bawah ini menggunakan software Code Vision AVR versi 2.05.3 , karena di dalamnya telah include pengaturan langsung pemrograman untuk Grafik LCD ex : LCD Nokia 3310 atau PCD 8544

Berikut Listing Programnya :
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : RANCANG BANGUN JAM DIGITAL DG LCD NOKIA 3310 BERBASIS MIKROKONTROLLER
Version : 2.05.3
Date    : 12/7/2011
Author  : Eva Listiyani
Company : STIKOM SURABAYA
Comments: 


Chip type               : ATmega8
Program type            : Application
AVR Core Clock frequency: 11.059000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega8.h>

// I2C Bus functions

#include <i2c.h>
#include <stdio.h>
#include <delay.h>


// DS1307 Real Time Clock functions
#include <ds1307.h>

// Graphic LCD functions
#include <glcd.h>

// Font used for displaying text
// on the graphic LCD
#include <font5x7.h>

// Function used for reading image
// data from external memory
unsigned char read_ext_memory(GLCDMEMADDR_t addr)
{
unsigned char data;
// Place your code here

return data;
}

// Function used for writing image
// data to external memory
void write_ext_memory(GLCDMEMADDR_t addr, unsigned char data)
{
// Place your code here

}

// Declare your global variables here
char str;

void main(void)
{
    unsigned char hari = 0, tanggal = 0, bulan = 0, tahun = 0;
    unsigned char hari_t = 0, tanggal_t = 0, bulan_t = 0, tahun_t = 0;
    unsigned char jam = 0, menit = 0, detik = 0;
    unsigned char jam_t = 0, menit_t = 0, detik_t = 0; 
    unsigned char temp[16];

// Graphic LCD initialization data
GLCDINIT_t glcd_init_data;

// Input/Output Ports initialization
// Port B 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 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// 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=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// USART disabled
UCSRB=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// I2C Bus initialization
// I2C Port: PORTC
// I2C SDA bit: 4
// I2C SCL bit: 5
// Bit Rate: 100 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
i2c_init();

// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 32768Hz
rtc_init(0,0,0);
    // pengaturan tanggal: Kamis, 8 Desember 2011
    rtc_set_date(4, 8, 12, 11);
    // pengaturan waktu: 21:00:00
    rtc_set_time(11, 0, 0);

// Graphic LCD initialization
// The PCD8544 connections are specified in the
// Project|Configure|C Compiler|Libraries|Graphic LCD menu:
// SDIN - PORTD Bit 3
// SCLK - PORTD Bit 4
// D /C - PORTD Bit 2
// /SCE - PORTD Bit 1
// /RES - PORTD Bit 0

// Specify the current font for displaying text
glcd_init_data.font=font5x7;
// No function is used for reading
// image data from external memory
glcd_init_data.readxmem=NULL;
// No function is used for writing
// image data to external memory
glcd_init_data.writexmem=NULL;
// Set the LCD temperature coefficient
glcd_init_data.temp_coef=PCD8544_DEFAULT_TEMP_COEF;
// Set the LCD bias
glcd_init_data.bias=PCD8544_DEFAULT_BIAS;
// Set the LCD contrast control voltage VLCD
glcd_init_data.vlcd=PCD8544_DEFAULT_VLCD;

glcd_init(&glcd_init_data);                                   
      { 
      glcd_outtextxy(6, 6, "JAM DIGITAL \n" "LCD NOKIA 3310 \n" "by : \n" "EVA LISTIYANI");
      glcd_clear();  
      }                         
      
while (1) 
{
     rtc_get_date(&hari_t, &tanggal_t, &bulan_t, &tahun_t);
//            if(hari_t != hari || tanggal_t != tanggal || bulan_t != bulan || tahun_t != tahun)
//            {   
//                hari = hari_t;
//                tanggal = tanggal_t;
//                bulan = bulan_t;
//                tahun = tahun_t;
                sprintf(temp, "Tanggal:\n" "%02d-%02d-%02d", tanggal_t, bulan_t, 2000+tahun_t);
                glcd_outtextxy (6,6,temp);
//            }
      rtc_get_time(&jam_t, &menit_t, &detik_t);
//            if(jam_t != jam || menit_t != menit || detik_t != detik)
//            {
//                jam = jam_t;
//                menit = menit_t;
//                detik = detik_t;
                sprintf(temp, "Waktu:\n" "%02d:%02d:%02d", jam, menit, detik);
                glcd_outtextxy (6,30,temp);   
//            }
            //delay_ms(30000);
};
}

dapat di download disini


KENDALA-KENDALA 
Kendala-kendala yang dihadapi saat pembuatan jam digital ini, antara lain :
- Kesalahan dalam penyolderan
- Seringnya penggantian MAX232
- Pengujian RTC DS1307 yang sering gagal

SOLUSI
Solusi untuk memecahkan kendala di atas adalah :
- Teliti Kembali setiap kali kita selesai menyolder terutama pada penyolderan PCB secara manual, PCB yang dicetak pun juga tetap harus diteliti per bagian nya, apakah ada yang short, apakah ada yang terhubung padahal seharusnya tidak, dll
- Sekali MAX232 mengalami short (terbaliknya pemasangan ground dan VCC, atau antara ground dan VCC terhubung, atau dapat juga dikatakan "hubungan pendek"), maka MAX232 sudah tidak dapat dipergunakan lagi dengan kata lain harus diganti. Oleh karena itu, saat pemasangan supply, kita harus benar-benar memastikan apakah telah terhubung dengan baik dan benar, karena bukan hanya MAX232 saja yang mudah rusak saat terjadi short tetapi juga mikrokontroller dan komponen-komponen pendukung lainnya.
-Pastikan RTC selalu "hidup" dengan cara menambahkan baterai 3V tambahan pada rangkaian dan VCC,Ground juga harus telah terhubung dengan baik dan benar. Pastikan juga SDA dan SCL mengeluarkan output sebesar +-5V. Jangan lupa menambahkan "pull up" pada kaki SDA dan  SCL. 











2 komentar: