Bienvenue aux nouveaux arrivants sur FantasPic !

- Pensez à lire les règles durant votre visite, il n'y en a pas beaucoup, mais encore faut-il les respecter .
- N’hésitez pas à faire des remarques et/ou suggestions sur le Forum, dans le but de l'améliorer et de rendre vos prochaines visites plus agréables.
- Vous pouvez regarder votre "panneau de l'utilisateur" afin de configurer vos préférences.
- Un passage par "l'utilisation du forum" est recommandé pour connaître les fonctionnalités du forum.

--- L’équipe FantasPic ---
Tout ce qui n'a pas de catégorie !
Transfert Date Time de Android vers HC06 + PIC
pspic
Passioné
Passioné
Messages : 357
Âge : 77
Enregistré en : septembre 2017
Localisation : 68

#11 Message par pspic » sam. 27 avr. 2019 07:47

@pspic, Ton appli fonctionne bien chez moi. Voici sur un terminal ce que j’obtiens :

Code : Tout sélectionner

CONNECTED
26
;04;19;22;38;06D

Bonjour à tous,
Ce qui correspond 26/04/2019 à 22h38mn, le 6éme jour de la semaine.
06D est le délimiteur utile pour indiquer la fin de trame (UART1_READ_TEXT(Trame,"D",18) en Mikrobasic.
Le détail dont parlais Paul :
ModHc6.jpg









Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.

Transfert Date Time de Android vers HC06 + PIC
pspic
Passioné
Passioné
Messages : 357
Âge : 77
Enregistré en : septembre 2017
Localisation : 68

#12 Message par pspic » sam. 27 avr. 2019 12:53

Le code coté PIC en Mikrobasic :

Code : Tout sélectionner

 program Test_Rtc_MajAndroid
'Test module RTC DS1307 avec mise à jour depuis App Android en Bluetooth (27/04/2019)
'Avec correction heure d'été / hiver.
'App SetRtcBt.APK
'PIC 18F2420 8 MHz.
'RC3 PIC SCL --> SCL (Module RTC DS1307) + Pull up.
'RC4 PIC SDA --> SDA (Module RTC DS1307) + Pull up.
'RC6 PIC TX --> RX (Module HC-06)
'RC7 PIC RX --> TX (Module HC-06) + Pull up
dim seconds, minutes, hours, _day, _month, year, Yb,Yh, _Yh, _Yb,Njs as byte
    JdTxt, MdTxt, Ab,HdTxt,NdTxt,SdTxt,Yh1Txt,Yb1Txt,JsTxt,TypAn,HmTxt,MmTxt,HsTxt,MsTxt,TmTxt,TsTxt as string[3]
    Sj,Sm,Sh,Sn,Sx,Sa,Snj,_Yh11,_Yb11, Ver as byte
    Rec as string[16]
    Delim as string[2]
    Da as string[4]
    Dj,Dm,Hh,Hm,Js as string[2]
    TrRec,NumJour as byte

dim Soft_I2C_Scl  as sbit at RC3_bit
    Soft_I2C_Sda  as sbit at RC4_bit
    Soft_I2C_Scl_Direction as sbit at TRISC3_bit
    Soft_I2C_Sda_Direction as sbit at TRISC4_bit

'Lcd module connections
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
'_______________________________________________________________________________
Sub procedure interrupt  'IntRCIF
 if PIR1.RCIF = 1 then
   if (UART1_Data_Ready() <> 0) then
     UART1_READ_TEXT(Rec , Delim, 255)
     TrRec = 1
   end if
   PIR1.RCIF = 0
 end if
end sub
'_______________________________________________________________________________
 sub procedure SetRtc()
  Lcd_Cmd(_LCD_CLEAR)
 'Decode trame de mise à jour reçue
  JdTxt= Rec[0]+Rec[1]               'Jour
  MdTxt= Rec[3]+Rec[4]               'Mois
  HdTxt= Rec[9]+Rec[10]              'Heure
  NdTxt= Rec[12]+Rec[13]             'Minute
  SdTxt= "00"                        'Seconde
  Yh1Txt= "20"                       'M + C année
  Yb1Txt= Rec[6]+Rec[7]              'D + U année
  JsTxt= " "+Rec[16]                 'N° jour semaine 1 à 7 (1= dimanche)
  Sj= Dec2Bcd(Strtoword(JdTxt))      'Jour
  Sm= Dec2Bcd(Strtoword(MdTxt))      'Mois
  Sh= Dec2Bcd(Strtoword(HdTxt))      'Heure
  Sn= Dec2Bcd(Strtoword(NdTxt))      'Minute
  Sx= Dec2Bcd(Strtoword(SdTxt))      'Seconde
  Snj=Dec2Bcd(Strtoword(JsTxt))      'N° jour
   _Yh11= Dec2Bcd(Strtoword(Yh1Txt)) 'An MC adr $10
   _Yb11= Dec2Bcd(Strtoword(Yb1Txt)) 'An Du adr $11
  Delay_ms(100)
  I2C1_Start()              ' Start
  I2C1_wr(0xD0)             ' Addresse écriture RTC
  I2C1_wr(0)                ' Start addresse 0
  I2C1_wr(Sx)               '  Write Ss à l'adresse 2 contenant les secondes
  I2C1_wr(Sn)               '  Write Sn à l'adresse 3 contenant les minutes
  I2C1_wr(Sh)               '  Write Sh à l'adresse 4 contenant les heures
  I2C1_wr(Snj)              '  Write N° jour
  I2C1_wr(Sj)               '  Write Sj à l'adresse 5 contenant les Jour
  I2C1_wr(Sm)               '  Write Sm à l'adresse 6 contenant les mois
  I2C1_wr(_Yb11)            '  Write An (dizaine unité)
  I2C1_wr($90)              '
  I2C1_Stop()               ' stop signal
  delay_ms(500)
end sub
'_______________________________________________________________________________
sub procedure Lecture_Date_Heure()
  I2C1_Start()              ' Issue start signal
  I2C1_Wr(0xD0)             ' Addresse RTC
  I2C1_wr(0)                ' Start à l'adresse 0
  I2C1_Start()              ' start
  I2C1_wr(0xD1)             ' Addresse de lecture
  seconds = I2C1_Rd(1)      ' Read seconde byte
  minutes = I2C1_Rd(1)      ' Read minute byte
  hours = I2C1_Rd(1)        ' Read heure byte
  Njs  = I2C1_Rd(1)         ' Read N° jour byte
  _day = I2C1_Rd(1)         ' Read jour
  _month = I2C1_Rd(1)       ' Read N° jour/mois byte}
  Yb = I2C1_Rd(0)           ' Read dizaine unité an byte
  Yh =_Yh11                 ' An Millier centaine
  I2C1_Stop()               ' Issue stop signal}
end sub
'_______________________________________________________________________________
sub procedure Formatage_Date_Heure()
  seconds  =  ((seconds and 0x70) >> 4)*10 + (seconds and 0x0F)
  minutes  =  ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F)
  hours    =  ((hours and 0x30)  >> 4)*10  + (hours and 0x0F)
   Njs = Njs  and $07  _day = ((_day and 0x30) >> 4)*10 + (_day and 0x0F)
  _month    =  ((_month and 0x10)  >> 4)*10 + (_month and 0x0F)
  _Yh = ((Yh and 0xF0)>> 4)*10 + (Yh and 0x0F )
  _Yb = ((Yb and 0xF0)>> 4)*10 + (Yb and 0x0F )
