Subversion Repositories HomeAutomation

Rev

Rev 389 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 389 Rev 660
Line 16... Line 16...
16
#include <avr/io.h>
16
#include <avr/io.h>
17
 
17
 
18
/* lib files */
18
/* lib files */
19
#include <ip_arp_udp_tcp.h>
19
#include <ip_arp_udp_tcp.h>
20
#include <enc28j60.h>
20
#include <enc28j60.h>
-
 
21
#include <enc28j60_cfg.h>
21
#include <timeout.h>
22
#include <timeout.h>
22
#include <avr_compat.h>
23
#include <avr_compat.h>
23
#include <net.h>
24
#include <net.h>
24
 
25
 
25
// please modify the following two lines. mac and ip have to be unique
26
// please modify the following two lines. mac and ip have to be unique
Line 43... Line 44...
43
        // set the clock speed to 8MHz
44
        // set the clock speed to 8MHz
44
        // set the clock prescaler. First write CLKPCE to enable setting of clock the
45
        // set the clock prescaler. First write CLKPCE to enable setting of clock the
45
        // next four instructions.
46
        // next four instructions.
46
        CLKPR=(1<<CLKPCE);
47
        CLKPR=(1<<CLKPCE);
47
        CLKPR=0; // 8 MHZ
48
        CLKPR=0; // 8 MHZ
48
       
-
 
49
        /* enable PB0, reset as output */
-
 
50
        DDRB|= (1<<DDB0);
-
 
51
 
-
 
52
        /* set output to gnd, reset the ethernet chip */
-
 
53
        PORTB &= ~(1<<PB0);
-
 
54
        delay_ms(20);
-
 
55
        /* set output to Vcc, reset inactive */
-
 
56
        PORTB|= (1<<PB0);
-
 
57
        delay_ms(100);
-
 
58
       
49
 
59
        // LED
50
        // LED
60
        /* enable PB1, LED as output */
51
        /* enable PB1, LED as output */
61
        DDRD|= (1<<DDD6);
52
        DDRB|= (1<<DDB0);
62
 
53
 
63
        /* set output to Vcc, LED off */
54
        /* set output to Vcc, LED off */
64
        PORTD|= (1<<PD6);
55
        PORTB|= (1<<PB0);
65
 
56
 
66
        /*initialize enc28j60*/
57
        /*initialize enc28j60*/
67
        enc28j60Init(mymac);
58
        enc28j60Init(mymac);
68
        delay_ms(20);
59
        delay_ms(20);
69
       
60
       
Line 74... Line 65...
74
        // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
65
        // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
75
        enc28j60PhyWrite(PHLCON,0x476);
66
        enc28j60PhyWrite(PHLCON,0x476);
76
        delay_ms(20);
67
        delay_ms(20);
77
       
68
       
78
        /* set output to GND, red LED on */
69
        /* set output to GND, red LED on */
79
        PORTD &= ~(1<<PD6);
70
        //PORTB &= ~(1<<PB0);
80
        i=1;
71
        i=1;
-
 
72
       
-
 
73
        //while (enc28j60getrev() != 5) { }
-
 
74
       
-
 
75
        //if (enc28j60getrev() == 5) {
-
 
76
            /* set output to GND, red LED on */
-
 
77
        //  PORTB &= ~(1<<PB0);
-
 
78
        //}
81
       
79
       
82
        //init the ethernet/ip layer:
80
        //init the ethernet/ip layer:
83
        init_ip_arp_udp_tcp(mymac,myip,80);
81
        init_ip_arp_udp_tcp(mymac,myip,80);
84
 
82
 
85
        while(1){
83
        while(1){
Line 103... Line 101...
103
                        continue;
101
                        continue;
104
                }
102
                }
105
               
103
               
106
                if (i){
104
                if (i){
107
                        /* set output to Vcc, LED off */
105
                        /* set output to Vcc, LED off */
108
                        PORTD|= (1<<PD6);
106
                        //PORTB|= (1<<PB0);
109
                        i=0;
107
                        i=0;
110
                }else{
108
                }else{
111
                        /* set output to GND, LED on */
109
                        /* set output to GND, LED on */
112
                        PORTD &= ~(1<<PD6);
110
                        //PORTB &= ~(1<<PB0);
113
                        i=1;
111
                        i=1;
114
                }
112
                }
115
 
113
 
116
                       
114
                       
117
                if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
115
                if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){