Jam digital ATmega 8535 7Segment dan LCD







ini Source codenya.

$regfile = "m8535.dat"
$crystal = 12000000
'------------------------  lcd -------------------------------------------------
Config Lcd = 16 * 2
Config Lcdpin = Pin , Rs = Pina.0 , E = Pina.1 , Db4 = Pina.4 , Db5 = Pina.5 , Db6 = Pina.6 , Db7 = Pina.7
Cls

'---------------------------  ds 1307 -----------------------------------------
$lib "ds1307clock.lib"
'configure the scl and sda pins
Config Sda = Portc.7
Config Scl = Portc.6
'address of ds1307
Const Ds1307w = &HD0                                        ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
'------------------------------ key --------------------------------------------
Config Pinc.1 = Input
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
Config Portb = Output
Config Portd = Output

Declare Sub Test(byval A1 As Byte)

'------------------------------------------------------------------------------
Config Debounce = 30

Dim A1 As Byte , B1 As Byte , B2 As Byte
Dim Seco As Byte , Mine As Byte , Hour As Byte

 '-------------------------------------------------------------------------------
Cursor Off
 '-------------------------------------------------------------------------------
Cls
Locate 1 , 1
Lcd "Jam Digital"
Waitms 100
Cls
  '-------------------------------------------------------------------------------
Main:
Do
          Gosub Ds1307
          Gosub 24_12
          Gosub Chekkey
 Loop
 '-------------------------------------------------------------------------------
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)

 Return
 '-------------------------------------------------------------------------------
  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 "Jam = " ; Hour ; ":" ;
         A1 = Hour
         Call Test(a1)
         Portd = &B00001000
         Portb = B2
         Waitms 30
         Portd = &B00000100
         Portb = B1
         Waitms 30                                          'call sub with parameters

         Lcd Mine ; ":" ;
         A1 = Mine
         Call Test(a1)
         Portd = &B00000010
         Portb = B2
         Waitms 30
         Portd = &B00000001
         Portb = B1
         Waitms 30

         Lcd Seco
         Locate 2 , 6
         Lcd "(24 Jam)"
         Wait 1

 Return
 '-------------------------------------------------------------------------------
 Disply_12:

         If Hour = 0 Then Hour = 12
         If Hour > 12 Then Hour = Hour - 12

         Locate 1 , 1
         Lcd "Jam = " ; Hour ; ":" ;

         A1 = Hour
         Call Test(a1)
         Portd = &B00001000
         Portb = B2
         Waitms 30
         Portd = &B00000100
         Portb = B1
         Waitms 30

         Lcd Mine ; ":" ;
         A1 = Mine
         Call Test(a1)
         Portd = &B00000010
         Portb = B2
         Waitms 30
         Portd = &B00000001
         Portb = B1
         Waitms 30

         Lcd Seco
         Locate 2 , 6
         Lcd "(12 Jam)"
 Return
 '-------------------------------------------------------------------------------
 Chekkey:

          Debounce Pinc.1 , 0 , Seco , Sub
          Debounce Pinc.2 , 0 , Mine , Sub
          Debounce Pinc.3 , 0 , Hour , Sub

 Return
 '--------------------------------------------------------------------------------
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
          I2cstop
 Return
 '-------------------------------------------------------------------------------
 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
          I2cstop
 Return
 '-------------------------------------------------------------------------------
 Hour:
          Incr Hour
          If Hour > 12 And Pinc.4 = 0 Then Hour = 0
          Hour = Makebcd(hour)
          I2cstart                                          ' Generate start code
          I2cwbyte Ds1307w                                  ' send address
          I2cwbyte 1                                        ' starting address in 1307
          I2cwbyte Hour
          I2cstop
 Return



Sub Test(byval A1 As Byte )                                 'start sub
B1 = A1 mod 10
B1 = Lookup(B1 , Dta)

B2 = A1 / 10
B2 = Lookup(B2 , Dta)
End Sub

Dta:
Data &H40 , &H79 , &H24 , &H30 , &H19 , &H12 , &H02 , &H78 , &H00 , &H10
 '-------------------------------------------------------------------------------




Semoga bermanfaat ......

1 comment:

  1. gan kalo pake ATmega16 dan g pake 7segmen, jadi cuma LCD aja kodingnya gimana ya??? apa sama cuma ganti intialnya aja??

    ReplyDelete

//