Pic18f4620 ve pic18f4550 Uart Haberleşme

Başlatan bymerag, 25 Kasım 2015, 08:09:30

bymerag

pic18f4620 nin kodları

// duplex config flags
#include  "__EthEnc28j60.h"
// duplex config flags
#define Spi_Ethernet_HALFDUPLEX     0x00                  // half duplex
#define Spi_Ethernet_FULLDUPLEX     0x01                  // full duplex
////////////////////////////////////////////////
#define G1 PORTA.RA0
#define G2 PORTA.RA1
#define G3 PORTA.RA2
#define G4 PORTA.RA3
#define G5 PORTA.RA4
#define G6 PORTA.RA5
////PORTA SABİTLER TANIMLANDI///////
//////////////////////////////////////////////
#define G7 PORTB.RB0
#define G8 PORTB.RB1
#define G9 PORTB.RB2
#define G10 PORTB.RB3
#define G11 PORTB.RB4
#define G12 PORTB.RB5
#define G13 PORTB.RB6
#define G14 PORTB.RB7
////PORTB SABİTLER TANIMLANDI///////
//////////////////////////////////////////////
#define G15 PORTC.RC2
////PORTC SABİTLER TANIMLANDI///////
//////////////////////////////////////////////
#define G16 PORTD.RD0
#define G17 PORTD.RD1
#define G18 PORTD.RD2
#define G19 PORTD.RD3
#define G20 PORTD.RD4
#define G21 PORTD.RD5
#define G22 PORTD.RD6
#define G23 PORTD.RD7
////PORTD SABİTLER TANIMLANDI///////
// mE ehternet NIC pinout
sfr sbit SPI_Ethernet_Rst at LATC0_bit;  // for writing to output pin always use latch (PIC18 family)
sfr sbit SPI_Ethernet_CS  at LATC1_bit;  // for writing to output pin always use latch (PIC18 family)
sfr sbit SPI_Ethernet_Rst_Direction at TRISC0_bit;
sfr sbit SPI_Ethernet_CS_Direction  at TRISC1_bit;
// end ethernet NIC definitions
int g=0;
int i=0,j=0,k=0;
char RISP1ON[3]={'1','1','2'};
char RISP1OFF[3]={'1','1','3'};
const char httpHeader[] = "HTTP/1.1 200 OK\nContent-type: "; // HTTP header
const char httpMimeTypeHTML[] = "text/html\n\n";             // HTML MIME type
const char httpMimeTypeScript[] = "text/plain\n\n";          // TEXT MIME type

// default html page
char    indexPage[] =
"<meta http-equiv=\"refresh\" content=\"10;url=http://192.168.2.245:8080\">\
<html><head><title>DENEME -aaa</title></head><body>\
<form name=\"input\" action=\"/\" method=\"get\">\
<table align=center width=200 bgcolor=#4974E2 border=2><tr>\
<td align=center colspan=4><font size=4 color=white><b>DENEME</b></font>\
</td></tr><tr>\
<td align=center bgcolor=#4974E2><input name=\"tst1\" width=60 type=\"submit\" value=\"MANUAL\"></td>\
<td align=center bgcolor=#4974E2><input name=\"tst2\" type=\"submit\" value=\"OTOMATIK\"></td>\
<td align=center bgcolor=#4974E2><input name=\"tst3\" type=\"submit\" value=\"AC\"></td>\
<td align=center bgcolor=#4974E2><input name=\"tst4\" type=\"submit\" value=\"KAPA\"></td>\
</tr>\
</table>\
</form></body></html>";
// network parameters  <meta http-equiv=\"refresh\" content=\"10;url=http://192.168.2.245:8080\">\

char   myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f};
char   myIpAddr[4]  = {192, 168, 2, 245};                         // my IP address
char   gwIpAddr[4]  = {192, 168, 2,  1};                         // gateway IP address
char   dnsIpAddr[4] = {192, 168, 2,  1};                         // dns IP address
char   ipMask[4]    = {255, 255, 255, 0};                         // subnet mask
// end network parameters

unsigned char   getRequest[20];                                    // HTTP request buffer

unsigned int  SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags)
{
  unsigned int    len;                            // my reply length
  if(localPort != 8080) return(0);             // I listen only to web request on port 80

  // get 10 first bytes only of the request, the rest does not matter here
  for(len = 0 ; len < 15 ; len++) getRequest[len] = SPI_Ethernet_getByte();
  getRequest[len] = 0;

  if(memcmp(getRequest, "GET /", 5)) return(0);  // only GET method
    if(!memcmp(getRequest+11, 112, 3)) //web'ten 112 gelirge g değişkenin 1 yap diyorum.
   
    {g=1;}

    if(!memcmp(getRequest+11, 113, 3)) //web'ten 112 gelirge g değişkenin 0 yap diyorum.
   
    {g=0;}

  len =  SPI_Ethernet_putConstString(httpHeader);               // HTTP header
  len += SPI_Ethernet_putConstString(httpMimeTypeHTML);  // with HTML MIME type
  len += SPI_Ethernet_putString(indexPage);                           // HTML page first part
  //len += SPI_Ethernet_putString(indexPage2);
  return len; // return to the library with the number of bytes to transmit
}
unsigned int  SPI_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength, TEthPktFlags *flags)

