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.

date and time display on LCD

Status
Not open for further replies.

vanvan00

Newbie level 6
Joined
Nov 13, 2009
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
How do i display real time and date with PIC18F452 and LCD panel? Anyone can help me with the code?
 

What type of lcd.
Operate manner is very different between different type.
 

Im using 2x16 LCD panel. Is there any mikroC codes which i can apply to display the date or the time itself?
 

so its not possible to do if i dont have the DS1307 chip?
 

It is, but with DS1307, it's more accurate.
I had coded one in mikroBASIC, hopefully you can convert it.
Code:
program sourcecode

symbol Selected = PORTA.0
symbol HrChange = PORTA.1
symbol MinChange = PORTA.2
symbol SecChange = PORTA.3
symbol Hr1224 = PORTA.4
symbol led1224 = PORTA.5

dim data7, num7 as byte
dim temp as byte
dim hr, min, sec as byte
dim hrten1224, hrone1224 as byte
dim HRTEN, HRONE, MINTEN, MINONE, SECTEN,SECONE as byte

sub procedure interrupt
      temp = temp + 1
      PIR1.TMR1IF = 0
      T1CON.TMR1ON = 0
      TMR1H = $3C
      TMR1L = $AF
      T1CON.TMR1ON = 1
      PORTA.3 = 1
end sub

sub procedure delay1ms
    delay_ms(1)
end sub

sub procedure delay50ms
    delay_ms(50)
end sub

sub procedure send7 (dim value, seven as byte)
    PORTC = 0
    select case value
           case 0 data7 = $C0
           case 1 data7 = $F9
           case 2 data7 = $A4
           case 3 data7 = $B0
           case 4 data7 = $99
           case 5 data7 = $92
           case 6 data7 = $82
           case 7 data7 = $F8
           case 8 data7 = $80
           case 9 data7 = $90
    end select
    PORTB = data7
    select case seven
           case 1 num7 = 1
           case 2 num7 = 2
           case 3 num7 = 4
           case 4 num7 = 8
           case 5 num7 = 16
           case 6 num7 = 32
    end select
    PORTC = num7
end sub

main:

     TRISB = 0
     PORTB = 0
     TRISC = 0
     PORTC = 0
     ADCON1 = 7
     TRISA = $1F
     T1CON = 0
     TMR1H = $3C
     TMR1L = $AF
     PIR1.TMR1IF = 0
     PIE1.TMR1IE = 1
     INTCON.GIE = 1
     INTCON.PEIE = 1
     T1CON.TMR1ON = 1
     while true
           if Selected then
              T1CON.TMR1ON = 0
              if Hr1224 then
                 delay50ms
                 hrten1224 = 1
                 hrone1224 = 3
                 led1224 = 1
              else
                 hrten1224 = 0
                 hrone1224 = 1
                 led1224 = 0
              end if
              if HrChange then
                 delay50ms
                 HRONE = HRONE + 1
                 if (HRONE > 9) then
                    HRONE = 1
                    HRTEN = HRTEN + 1
                 end if
                 if (HRTEN > hrten1224) and (HRONE > hrone1224) then
                    HRTEN = 0
                    HRONE = 0
                 end if
                 while HrChange
                 wend
              end if
              if MinChange then
                 delay50ms
                 MINONE = MINONE + 1
                 if (MINONE > 9) then
                    MINONE = 0
                    MINTEN = MINTEN + 1
                 end if
                 if (MINTEN > 5) then
                    MINTEN = 0
                    MINONE = 0
                 end if
                 while MinChange
                 wend
              end if
              if SecChange then
                 delay50ms
                 SECONE = SECONE + 1
                 if (SECONE > 9) then
                    SECONE = 0
                    SECTEN = SECTEN + 1
                 end if
                 if (SECTEN > 5) then
                    SECTEN = 0
                    SECONE = 0
                 end if
                 while SecChange
                 wend
              end if
           else
              T1CON.TMR1ON = 1
           end if
           if (temp = 20) then
               temp = 0
               sec = sec + 1
               SECONE = SECONE + 1
           end if
           if (SECONE > 9) then
              SECONE = 0
              SECTEN = SECTEN + 1
           end if
           if (SECTEN > 5) then
              SECTEN = 0
              SECONE = 0
              MINONE = MINONE + 1
           end if
           if (MINONE > 9) then
              MINONE = 0
              MINTEN = MINTEN + 1
           end if
           if (MINTEN > 5) then
              MINTEN = 0
              MINONE = 0
              HRONE = HRONE + 1
           end if
           if (HRONE > 9) then
              HRONE = 0
              HRTEN = 1
           end if
           if (HRTEN > hrten1224) and (HRONE > hrone1224) then
              HRTEN = 0
              HRONE = 0
              MINTEN = 0
              MINONE = 0
              SECTEN = 0
              SECONE = 0
           end if
           send7(HRTEN, 1)
           delay1ms
           send7(HRONE, 2)
           delay1ms
           send7(MINTEN, 3)
           delay1ms
           send7(MINONE, 4)
           delay1ms
           send7(SECTEN, 5)
           delay1ms
           send7(SECONE, 6)
           delay1ms
     wend
