The Godfather talking
This is god damn my place! Capisci?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 09, 2016, 04:25:53 16:25


Login with username, password and session length


Pages: [1]
Print
Author Topic: PIC16F877 communication with PC as Slave Modbus  (Read 4786 times)
0 Members and 1 Guest are viewing this topic.
We2
Guest
« on: July 09, 2008, 04:54:41 16:54 »

If I use PIC16F877 as slave device for modbus protocol with PC, how to program PIC as slave device in modbus protocol??
Logged
arash_tah
Active Member
***
Offline Offline

Posts: 113

Thank You
-Given: 18
-Receive: 6


« Reply #1 on: November 30, 2009, 05:53:05 05:53 »

This is also my question please help us
Logged
darck_khronos
Junior Member
**
Offline Offline

Posts: 59

Thank You
-Given: 4
-Receive: 93

Khronoscorp Systems


WWW
« Reply #2 on: November 30, 2009, 07:24:46 07:24 »

Incert Identifications in your pic

Exsample

Code: (c)
#include <18f4550.h>
#fuses NOWDT,NOPROTECT,NOLVP,INTRC_IO
#use delay (clock= 8000000) 
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#define EEPROM_SDA PIN_B0       
#define EEPROM_SCL PIN_B1       
#define RTC_SDA  PIN_B0
#define RTC_SCL  PIN_B1
#include <24256.c>
#include <ds1307.c>

void clock()
{
  char clok;
  BYTE secuni,secdec;
  BYTE minuni,mindec;
  BYTE hrsuni,hrsdec;
  BYTE diauni,diadec;
  BYTE mesuni,mesdec;
  BYTE aniouni,aniodec;
  BYTE dia,mes,anio,hrs,min,sec;
  BYTE dow;
  clok=getchar();
  if(clok=='E'){
  printf("\r\nEntrando a Ciclo De Escritura");
  secuni=getc();
  secdec=getc();
  minuni=getc();
  mindec=getc();
  hrsuni=getc();
  hrsdec=getc();
  diauni=getc();
  diadec=getc();
  mesuni=getc();
  mesdec=getc();
  aniouni=getc();
  aniodec=getc();
  sec=(secuni-48)+((secdec-48))*10;
  min=(minuni-48)+((mindec-48))*10;
  hrs=(hrsuni-48)+((hrsdec-48))*10;
  dia=(diauni-48)+((diadec-48))*10;
  mes=(mesuni-48)+((mesdec-48))*10;
  anio=(aniouni-48)+((aniodec-48))*10;
  ds1307_init();
  ds1307_set_date_time(dia,mes,anio,dow,hrs,min,sec);
  delay_ms(1000);
  ds1307_get_date(dia,mes,anio,dow);
  ds1307_get_time(hrs,min,sec);
  printf("\f\%02d/\%02d/\%02d\r\n",dia,mes,anio);
  printf("\%02d:\%02d:\%02d", hrs,min,sec);
  printf("\r\nRegresando a Ciclo Fuera De Escritura");}
  if(clok=='L'){
  printf("\r\nLellendo Relog Espere 1 Segundo");
    delay_ms(1000);
  ds1307_get_date(dia,mes,anio,dow);
  ds1307_get_time(hrs,min,sec);
  printf("\f\%02d/\%02d/\%02d\r\n",dia,mes,anio);
  printf("\%02d:\%02d:\%02d", hrs,min,sec);
    printf("\r\nLellendo Relog Espere 1 Segundo");
    delay_ms(1000);
  ds1307_get_date(dia,mes,anio,dow);
  ds1307_get_time(hrs,min,sec);
  printf("\f\%02d/\%02d/\%02d\r\n",dia,mes,anio);
  printf("\%02d:\%02d:\%02d", hrs,min,sec);
    printf("\r\nLellendo Relog Espere 1 Segundo");
    delay_ms(1000);
  ds1307_get_date(dia,mes,anio,dow);
  ds1307_get_time(hrs,min,sec);
  printf("\f\%02d/\%02d/\%02d\r\n",dia,mes,anio);
  printf("\%02d:\%02d:\%02d", hrs,min,sec);
  printf("\r\nRegresando a Ciclo Fuera De Lectura");
  delay_ms(100);}
}

void memoria()
{
   char mem;
   byte uni,dec,cent,dir; //direccion
   int fecha,hora,temp,dato; //dato
   init_ext_eeprom();
   mem=getchar();
      if(mem=='E'){
      printf("\r\nEscribiendo En Memoria");
      delay_ms(5);
         uni=getch();
         dec=getch();
         cent=getch();
         fecha=getch();
         hora=getch();
         temp=getch();
         dir=(uni-48)+ ((dec-48)*10)+ ((cent-48)*100);
         dato=(fecha)+ ((hora)*10)+ ((temp)*100);
         write_ext_eeprom(dir,dato); }
       if(mem=='L'){
       printf("\r\nLellendo Memoria ");
       delay_ms(5);
         uni=getch();
         dec=getch();
         cent=getch();
         dir=(uni-48)+ ((dec-48)*10)+ ((cent-48)*100);
         printf("\r\nDatos Leidos %d",dir);
         delay_ms(5);
         dato=read_ext_eeprom(dir);
         printf("\r\nFormato FHT %d Dato Guardado %d",dato,dir);
      }
}

void main()
{
char entrada;
    for(;;){
   printf("\r\n Selecione 'C' Para Relog y 'M' Para Memoria");
    entrada=getchar();
    if(entrada=='C')
         {
   printf("\r\n Ingresando a Relog Seleccione Su Opcion");
   clock();
         }
    if(entrada=='M')
         {
    printf("\r\n Ingresando a Memoria Seleccione Su Opcion");
    memoria();
         }
            }
}

Logged
arash_tah
Active Member
***
Offline Offline

Posts: 113

Thank You
-Given: 18
-Receive: 6


« Reply #3 on: November 30, 2009, 07:06:14 19:06 »

Hi darck_khronos  thanx for your attention but in your code there is no comment
What are they for?
we asked about modbus!
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC