Tuesday, 2 January 2018

Rangkaian dan Coding Jam Digital Menggunakan LCD dan ATMEGA32



#include <mega32.h>
#include <delay.h>
#include <stdio.h>
#asm
   .equ __i2c_port=0x15 ;PORTC
   .equ __sda_bit=1
   .equ __scl_bit=0
#endasm
#include <i2c.h>
#include <ds1307.h>
#asm
   .equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>

char buf[33];

unsigned char s;
unsigned char m;
unsigned char h;

void main(void)
{

PORTA=0x00;
DDRA=0x00;

PORTB=0x00;
DDRB=0x00;

PORTC=0x00;
DDRC=0x00;

PORTD=0x00;
DDRD=0x00;

TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
MCUCSR=0x00;
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=0x33;

ACSR=0x80;
SFIOR=0x00;

// I2C Bus initialization
i2c_init();

rtc_init(0,0,0);

lcd_init(16);
lcd_clear();


while (1)
      {
      rtc_get_time(&h,&m,&s);
    
      lcd_gotoxy(0,1);
      sprintf(buf,"%02u:%02u:%02u",h,m,s);
      lcd_puts(buf);
      printf(" %02u:%02u:%02u \r",h,m,s);
      delay_ms(10);
      }

}

1 comment:

Spiderman