ccs c de rs485 ile pc arasında seri iletişim nasıl?

Başlatan forumsad, 19 Ağustos 2010, 12:16:29

forumsad

ccs c de rs485 ile pc arasında seri iletişim nasıl yapılır....
elimde bir rs485 kartı var bu kart pc'ye veri gönderiyor pc'deki delphi programı gönderilen bilgiyi alıyor...bu sistem pic16f877 ile protonda yazılan kod ile sorunsuz
çalışıyor....

fakat ben şu anda ccs c ile ve pic18f452 ile aynı uygulamayı yapmaya çalışıyorum ama bilğisayara sürekli bozuk veri gidiyor bu konuda deneyimli arkadaşların
yardımını bekliyorum....

ccs c de yazdığım kod

main.c
#include "E:\elektronik\ccs_pic\uygulamalar\seriiletisim\2_452\main.h"
#include "stdio.h"
#include <rs485_2.c>




void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
   //_____________________________________________________________-
   set_tris_d(0x00);    //portd çıkış
   set_tris_c(0x00);    //portc çıkış
   output_d(0x00);     //portu temizle
   output_c(0x00);     //portu temizle
   
  
   //____________________________________________________________________________
   //basla
   

        
        
   
   while(1){
       output_high(PIN_D0);
       delay_ms(200);
       output_low(PIN_D0);
       delay_ms(200);
       //putc (49); // bu $ekildede bilgi yollayabilirsin...
       //fputc("Merhaba\n" , seri1);  //hata veriyor
      printf("Merhaba\n\r");  
       //fprintf(seri1,"Merhaba\n");
       
       
       
       
       
       
       
   }
    
      
      
}




main.h
#include <18F452.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                      //Resistor/Capacitor Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES PUT                       //???BİLİNMİYOR

#use delay(clock=4000000)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)



#include <rs485_2.c>  //rs485 dosyasına hiç dokunmadım sadece include etttim


rs485 ile veri nasıl gönderilir???

forumsad

araştırdım şöyle bir şeyler buldum ama sonuç gene değişmedi

main.c
#include "E:\elektronik\ccs_pic\uygulamalar\seriiletisim\3_452\main.h"
  #include <stdio.h>


#define  RS485_RX_BUFFER_SIZE 64 
#define  RS485_USE_EXT_INT    TRUE 

int8 OUR_RS485_ID = 0; 
#define RS485_ID OUR_RS485_ID 

#include <rs485.c> 
#include <stdlib.h> 

   #define RS485_RX_PIN       PIN_C6   // Data receive pin 
   #define RS485_TX_PIN       PIN_C7   // Data transmit pin 
   #define RS485_ENABLE_PIN   PIN_E0   // Controls DE pin.  RX low, TX high. 
   #define RS485_RX_ENABLE    PIN_E1   // Controls RE pin.  Should keep low. 
    

char* s; 
int8 id;
int8 size;

void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
   output_high(PIN_E0);          //'452 den max485'e veri gönderme izni verildi
   output_low(PIN_E1);          //'com dan max485'e veri gönderme izni iptal
   while(1){
   for(size=0; s[size]!='\0'; ++size); 
   printf("Wait for bus"); 
   rs485_wait_for_bus(FALSE); 
   printf("bus released, sending message..."); 
   while(!rs485_send_message(id, size, s)) 
      delay_ms(OUR_RS485_ID); 
   printf("msg sent!"); 
   
   
       output_high(PIN_D0);
       delay_ms(400);
       output_low(PIN_D0);
       delay_ms(400);
   }
   
}



main.h
#include <18F452.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)