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.

[PIC] C Code for LM35 with PIC16F887 in HTC c compiler

Status
Not open for further replies.
Re: PIC16F887 DS1307 I2C Serial Communication Automation

Is the "CONTROL" register of DS1307 is at the address of 0x00 that only in which some Ch bit is there ??
 

Re: PIC16F887 DS1307 I2C Serial Communication Automation

Is the "CONTROL" register of DS1307 is at the address of 0x00 that only in which some Ch bit is there ??

no control resistor is on 0X07h address.

by the way I have also some doubts in this resistor setting..
go through below link also.
https://www.edaboard.com/threads/309008/
 

Re: PIC16F887 DS1307 I2C Serial Communication Automation

Jay have u got the current time & Date using this code only at hyper terminal or LCD ??
 

Re: PIC16F887 DS1307 I2C Serial Communication Automation

Jay have u got the current time & Date using this code only at hyper terminal or LCD ??

No still I am working on this to get that..
 

Re: PIC16F887 DS1307 I2C Serial Communication Automation

Could I set my PC time to DS1307 time?

Yes you can. You will have to write a PC application(using VB or java) which gets the system time and then send it via. UART on request from the microcontroller.

Regards,
Raj Gunaseelan
 

Re: PIC16F887 DS1307 I2C Serial Communication Automation

Yes you can. You will have to write a PC application(using VB or java) which gets the system time and then send it via. UART on request from the microcontroller.

Regards,
Raj Gunaseelan

isn't any function directly in MPLAB IDE or PIC library that I can use for same?
or else not any way to write in c?
 

Re: PIC16F887 DS1307 I2C Serial Communication Automation

hello,

I do that with my application EDFinfo.. refresh date and time by PC terminal
and diplay on Nokia3310

Written in C18 for 18F..but easy to adapt..

Code:
static unsigned char buffer[64];

unsigned int  i,j,k,l,m;
volatile unsigned char c1;
volatile unsigned int Elapsed;
volatile int  DataReady1;
volatile int i1;
volatile int Index;



//-------- interrupts---------------

void Serial_ISR(void);
 //gestionnaire d'interruption
//------------------------------
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
  _asm
    goto Serial_ISR //jump to interrupt routine
  _endasm
}
#pragma code


#pragma interrupt Serial_ISR
void Serial_ISR()
 {
     
 // Gestion IT UART1  sur  Serial com1 19200,N,8,1
  if(PIR1bits.RC1IF) // si une interruption arrive
  {
   c1 =Read1USART(); // le lire => RAZ  RCIF
  if(RCSTA1bits.FERR==1 )
   {
     RCSTA1bits.SPEN = 0 ;
     RCSTA1bits.SPEN= 1 ;
     c1=0;
      }
   if (RCSTA1bits.OERR==1)    // voir parag 16.1.26 p273
   {
       RCSTA1bits.CREN = 0 ;
       RCSTA1bits.CREN = 1 ;
     c1=0;
     } 
   // CR ou LF ou depassement buffer valide le buffer
    if((c1 != CR) && (c1 != LF) && (i1<=64)) 
   {
      buffer[i1] = c1;      
      i1++; 
      DataReady1 = 0; 
     }
     else 
      {
      buffer[i1] = 0;         //  0 a la fin du string
      DataReady1 = 1;      // drapeau Data recue
      i1=0;
        }
    PIR1bits.RC1IF=0;      // Raz drapeau IT
  }
}

void MAJ_RTC()
{
     m=2; // passe par dessus "U;"
     j=0;
     PIE1bits.RCIE = 0;
     l=strlen(buffer);
    // #ifdef Debugging 
     k=fprintf(_H_USART,"\n\rMise a l'heure de %03d cars =%s  buffer{0)=%c   Buffer[l-1]=%c\n\r",l,buffer,buffer[0],buffer[l-1]); 
    // #endif    
    // from appli Appinventor  U;15;10;13;2;14;25;#  + CR
    // from Vbray U;15;10;13;2;14;25;#035#013
     if ((buffer[0]=='U')&& (buffer[l-1]=='#') && (l<21))
     {
       // k=fprintf(_H_USART,"\n\rMise a l'heure : %s   %2d cars\n\r",buffer,l);      
         for (i=2;i<l;i++)
          { if(buffer[i]==';')
              { 
                buffer[i]=0;    
                DateTime[j]=atoi(buffer+m);
                m=i+1;
                j++;
              } 
          }// for i 
       // ne pas oublier le dernier! 
        buffer[l-1]=0; // elimine # en fin de chaine
        DateTime[j]=atoi(buffer+m);
        min=DateTime[5];
        heure=DateTime[4];
        jour=DateTime[0];
        mois=DateTime[1];
        An=DateTime[2];
        dow=DateTime[3]; // jour de la semaine sur 1 seul digit
        set_datetime( jour,mois,An,dow,heure,min);    
        buffer[0]=0;
        j=0;
        NbErr=0;
        DataReady1 =0;
        PIE1bits.RCIE = 1;
     }// if buffer[0]='U'
 }   




void main()
{

  i1=0;
  DataReady1 = 0;
  c1=0;
 
  Init_Hardware(); 
 
  buffer[0]=0;
   
  Init_UART1();         // 19200 bds at 10MHz
 
  gotoxy(0,3);     
  Nokia_PutRomString("Init UART1 RN41 ");
  
  // ----- UART1 enable interupt---------
  RCSTA1bits.CREN = 1 ; // enable reception
  PIE1bits.RCIE = 1;    // enable Interrupt on receive uART1
  IPR1bits.RC1IP=1;     // high priority level
  RCONbits.IPEN = 1;    // Enable High interrupt priority model.
  INTCONbits.PEIE = 1;  // autorisation des IT des périphériques
  INTCONbits.GIE =1 ;  // autorisation globale des IT
  

  while (1) // ======= Boucle Principale  ===============
  {
  DataReady1 = 0;         // Data not received
  PIR1bits.RC1IF=0;
  c1 =Read1USART() ; // vide buffer
  i1=0;  
  buffer[0]=0;
  .....
  
  // mise a l'heure par clavier UART1 com1 19200,N,8,1
 // sequence attendue  U;JJ;MM,AA,J;HH;MN#   20 cars   (secondes forcees a 00)
 // attention JS sur 1 seul digit
 // macro sur touche vbray : U;29;10;50;4;18;33#035#013
 
  // si receptionde U au debut et # àpres 17 cars
  if (( DataReady1 == 1)&& (buffer[0]=='U')&& (buffer[18]=='#'))
   {
     k=fprintf(_H_USART,"Recu ordre <U>pdate RTC \r\n ");
     MAJ_RTC();
   }     
  // ... Other treatments ............ 
  // si reception de RAZ
  if (( DataReady1 == 1)&& (buffer[0]=='R') && (buffer[1]=='A')&& (buffer[2]=='Z'))
   {
        k=fprintf(_H_USART,"Recu ordre RAZ \r\n ");
       RazIndex();
   }    
  
  .....
  other task here ....
  during these task, UART can receive data and store them into the buffer
  .....
  
  } // while(1)	  
 ...
  }
 
Re: PIC16F887 DS1307 I2C Serial Communication Automation

hello,

I do that with my application EDFinfo.. refresh date and time by PC terminal
and diplay on Nokia3310

Written in C18 for 18F..but easy to adapt..

ok I will convert it for HTC C compiler PIC16F887 and then check
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top