Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Mikroc + Keypad + LCD + Pic16f877a -- Clock Timer

Status
Not open for further replies.

fcaiii89

Junior Member level 1
Junior Member level 1
Joined
May 16, 2009
Messages
18
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,427
Hi to all,

My plan is to enter time in this format -- hh:mm:ss. First, I have to input the "Hour". Second is "Minute" and last is "Second". This is the first step only.

The second step is I want to increase it with 1 second increment. It must be in a 24 hour format.

Can anyone give me some ideas on how to do this?

Thanks ahead guys.
 

For accuracy, I would recommend using a RTC chip for time-keeping. Two such popular chips are DS1307 and PCF8583.

Starting on your project, have you used mikroC to display text on the LCD? Have you used the keypad library to input data from a keypad? If you use the RTC chips mentioned above, you will need to learn to use I2C interfacing.

Hope this helps.
Tahmid.
 
  • Like
Reactions: drood

    drood

    Points: 2
    Helpful Answer Positive Rating
Thanks for the reply,

Yes, I've already used mikroC to display text on LCD with Pic16f877a. I have no idea about RTC chips but I'll try about it.

Maybe you still have more ideas bro?

Cheerz!
 

I've made a clock with mikroC before but it the time varied by a few minutes after a few days. I guess it was due to the slight inaccuracy of the crystal as well as program. That's why I suggested RTC chips as they use (or have in them, integrated) 32.768kHz crystals which tend to be more accurate than the standard 4-20MHz that we use.
 

But I really have to stick on mikroC and Pic16f877a. I still have to use the UART module of this PIC and the result should be displayed on LCD and hyperterminal too. Thanks for your suggestions, I really appreciate that.
 

DS1307 is good. can you tell how to set date time when i reset it..?
 

This snippet from the project link I posted above is the method of initializing the RTC to the current Time and Date:

Code:
//Set Time
write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
write_ds1307(1,0x10); //write min 27
write_ds1307(2,0x01); //write hour 14
write_ds1307(3,0x02); //write day of week 2:Monday
write_ds1307(4,0x05); // write date 17
write_ds1307(5,0x01); // write month 6 June
write_ds1307(6,0x09); // write year 8 --> 2008
write_ds1307(7,0x10); //SQWE output at 1 Hz
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator

Reference MAXIM DS1307 64 x 8, Serial, I2C Real-Time Clock Datasheet, pg 8, Section CLOCK AND CALENDAR:

**broken link removed**

The MikroC snippet above sequential loads the DS1307's registers with the current time and date and the oscillator is restarted by resetting the seconds register to zero.

BigDog
 
i used soft_i2c library. how can i use write_ds1307..... what is the libruary..?
 

Both the read_ds1307() and write_ds1307() routines are functions which call MikroC's I2C library functions.

If you are using the soft_I2C library, simply substitute the appropriate soft_I2C library functions for the hardware I2C library functions in the following routines:

Code:
unsigned short read_ds1307(unsigned short address)
{
I2C_Start();
I2C_Wr(0xd0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(address);
I2C_Repeated_Start();
I2C_Wr(0xd1); //0x68 followed by 1 --> 0xD1
data=I2C_Rd(0);
I2C_Stop();
return(data);
}

unsigned char BCD2UpperCh(unsigned char bcd)
{
return ((bcd >> 4) + '0');
}

void write_ds1307(unsigned short address,unsigned short w_data)
{
I2C_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(0xD0); // send byte via I2C (device address + W)
I2C_Wr(address); // send byte (address of DS1307 location)
I2C_Wr(w_data); // send data (data to be written)
I2C_Stop(); // issue I2C stop signal
}

The modification will allow you to retain the functionality of both read_ds1307() and write_ds1307().

Refer to the MikroC Pro User's Manual, for the correct soft_I2C library functions and their use.

BigDog
 
Dear All I have made a simple calculator using pic16F877A in Mikroc. Now I want to improve it. I want to do operations on string instead of single single digit. Like 220*450, 556+778 etc.
earlier its is just for single digit like 4+8, 9-4 etc.
pls help me in this regard and Also I want to make functions of arithmetic operations. Do help me plz.
My Complete code is give below.
// Simple Calculator by Tanvir Ahmad
char txt[2];
int kp;
// Keypad module connections
char keypadPort at PORTD;
// LCD connections definitions
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

// MAIN

void main() {


int Calc, Op1, Op2, txt1;
Keypad_Init(); // Initialize Keypad
Lcd_Init(); // Initialize Lcd

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 3, "Welcome to"); // Write message text on Lcd
Lcd_Out(2, 8, "UES"); // Write message text on Lcd
delay_ms(2000) ;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 5, "Simple"); // Write message text on Lcd
Lcd_Out(2, 3, "Calculator"); // Write message text on Lcd
delay_ms(3000) ;
Lcd_Cmd(_LCD_CLEAR);


start:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Key1:"); // Write message text on Lcd
Lcd_Out(2, 1, "Key2:"); // Write message text on Lcd
Lcd_Out(1,12, "k3:");


while(1){
kp = 0; // Reset key code variable

do
kp = Keypad_Key_Click(); // Store key code in kp variable
while (!kp);

switch (kp) {
case 9: kp = 49; break; // 1
case 10: kp = 50; break; // 2
case 11: kp = 51; break; // 3
case 5: kp = 52; break; // 4
case 6: kp = 53; break; // 5
case 7: kp = 54; break; // 6
case 1: kp = 55; break; // 7
case 2: kp = 56; break; // 8
case 3: kp = 57; break; // 9
case 14: kp = 48; break; // 0
}
Lcd_Chr(1, 8, kp);
delay_ms(200);

{
op1 = 0; // Reset key code variable
do
op1 = Keypad_Key_Click(); // Store key code in kp variable
while (!op1);
switch (op1) {
case 9: op1 = 49; break; // 1
case 10: op1 = 50; break; // 2
case 11: op1 = 51; break; // 3
// case 4: op1 = 47; break; // /
case 5: op1 = 52; break; // 4
case 6: op1 = 53; break; // 5
case 7: op1 = 54; break; // 6
case 1: op1 = 55; break; // 7
case 2: op1 = 56; break; // 8
case 3: op1 = 57; break; // 9
case 14: op1 = 48; break; // 0





}
Lcd_Chr(2, 8, op1);
}
{
op2=0;
do
op2 = Keypad_Key_Click(); // Store key code in kp variable
while (!op2);
switch (op2) {
case 16: Op2= 43; break; // +
case 12: Op2= 45; break; // -
case 8: Op2= 42; break; // *
case 4: Op2= 47; break; // /
//case 15: Op2= 61; break; // =
}
Lcd_Chr(2, 12, op2);
//Addition
if (op2==43) {
Op1 = Op1-48;
kp = kp-48;
calc = kp+op1;

intToStr(calc, txt); // Transform Calc value to string
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,2, " Result is :");
Lcd_Out(2, 10, txt); // Display Calc value on Lcd
}
// Subtraction
if (op2==45) {
Op1 = Op1-48;
kp = kp-48;
calc = kp-op1;
if(op1>kp){
Calc=Op1-kp ;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,9,"-");
WordToStr(calc, txt); // Transform Calc value to string
// Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,2, " Result is :");
Lcd_Out(2, 10, txt);
delay_ms(1200);
Lcd_Cmd(_LCD_CLEAR);
goto start;
}
WordToStr(calc, txt); // Transform Calc value to string
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,2, " Result is :");
Lcd_Out(2, 10, txt); // Display Calc value on Lcd
}

// Multiplication
if (op2==42) {
Op1 = Op1-48;
kp = kp-48;
calc = kp*op1;
WordToStr(calc, txt); // Transform Calc value to string
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,2, " Result is :");
Lcd_Out(2, 10, txt); // Display Calc value on Lcd
}

// Division
if (op2==47) {
Op1 = Op1-48;
kp = kp-48;
calc = kp/op1;
WordToStr(calc, txt); // Transform Calc value to string
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,2, " Result is :");
Lcd_Out(2, 10, txt); // Display Calc value on Lcd
}
delay_ms(1000);
goto start;
}
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top