25 Februari 2013

Jam Digital dengan Mode 12/24

Rangkaian :

Source Code : Bascom AVR$regfile = "m8def.dat"$crystal = 1000000'------------------------ lcd -----------------------------------------------Config Lcd = 16 * 2Config Lcdpin = Pin , Rs = Pind.0 , E = Pind.1 , Db4 = Pind.2 , Db5 = Pind.3 , Db6 = Pind.4 , Db7 = Pind.5Cls'--------------------------- ds 1307 -----------------------------------------$lib "ds1307clock.lib"'configure the scl and sda pinsConfig Sda = Portd.7Config Scl = Portd.6'address of ds1307Const Ds1307w = &HD0 ' Addresses of Ds1307 clockConst Ds1307r = &HD1'------------------------------ key --------------------------------------------Config Pinc.1 = InputConfig Pinc.2 = InputConfig Pinc.3 = InputConfig Pinc.4 = Input'------------------------------------------------------------------------------Config Debounce = 30Dim A As Byte , B As Byte , Data1 As Byte , C As ByteDim Seco As Byte , Mine As Byte , Hour As Byte'----------------------------------------------------------------------------Cursor Off'-----------------------------ClsLocate 1 , 6Lcd "Hello"Locate 2 , 1Lcd "WWW.elec4u.ir"Wait 2For A = 1 To 15 Shiftlcd LeftWaitms 300NextCls'-------------------------------------------------------------------------------Main:Do Gosub Ds1307 Gosub 24_12 Gosub ChekkeyLoop'-------------------------------------------------------------------------------Ds1307: I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' start address in 1307 I2cstart ' Generate start code I2cwbyte Ds1307r ' send address I2crbyte Seco , Ack 'sec I2crbyte Mine , Ack ' MINUTES I2crbyte Hour , Nack ' Hours I2cstop Seco = Makedec(seco) : Mine = Makedec(mine) : Hour = Makedec(hour) If Seco > 59 Then Seco = 0 If Mine > 59 Then Mine = 0 If Hour > 23 Then Hour = 0 Gosub Seco End IfReturn'------------------------------------------------------------------------------- 24_12: If Pinc.4 = 1 Then Gosub Disply_24 If Pinc.4 = 0 Then Gosub Disply_12 Return'-------------------------------------------------------------------------------Disply_24: Locate 1 , 1 Lcd "Time = " ; Hour ; ":" ; Mine ; ":" ; Seco ; " " Locate 2 , 6 Lcd "(24)"Return'-------------------------------------------------------------------------------Disply_12: If Hour = 0 Then Hour = 12 If Hour > 12 Then Hour = Hour - 12 Locate 1 , 1 Lcd "Time = " ; Hour ; ":" ; Mine ; ":" ; Seco ; " " Locate 2 , 6 Lcd "(12)"Return'-------------------------------------------------------------------------------Chekkey: Debounce Pinc.1 , 0 , Seco , Sub Debounce Pinc.2 , 0 , Mine , Sub Debounce Pinc.3 , 0 , Hour , SubReturn'---------------------------------------------Seco: Incr Seco If Seco > 59 Then Seco = 0 Seco = Makebcd(seco) I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' starting address in 1307 I2cwbyte Seco I2cstopReturn'-------------------------------------Mine: Incr Mine If Mine > 59 Then Mine = 0 Mine = Makebcd(mine) I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 1 ' starting address in 1307 I2cwbyte Mine I2cstopReturn'-------------------------------------Hour: Incr Hour If Hour > 23 Then Hour = 0 Hour = Makebcd(hour) I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 2 ' starting address in 1307 I2cwbyte Hour I2cstopReturn'-------------------------------------End

View the original article here

Ikuti Blog ini

Langganan

Mau dapet Update-an Blog ini lewat e-mail? Masukkin aja alamat Email kamu disini:

Dikirim Oleh FeedBurner