Menu

a-ads Ad Unit #2456538

Ad Unit #2456555

Navbar

a-ads Ad Unit #2456538

Saturday, February 7, 2026

ATMega644P TWI DS1307 MCP23017 LCD

In previous posts the ATMega644P TWI interface with the DS13017 RTC and MCP23017 GPIO expansion chip. Here I will put them altogethers. This TWI bus will drives the DS1307 RTC and the MCP23017 that controls a character LCD.

ATMega644P TWI DS1307 MCP23017 LCD 

The master microcontroller read the RTC data from ds1307 and it will send to the MCP23017 based LCD. 

Source Code:

  1. /*
  2. * 10-i2c_ds1307_mcp23017_lcd.c
  3. *
  4. * Created: 2/7/2026 7:42:39 PM
  5. * Author : Admin
  6. */

  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9. #define F_CPU 16000000UL

  10. void rtc_init(void){
  11. char rtc[8]={0x30,0x00,0x17,0x07,0x31,0x01,0x26,1<<4};
  12. for (char i=0;i<8;i++)
  13. {
  14. twi_start();
  15. //D0 is DS1307 Write Address
  16. twi_write(0xD0);
  17. //Select Control Register
  18. twi_write(i);
  19. //Enable SQWE bit blinks at 1 Hz
  20. twi_write(rtc[i]);
  21. twi_stop();
  22. _delay_ms(10);
  23. }
  24. }

  25. char rtc[6], msg[16];
  26. int main(void)
  27. {
  28. /* Replace with your application code */
  29. _delay_ms(1000);
  30. lcd_init();
  31. lcd_text("ATMega644P TWI");
  32. lcd_xy(1,2);
  33. lcd_text("MCP23017 DS1307");
  34. _delay_ms(10000);
  35. lcd_clear();
  36. lcd_command(0x0C);
  37. while (1)
  38. {
  39. for(char i=0;i<7;i++){
  40. /*Second Register*/
  41. twi_start();
  42. twi_write(0xD0);
  43. /*Select Second register*/
  44. twi_write(i);
  45. twi_stop();
  46. _delay_us(10);
  47. twi_start();
  48. twi_write(0xD1);
  49. rtc[i]=twi_read(1);
  50. twi_stop();
  51. _delay_us(10);
  52. }
  53. lcd_xy(1,1);
  54. sprintf(msg,"Time: %02X:%02X:%02X",rtc[2],rtc[1],rtc[0]);
  55. lcd_text(msg);
  56. lcd_xy(1,2);
  57. sprintf(msg,"Date: %02X/%02X/20%02X",rtc[4],rtc[5],rtc[6]);
  58. lcd_text(msg);
  59. _delay_ms(500);
  60. }
  61. }


Circuit Simulation:

ATMega644P TWI DS1307 MCP23017 LCD
Circuit and Simulation

 

AVR Prototype Board

ATMega644P TWI DS1307 MCP23017 LCD

 

ATMega644P TWI DS1307 MCP23017 LCD 

This PCB was offered by PCBWay (pcbway.com).

I have been using PCBWay for many years now. PCBWay fabricate PCBs at low cost, fast processing time for only 24 hours, and fast delivery time using any carrier options. This double side 10cmx10cm can be fabricate at only 5USD for 5 to 10pcs by PCBWay. It's a standard PCB with silk screen and solder mask.

A DIY dsPIC30F2010 and dsPIC30F1010 Prototype Board with Programmer
10 PCBs for only 5USD
 

For different size of PCB we can instantly quote on PCBWay website using a zip PCB Gerber file without account.

A DIY dsPIC30F2010 and dsPIC30F1010 Prototype Board with Programmer
PCBWay Instant Quote

 

Click here to download this example. 

For a full ATMega644P tutorials please visit this page.

No comments:

Post a Comment

Ad Unit #2456555

Search This Blog

Labels

23K256 (1) 24C16B (2) 25AA010A (2) 8051 (7) 93AA46B (1) ADC (34) Analog Comparator (1) Arduino (16) ARM (13) AT89C52 (7) ATMega32 (58) ATMega644P (27) AVR (87) AVR PCB (2) Bootloader (1) CCS PICC (31) Change Notify Interrupt (CNI) (2) DAC (2) DHT11 (4) Display (133) Distance Sensor (3) ds1307 (10) DS18B20 (5) ds3231 (1) ds3232 (2) dsPIC (5) dsPIC30F1010 (3) dsPIC30F2010 (5) EEPROM (5) Environment Sensor (5) ESP32 (1) esp8266 (1) Graphical LCD (2) I2C (38) ILI9341 (1) Input/Output (76) Interrupt (22) IoT PCB (1) Keil (5) Keypad (16) KS0108 (2) LCD (75) LM35 (3) Master/Slave (2) MAX7221 (1) MCP23017 (8) MCP23S17 (7) MCP4921 (1) MCP4922 (2) Meter (3) MikroC (2) Module PCB (1) Motor (15) MPLABX (73) Nokia 5110 LCD (4) OLED (2) One-Wire (7) Oscillator (8) PCB (10) PCD8544 (3) PCF8574 (10) PIC (108) PIC12F (3) PIC16 (105) PIC16F628A (3) PIC16F630 (2) PIC16F716 (4) PIC16F818 (11) PIC16F818/819 (3) PIC16F84A (16) PIC16F876A (2) PIC16F877A (9) PIC16F88 (2) PIC16F887 (60) PIC18 (19) PIC18F1220 (5) PIC18F2550 (5) PIC18F4550 (12) PICKit2 (1) PICMicro PCB (4) Pin Change Interrupt (1) PWM (12) RTC (12) SBN0064G (1) Sensor (13) SH1106 (3) Shift Register (13) Shift Registers (10) Software TWI (2) SPI (39) ST7735 (1) STM32 (11) STM32 Black Pill (1) STM32 Blue Pill (12) STM32 HAL (5) STM32CubeIDE (13) STM32F103C8T6 (9) STM32F401CCU6 (1) SysTick (4) temperature sensor (13) TFT (1) TG12864A (1) Thermometer (22) Timer/Counter (32) TM1637 (2) twi (10) UART (8) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (96)