end.
86_1262803493.jpg
 

thanks but im not so sure how to convert to MikroC language its ok how about do u know anything about LM35 temperature sensor with PIC18F452?
 

Hi vanvan00,
Yeah, I have that project done, but that too in mikroBASIC. But if you give me some time, I can code one in mikroC.

Added after 14 minutes:

Code:
unsigned long ADCResult;
unsigned int value[3];
char vstring[3];

void GlobInit(void){
    TRISB = 0;
    PORTB = 0;
    TRISA = 1;
    ADCON1 = 0x4E;
    LCD_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0);
    LCD_Cmd(LCD_CLEAR);
    LCD_Cmd(LCD_CURSOR_OFF);
    LCD_Out(1, 1, "Temp:");
    LCD_Out(1, 15, "'C");
}

void main(){
    GlobInit();
    while (1){
          ADCResult = (ADC_Read(0) * 500) >> 10;
          value[0] = ADCResult / 100;
          value[1] = (ADCResult / 10) % 10;
          value[2] = ADCResult % 10;
          vstring[0] = value[0] + 48;
          vstring[1] = value[1] + 48;
          vstring[2] = value[2] + 48;
          LCD_Out(1, 10, vstring);
          delay_ms(50);
    }
}
I think that's it.
mikroBASIC code:
Code:
program thermometer452

dim LCD_RS as sbit at RB4_bit
    LCD_EN as sbit at RB5_bit
    LCD_D4 as sbit at RB0_bit
    LCD_D5 as sbit at RB1_bit
    LCD_D6 as sbit at RB2_bit
    LCD_D7 as sbit at RB3_bit

    LCD_RS_Direction as sbit at TRISB4_bit
    LCD_EN_Direction as sbit at TRISB5_bit
    LCD_D4_Direction as sbit at TRISB0_bit
    LCD_D5_Direction as sbit at TRISB1_bit
    LCD_D6_Direction as sbit at TRISB2_bit
    LCD_D7_Direction as sbit at TRISB3_bit

dim ADCResult as longword
dim value as word[3]
dim vstring as string[3]

sub procedure GlobInit
    TRISB = 0
    PORTB = 0
    TRISA = 1
    ADCON1 = $4E
    LCD_Init
    LCD_Cmd(_LCD_CLEAR)
    LCD_Cmd(_LCD_CURSOR_OFF)
    LCD_Out(1, 1, "Temp:")
    LCD_Out(1, 15, "'C")
end sub

main:
     GlobInit
     while true
           ADCResult = (ADC_Read(0) * 500) >> 10
           value[0] = ADCResult div 100
           value[1] = (ADCResult div 10) mod 10
           value[2] = ADCResult mod 10
           vstring[0] = value[0] + 48
           vstring[1] = value[1] + 48
           vstring[2] = value[2] + 48
           LCD_Out(1, 10, vstring)
           delay_ms(50)
     wend
end.
 

i have to display maximum temperature and minimum temperature on the LCD when i press 1 button connected to Port A e.g press once it show maximum temperature and press the 2nd time it will show the minimum temperature
 

Hi vanvan00,
I didn't get what you meant by "display maximum temperature and minimum temperature".
 

i have to display maximum temperature and minimum temperature on the LCD
The circuit should have a temperatur sensor, I think, presently it doesn't. You also should know, how you want to reset
the min/max memory.
 

this is my code but i think it lack of something as it dont work at all



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
unsigned oldstate0;
unsigned oldstate1;
unsigned tMax,tMin;
 
unsigned temp_value;
char out[12],out2[12];              // declares array of 12 characters
float dec_value;
 
