asking
Full Member level 5
- Joined
- Sep 21, 2010
- Messages
- 279
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Activity points
- 3,377
I tried to modify the LCD clock circuit and tried to multiplex the out into 7 Segment. So here i have combined 2 circuits to make 1 Digital 7 segment circuit. But m confused about PORT A.6 and A.7 Pins as this pins are used for I2C Connection they should be I/o Pins... But how to make only those 2 pins as input/output ? Because my Port A0-A3 are used for Display Refresh multiplexing so they're consider as only outputs...
i have tried to run code and attached proteus circuit file but its not working.... please suggest whats wrong ?
Here the count = 1234 i write i get on display 1234 so what i did is count = hour*100 + minute so whatever output from DS1307 it will be display on 7 segment... please correct me if m wrong... Still i have not implemented time set i was just starting and i got error...so please help
i have tried to run code and attached proteus circuit file but its not working.... please suggest whats wrong ?
Here the count = 1234 i write i get on display 1234 so what i did is count = hour*100 + minute so whatever output from DS1307 it will be display on 7 segment... please correct me if m wrong... Still i have not implemented time set i was just starting and i got error...so please help
Code:
unsigned short i, DD0, DD1, DD2, DD3;
unsigned int Count, hour, minute;
//------ Function to Return mask for common anode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
} //case end
}
// Software I2C connections
sbit Soft_I2C_Scl at RA6_bit;
sbit Soft_I2C_Sda at RA7_bit;
sbit Soft_I2C_Scl_Direction at TRISA6_bit;
sbit Soft_I2C_Sda_Direction at TRISA7_bit;
// End Software I2C connections
// this is my programming part 1
unsigned short read_ds1307(unsigned short address)
{
unsigned short r_data;
Soft_I2C_Start();
Soft_I2C_Write(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
Soft_I2C_Write(address);
Soft_I2C_Start();
Soft_I2C_Write(0xD1); //0x68 followed by 1 --> 0xD1
r_data=Soft_I2C_Read(0);
Soft_I2C_Stop();
return(r_data);
}
void write_ds1307(unsigned short address,unsigned short w_data)
{
Soft_I2C_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
Soft_I2C_Write(0xD0); // send byte via I2C (device address + W)
Soft_I2C_Write(address); // send byte (address of DS1307 location)
Soft_I2C_Write(w_data); // send data (data to be written)
Soft_I2C_Stop(); // issue I2C stop signal
}
void main()
{
Soft_I2C_Init();
minute = read_ds1307(1);
hour = read_ds1307(2);
CMCON |= 7; // Disable Comparators
TRISB = 0xff; // Set PORTB7 input all other direction to be output
PORTB = 0xff; // Turn OFF LEDs on PORTB
TRISA = 0b11100000; // RA5-6-7 is input only
do {
DD0 = Count%10; // Extract Ones Digit
DD0 = mask(DD0);
DD1 = (Count/10)%10; // Extract Tens Digit
DD1 = mask(DD1);
DD2 = (Count/100)%10; // Extract Hundreds Digit
DD2 = mask(DD2);
DD3 = (Count/1000); // Extract Thousands Digit
DD3 = mask(DD3);
for (i = 0; i<=50; i++) {
RA3_bit = 1; //disable RA3
PORTB = DD0;
RA0_bit = 0; // Select Ones Digit
RA1_bit = 1;
RA2_bit = 1;
delay_ms(5);
RA0_bit = 1; //disable RA0
PORTB = DD1;
RA1_bit = 0; // Select Tens Digit
RA2_bit = 1;
RA3_bit = 1;
delay_ms(5);
RA1_bit = 1; //disable RA1
PORTB = DD2;
RA0_bit = 1;
RA2_bit = 0; // Select Hundreds Digit
RA3_bit = 1;
delay_ms(5);
RA2_bit = 1; //disable RA2
PORTB = DD3;
RA0_bit = 1;
RA1_bit = 1;
RA3_bit = 0; // Select Thousands Digit
delay_ms(5);
}
Count = hour*100 + minute;
} while(1);
}
// endless loop