Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Project Request

Return
Isah Usman
apt_man

posted on 2011/09/06 11:22:38 AM CEST

Timers (Real time clock)

Stopwatch Timer (hr:min:sec) using keypad

Plz... can anyone help me with CODE or the IDEA how to input/change timer_variables [HR : MIN : SEC] from the keypad?

I download the"Programmable Relay Timers (PIC)" code given in this great site(LIBSTOCK) and try to edit it but still it didn't

work.

I'm using mikcroBasic for PIC as compiler, 2x16LCD, Keypad and PIC16F877a.

Thanks a lot, in advance.

USER Comments

Isah Usman
apt_man

posted on 2011/09/13 03:25:41 PM CEST

Mr. shivendra sahu,
thanks too for responding my post and yes u can share the Mickro C one too..
Bcuz Im sure it will be useful 2 me, and other users of this site.

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 86 in "Stopwatch Timer (hr:min:sec) using keypad" request.

Isah Usman
apt_man

posted on 2011/09/13 03:20:50 PM CEST

Great Thanks Mr. Miljenko :D!!!

Now I got the Idea I'm going to modify my code :)

Once again thank you so much (*_*)

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 85 in "Stopwatch Timer (hr:min:sec) using keypad" request.

Miljenko Majstrovicć
majstor

posted on 2011/09/12 03:58:33 PM CEST

I have a big program, and I resolved your problem. I try to reduce my old program, and I hope that I will reduce it OK. I didn't have enought time so iI didn't try it on my EASYPIC 5 and KAYPAD 4x4. If you have any question, I will respond to you.

program I_hope

' pic 16f887 8 MHz, Keypad on PORT D, LCD on PORT B
' read sub procedure enter, should look on variables asds i asm
' and proces of conversion this variables
' good luck

dim fgh, kp as byte
SD, SJ, MDd, MJ, SDJ, MDJ, adM, asdS as byte
TimeRead_year, TimeRead_months, TimeRead_day as byte
TimeRead_hours, TimeRead_minutes, TimeRead_seconds as byte
byteRead, yearmod4 as byte


dim txt1 as string [6]

sub procedure enter ()

unosenje:
for fgh=1 to 4
kp = 0 ' Wait for key to be pressed and released
while kp = 0
kp = Keypad_Released() ' Treba ukucati deset brojeva sata i
Delay_ms(10) ' temperature za prvo razdoblje
wend
select case kp
case 1 kp = 1
case 2 kp = 2
case 3 kp = 3
case 5 kp = 4
case 6 kp = 5
case 7 kp = 6
case 9 kp = 7
case 10 kp = 8
case 11 kp = 9
case 14 kp = 0
end select

EEPROM_WRITE (fgh,kp)
delay_ms (20)
next FGH
SD=Eeprom_read (1)
SJ=Eeprom_read (2)
MDd=Eeprom_read (3)
MJ=Eeprom_read (4)

SDJ=(SD*10)+SJ
MDJ=(MDd*10)+MJ

IF SDJ>24 then
Lcd_out(1, 1, "wrong hour")
DELAY_MS(1000)
LCD_Cmd(LCD_CLEAR)
GOTO UNOSENJE
END IF

IF MDJ>59 then
Lcd_out(1, 1, "wrong minute")
DELAY_MS(1000)
LCD_Cmd(LCD_CLEAR)
GOTO UNOSENJE
END IF

asdS=Dec2Bcd(SDJ)
adm=Dec2Bcd(MDJ)
I2C_Init(100000) ' initialize full master mode
I2C_Start() ' issue start signal
I2C_Wr($A0) ' address PCF8583
I2C_Wr(0) ' start from word at address 0 (configuration word)
I2C_Wr($80) ' write $80 to config. (pause counter...)
I2C_Wr(0) ' write 0 to cents word
I2C_Wr(0) ' write 0 to seconds word
I2C_Wr(adm) ' write admto minutes word
I2C_Wr(asds) ' write asds to hours word
I2C_Wr($03) ' write $24 to year/date word
I2C_Wr($01) ' write $08 to weekday/month
I2C_Stop() ' issue stop signal

