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.

i want to make a digital clcok with pic!! please help me!!

Status
Not open for further replies.

shaomme05

Newbie level 5
Joined
Jun 12, 2009
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,358
hi

i want to make a digital clock with pic microcontroller using interrupt.
seven segment is to be used. ":" is to be blinked.

how to do this?

i use mikroC and pic16f877a.

please help me on coding and explanation!! i am very new in mcu.
 

Hi,
I made one such clock for me with mikroBASIC. I'm still using it :) . It was done with 16f873a. Can easily be ported to 16f877a and for mikroC. Hope it helps.
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.
There is only a problem with this that it is not the most accurate of clocks. In my use, I've noticed a change of about five minutes every month :p . But I guess this is for the crystal oscillator. Anyway, for more accurate, an RTC chip like DS1307/PCF8583 could be used.
In the mikroC v8.2 example for Software I2C, they have sample program for setting date in PCF8583, and in mikroBASIC, they have sample program for reading date from PCF8583. Combining these two for mikroC, you have a watch! :p
Circuit for my program:
86_1262803493.jpg
 

Re: i want to make a digital clcok with pic!! please help me

Hi Tahmid,

you missed
seven segment is to be used. ":" is to be blinked
on your schematic flip 3rd and 5th display connect the decimal points to RB7 and you can then have blinking colons.

(Happy user of EasyPic6, Proton+, ...)
 

Hi,
Yeah, I noticed that, but I just uploaded whatever I had designed for myself.
Hope that doesn't cause too much inconvenience.
Tahmid.
 

Re: i want to make a digital clcok with pic!! please help me

Tahmid said:
Hi,
Yeah, I noticed that, but I just uploaded whatever I had designed for myself.
Hope that doesn't cause too much inconvenience.
Tahmid.
No inconviniences, my clock just uses 6 pcs. 7 segment displays, 16f628 and a GPS module (I like accurate time :))
 

My one isn't the most accurate of clocks, but does okay as a DIY project. :p
Anyway, nice to hear about your project.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top