{
  return 0; // back to the library with the length of the UDP reply
}


void main()
{
UART1_Init(300);
Delay_ms(100);
ADCON1 |= 0x0F ;        // Analog Girişler Kapalı
CMCON  |= 0x07 ;        // Komparatörler
TRISA=0XFF;     //PORTA GİRİŞ
TRISB=0xFF;     //PORTB GİRİŞ
TRISB.RB0=0;
TRISC.RC6=0;  ////     TX BACAĞI ÇIKIŞ
TRISD=0XFF;     //PORTD  GİRİŞ
TRISC.RC2=1;    //RC2 GİRİŞ
//TRISE.RE0=1;    //RE0 GİRİŞ
PORTB=0X00;
PORTA=0X00;
PORTC.RC2=0;
PORTD=0x00;
  // starts ENC28J60 with: reset bit on PORTC.F0, CS bit on PORTC.F1,
  //                             my MAC & IP address,  full duplex
  SPI1_Init();
  // full duplex, CRC + MAC Unicast + MAC Broadcast filtering
  SPI_Ethernet_Init(myMacAddr, myIpAddr, Spi_Ethernet_FULLDUPLEX) ;

  // dhcp will not be used here, so use preconfigured addresses
  SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr);

  while(1)
  {
  if(g==1)
  {
  for(j=0;j<5;j++)
  {
  for(i=0;i<3;i++)
  {
  while(!UART1_Tx_Idle());
  UART1_Write(RISP1ON[i]);
  }

  }
  memcpy(indexPage+112,"-502",4);
  }

    SPI_Ethernet_doPacket();
  }
}



pic18f4550 nin kodları

char i=0,msg[6];
////////////////////////////////////////////////
#define C1 PORTA.RA0
#define C2 PORTA.RA1
#define C3 PORTA.RA2
#define C4 PORTA.RA3
#define C5 PORTA.RA4
#define C6 PORTA.RA5
////PORTA SABİTLER TANIMLANDI///////
//////////////////////////////////////////////
#define C7 PORTB.RB0
#define C8 PORTB.RB1
#define C9 PORTB.RB2
#define C10 PORTB.RB3
#define C11 PORTB.RB4
#define C12 PORTB.RB5
#define C13 PORTB.RB6
#define C14 PORTB.RB7
////PORTB SABİTLER TANIMLANDI///////
//////////////////////////////////////////////
#define C15 PORTC.RC2
////PORTC SABİTLER TANIMLANDI///////
//////////////////////////////////////////////
#define C16 PORTD.RD0
#define C17 PORTD.RD1
#define C18 PORTD.RD2
#define C19 PORTD.RD3
#define C20 PORTD.RD4
#define C21 PORTD.RD5
#define C22 PORTD.RD6
#define C23 PORTD.RD7
////PORTD SABİTLER TANIMLANDI///////
void main(void){
  ADCON1 |= 0x0F;
  CMCON  |= 7;
  UART1_Init(300);
  Delay_ms(100);
  TRISA = 0;
  TRISB = 0;
  TRISC.RC2=0;
  TRISD = 0;
  PORTA=0x00;
  PORTB=0x00;
  PORTD=0x00;
  PORTC.RC2=0;
  while(1)
  {
/* C2=1;
  Delay_ms(500);
  C2=0;                             
  Delay_ms(500);*/ bu 4 satır yüzünden sıkıntı varmış kaldırınca halloldu.
          if(UART1_Data_Ready())
          {
           msg[i]=UART1_Read();
           if(msg[0]=='1')// ilk gelen bilgi 1 ise
                                           {
                                            i++;
                                           }
          }
          if(i==3)
                  {
                   if(msg[0]=='1' && msg[1]=='1' && msg[2]=='2' )
                   {
                    C1=1; C7=1;
                   }
                   if(msg[0]=='1' && msg[1]=='1' && msg[2]=='3' )
                   {
                   C1=0; C7=0;
                   }
                    i=0;msg[0]=0;

                  }  //GELEN DEĞER 002 İSE C1 YANİ PORTA.RA0 AKTİF ET DEĞİŞKENLERİ SIFIRLA

}
}




sorun çözülmüştür.
  C2=1;
  Delay_ms(500);
  C2=0;                             
  Delay_ms(500);

satırları sildim düzeldi.

Selametle

Powered by EzPortal