I2C_Start() ' issue start signal
I2C_Wr($A0) ' address PCF8530
I2C_Wr(0) ' start from word at address 0
I2C_Wr(0) ' write 0 to config word (enable counting)
I2C_Stop() ' issue stop signal
end sub

sub procedure Display_Time()
txt1[0] = (TimeRead_hours div 10) + 48
txt1[1] = (TimeRead_hours mod 10) + 48
txt1[2] = ":"
txt1[3] = (TimeRead_minutes div 10) + 48
txt1[4] = (TimeRead_minutes mod 10) + 48
txt1[5] = 0
Lcd_Out(2,7,txt1)
end sub

sub procedure ReadTime()
dim updateYear as byte
updateYear = 0

I2C_start ' issue start signal
I2C_Wr($A0) ' address PCF8583
I2C_Wr(2) ' first word address
I2C_Repeated_Start ' issue repeated start signal
I2C_Wr($A1) ' address PCF8583 for reading R/W=1

byteRead = I2C_Rd(1) ' read seconds byte
TimeRead_seconds = (byteRead >> 4)*10 + byteRead and 0x0F ' transform seconds

byteRead = I2C_Rd(1) ' read minutes byte
TimeRead_minutes = (byteRead >> 4)*10 + byteRead and 0x0F ' transform minutes

byteRead = I2C_Rd(1) ' read hours byte
TimeRead_hours = (byteRead >> 4)*10 + byteRead and 0x0F ' transform hours

byteRead = I2C_Rd(1) ' read year/day byte
TimeRead_day = ((byteRead and %00110000) >> 4)*10 + byteRead and 0x0F ' transform day
yearmod4 = (byteRead and %11000000) >> 6 ' get year mod 4 from RTC

byteRead = I2C_Rd(0) ' read weekday/months byte
TimeRead_months = ((byteRead and %00010000) >> 4)*10 + byteRead and 0x0F ' transform months
I2C_Stop

I2C_start ' issue start signal
I2C_Wr($A0) ' address PCF8583
I2C_Wr($10) ' first word address
I2C_Repeated_Start ' issue repeated start signal
I2C_Wr($A1) ' address PCF8583 for reading R/W=1

byteRead = I2C_Rd(0) ' read year
if yearmod4 <> (byteRead mod 4) then ' check if year is incremented in RTC
Inc(byteRead) ' in this case the new value should be written to RTC RAM at address 16(0x10)
updateYear = 1
end if
TimeRead_year = byteRead

if updateYear > 0 then
I2C_Start ' issue start signal
I2C_Wr($A0) ' address PCF8530
I2C_Wr($10) ' start from word at address 16
I2C_Wr(TimeRead_year) ' write year to RAM
I2C_Stop ' issue stop signal
end if

end sub

sub procedure MainInit()
ADCON1 = 0x0F
I2C_Init(100000) ' initialize I2C
end sub


main:
ADCON1 = 0x0F ' Configure AN pins as digital I/O
TRISA = $FF

Lcd_Config(PORTB,3,2,1,0,PORTB,4,7,5) ' Lcd_Init_EP5, see Autocomplete
LCD_Cmd(LCD_CLEAR) ' clear display
LCD_Cmd(LCD_CURSOR_OFF)

Keypad_Init(PORTD)
enter () ' This sub procedure is solution for your request


while TRUE
maininit ()
readtime ()
display_time()
wend

end.

  • Rating:
5
No Abuse Reported

Do you want to report abuse comment ID: 77 in "Stopwatch Timer (hr:min:sec) using keypad" request.

shivendra sahu
sahu

posted on 2011/09/08 01:41:08 PM CEST

i have also requirement it

I'm using mikcroC for PIC as compiler, 2x16LCD, Keypad and PIC16F72 / PIC16F676

  • Rating:
3
No Abuse Reported

Do you want to report abuse comment ID: 66 in "Stopwatch Timer (hr:min:sec) using keypad" request.