////////////////////////////////////////////////////////////////////////// // Project: RTC-7seg Digital Clock // Author: jrapisora(joselito.rapisora@gmail.com), Aug2013 // // To God be the Glory! // ////////////////////////////////////////////////////////////////////////// #include #include #include #include #include "myI2C.h" #define F_CPU 1000000L // PINNAME PORTPIN //PINNUM #define RESET PA2 //1 #define segG PD0 //2 #define segB PD1 //3 //#define NC PA1 //4 //#define NC PA0 //5 #define segD PD2 //6 #define segA PD3 //7 #define segF PD4 //8 #define segE PD5 //9 //#define GND NA //10 #define segC PD6 //11 #define segP PB0 //12 #define ce1 PB1 //13 #define ce2 PB2 //14 #define ce4 PB3 //15 #define ce3 PB4 //16 #define SDA PB5 //17 //#define NC PB6 //18 #define SCL PB7 //19 //#define VCC NA //20 #define SEG_PORT PORTD #define SEL_PORT PORTB #define RTC_PORT PORTB #define SEC_PORT PORTB #define SEG_IOREG DDRD #define SEL_IOREG DDRB #define RTC_IOREG DDRB #define SEC_IOREG DDRB #define MESSAGEBUF_SIZE 3 #define RTCADDR 0xD0 //DS1307 address #define REFRESHRATE 0xBF //60Hz refresh rate (60Hz x 4 = 240Hz interval between digits) unsigned char msgBuff[MESSAGEBUF_SIZE]; unsigned char digitVal[4]; unsigned char digitSelect[] = {ce1,ce2,ce3,ce4}; unsigned char segmentOn[] = {0b10000001,0b11110101,0b10100010,0b10100100,0b11010100,0b10001100,0b10001000,0b11100101,0b10000000,0b10000100}; //unsigned char decToBcd(unsigned char val) { return ( (val/10*16) + (val%10) ); } unsigned char bcdToDec(unsigned char val) { return ( (val/16*10) + (val%16) ); } void sleep() { MCUCR = (0<= 3 ? select = 0 : select++; //roll digit select SEG_PORT = segmentOn[digitVal[select]]; //update 7-segment value SEL_PORT = (0<