void loop1() {
 
Lcd_Out(1,1,"Welcome to ECE");   //Prints text on LCD at 1st row and 1st column
 
Lcd_Chr(2,7,out[3]);        //Prints on LCD at 2nd row and 3rd column
Lcd_Chr_Cp(out[4]);
Lcd_Chr_Cp('.');            //Prints decimal point on LCD
Lcd_Out(2,10,out2);          //Prints reminder on LCD at 2nd row and 6th column
Lcd_Chr_Cp(223);         //Prints degree symbol on LCD at 2nd row and 7th column
Lcd_Chr_Cp('C');           //Prints Celsius symbol
delay_ms(3000);                // Sample at 3 sec
}
 
void main() {
ADCON1 = 0x80;                      // Configure analog input
TRISA = 0xFF;                        // PORTA as input
TRISB = 0x00;                       // PORTB as ouput
Lcd_Init(&PORTB);                   //Initialise LCD with PORT B
Lcd_Cmd(LCD_CLEAR);                // Clear LCD
Lcd_Cmd(LCD_CURSOR_OFF);
 
do {
 
temp_value = (Adc_Read(0)/2); // Read analog input
WordToStr(temp_value,out);    // convert hex to string
dec_value = (adc_read(0)%10);  //get the remainder so that it can display the up to 1 decimal place
floattostr(dec_value,out2);  // //remove blank spaces
 
  if (temp_value > tMax) {
  tMax = temp_value;
  }
  if (temp_value < tMin) {
  tMin = temp_value;
  }
 
if ( Button(&PORTA,0,10,1 )) oldstate0 = 1 ;
if ( oldstate0 && Button(&PORTA,1,10,0 )) {
 
    Lcd_Init(&PORTB);
    Lcd_Out(2,1,"Max");
      loop1();
}
 
if ( Button(&PORTA,0,10,1 )) oldstate1 = 1 ;
if ( oldstate1 && Button(&PORTA,0,10,0 )) {
     {
     Lcd_Init(&PORTB);
     Lcd_Out(2,1,"Min");
      loop1();
     }
}
} while(1);
}

 

anyone understand my question on this?
 

hi tahmid!

I'm interested in your code. What I'm trying to do is to monitor my current for 24 hours for 30 days, so, I need a clock. So far, I've used PORTs A,B, and D for my keypad, lcd and ADC program. I still have to interface the PIC with a gsm modem.

So, How do I program the clock with time and date and display it on LCD? I only have Ports C and E left.

I'm using 16f877a and MikroBasic.

Please help...:-(

Thank you..

Sincerely,

Heina
 

Hi Heina,

If you need an accurate clock (as you are interfacing your PIC with GSM modem) you should consider Telit GM862 GPS module.

When you initialize your system, you should periodically check for valid GPS lock, and when you obtain one, you will have clock information (UTC). No more clock/time/date routines using TMRx's :)

From here on, it's all up to you and your programming skills.

HTH
 

gps..wow..sounds cool.. sounds expensive..hahaha :-D hmm.. we have a tight budget..lol uhm, I dunno i we'll be able to afford that. =/

if I knew that gps thing would be helpful, I should've bought a gsm/gprs modem instead.. anyways, what's done is done.. I have a plain gsm modem. :-D I should figure something out from here..

uhm.. do u have any other suggestions zasto?
I could use some...

Thank you..:)

Sincerely,

Heina
 

Heina,

For accurate, a DS1307 or PCF8583 RTC chip should be enough. Interface this to the microcontroller. If your I2C/TWI pins are occupied, use software I2C/TWI.

Hope this helps.
Tahmid.
 

Hi Heina,

as Tahnid wrote, you can use DS or PCF RTC chip, but you must consider that you will need an external battery for RTC backup, and must set the clock at some time during initialization or at some point in time during run (SMS comes to my mind :))

You have not wrote which GSM modem you plan to use.

HTH
ZASto
 

I'm using a Benq M23 gsm modem. I dunno if you're familiar with it, but that's what we commonly use for projects here in the philippines.

@ Tahmid and @zasto : uhm, how do I interface the DS1307 or PCF8583 with the PIC 16F877A? Could you help me with the code coz I have no idea on using it? btw, I'm using Mikrobasic..

Thank you so much for replying. Very much appreciated. <3


Sincerely,

heina
 

Hi heina,

First download the datasheet of DS1307. Look at the registers. Use the I2C library in mikroBASIC.

I have a code made with ATmega88. Give me some time. I'll convert it to PIC16F877A.

Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top