'Heure d'été
 if _Day > 24 then
  if hours = 2 then
   if _month = 3 then
    if Njs = 1 then
      I2C1_Stop()
      I2C1_Start()
      I2C1_wr(0xD0)
      I2C1_wr(2)
      I2C1_wr(3)        'A 2 heure il est 3 heure
      I2C1_Stop()
    end if
  end if
  end if
 end if
'Heure d'hiver
 if _Day > 24 then
  if hours = 3 then
   if _month = 10 then
    if Njs = 1 then
     I2C1_Stop()
     I2C1_Start()
     I2C1_wr(0xD0)
     I2C1_wr(2)
     I2C1_wr(2)           'A 3 heure il est 2 heure
     I2C1_Stop()
    end if
   end if
  end if
 end if
end sub
'_______________________________________________________________________________
sub procedure Affiche_Date_Heure()
  Lcd_Chr(1, 1, (_day / 10)   + 48)    'Jour dizaine
  Lcd_Chr(1, 2, (_day mod 10)   + 48)  'Jour unité
  Lcd_Out(1,3,"/")
  Lcd_Chr(1,4, (_month / 10) + 48)     'Mois dizaine
  Lcd_Chr(1,5, (_month mod 10) + 48)   'Mois unité
  Lcd_Out(1,6,"/")
  Lcd_Chr(1,7, (_Yh / 10)   + 48)      'Année millier
  Lcd_Chr(1,8, (_Yh mod 10) + 48)      'Année centaine
  Lcd_Chr(1,9, (_Yb / 10)   + 48)      'Année dizaine
  Lcd_Chr(1,10, (_Yb mod 10) + 48)     'Année unité
  Lcd_Chr(2, 1, (hours / 10)   + 48)  'Heure dizaine
  Lcd_Chr(2, 2, (hours mod 10)   + 48)'Heure unité
  Lcd_Out(2,3,":")
  Lcd_Chr(2,4, (minutes / 10) + 48)   'Minute dizaine
  Lcd_Chr(2,5, (minutes mod 10) + 48) 'Minute unité
  Lcd_Out(2,6,":")
  Lcd_Chr(2,7, (seconds / 10) + 48)   'Seconde dizaine
  Lcd_Chr(2,8, (seconds mod 10) + 48) 'Seconde unité
  Lcd_Chr(2,12, (Njs mod 10) + 48)    'N° jour
  end sub
'_______________________________________________________________________________
main:
  Uart1_Init(9600)         'Init Usart
  Delay_ms(100)
  I2C1_Init(100000)        'Init Soft I2C
  INTCON.PEIE = 1          'Perif interupt enable = true
  PIE1.RCIE = 1
  INTCON.GIE = 1           'Global interupt enable = true
  Adcon1 = $0F             'Configure AN pins as digital I/O
  TRISA = 0
  PORTA = 0
  TRISB = 0
  PORTB = 0
  TRISB = 0
  Lcd_Init()                'Init Lcd
  Lcd_Cmd(_LCD_CLEAR)       'Clear Lcd display
  Lcd_Cmd(_LCD_CURSOR_OFF)  'cursor off
  TrRec = 0                 'Raz Trame reçu
  Delim =""+"D"+chr(13)     'Délimiteur trame recu
 while TRUE
  'Lecture RTC, formatage et affichage date time________________________________
    if TrRec = 0 then          'Si pas de mise à jour RTC
     Lecture_Date_Heure()      'Lecture dans RTC
     Formatage_Date_Heure()    'Formatage date et heure
     Affiche_Date_Heure()      'Affiche date heure
    end if
  'Set Rtc si trame de mise à jour reçue________________________________________
    if TrRec = 1 then
     SetRtc()
     TrRec = 0
    end if
   delay_ms(1000)
 wend
end.


Retourner vers « Coin Fourre-tout »

Qui est en ligne

Utilisateurs parcourant ce forum : Bing [Bot] et 39 invités