1 |
|
2 | #include <xc.h> // XC8 General Include File
|
3 | #include <stdint.h> // For uint8_t definition
|
4 | #include <stdbool.h> // For true/false definition
|
5 |
|
6 | #pragma config WDT = OFF // WDT disabled (control is placed on SWDTEN bit)
|
7 | #pragma config XINST = OFF // Turn off support for extended instruction set
|
8 | #pragma config FOSC = HS // HS oscillator
|
9 |
|
10 | unsigned int counter1 = 0;
|
11 | int x = 0;
|
12 | unsigned char packetDest [6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // Multicast
|
13 | unsigned char packetSource [6] = {0xD8,0xD3,0x85,0x1F,0x11,0x01};
|
14 | unsigned char packetTypeIP [2] = {0x08,0x00};
|
15 | unsigned char packetIPHeader [12] = {0x45, 0x00, 0x00, 0x32, 0x11, 0xF7, 0x00, 0x00, 0x01, 0x11, 0x00, 0x00};
|
16 | unsigned char packetIPSource [4] = {0xC0, 0xA8, 0x01,0x06};
|
17 | unsigned char packetIPDest [4] = {0xE0, 0x00, 0x00,0xFC }; //broadcast
|
18 |
|
19 |
|
20 |
|
21 | void interrupt high_isr(void)
|
22 | {
|
23 | counter1++; //flash LED
|
24 | if(counter1 == 20000)
|
25 | {
|
26 | ETXSTH = 0x00;
|
27 | ETXSTL = 0x40;
|
28 | EDATA = 0;
|
29 | for (x=0; x<6 ;x++){
|
30 | EDATA = packetDest[x];
|
31 | }
|
32 | for (x=0; x<6 ;x++){
|
33 | EDATA = packetSource[x];
|
34 | }
|
35 | for (x=0; x<2 ;x++){
|
36 | EDATA = packetTypeIP[x];
|
37 | }
|
38 | for (x=0; x<12 ;x++){
|
39 | EDATA = packetIPHeader[x];
|
40 | }
|
41 | for (x=0; x<4 ;x++){
|
42 | EDATA = packetIPSource[x];
|
43 | }
|
44 | for (x=0; x<4 ;x++){
|
45 | EDATA = packetIPDest[x];
|
46 | }
|
47 | for (x=0; x<30 ;x++){
|
48 | EDATA = 0x01;
|
49 | }
|
50 | ECON1bits.TXRST = 1;
|
51 | PORTBbits.RB4 = !PORTBbits.RB4; //toggle LED counter1 = 0;
|
52 |
|
53 | }
|
54 | INTCONbits.TMR0IF = 0; // clear interrupt-flag
|
55 | }
|
56 |
|
57 | void low_priority interrupt low_isr(void){
|
58 | // will never happen
|
59 | }
|
60 |
|
61 | void main(void)
|
62 | {
|
63 |
|
64 | INTCONbits.GIE = 1; // enable global interrupts
|
65 | INTCONbits.TMR0IF = 0; // clear interrupt-flag
|
66 | INTCONbits.TMR0IE = 1; // enable interrupt for timer0
|
67 | T0CONbits.T0CS = 0; // clock source: 0 = internal clock, 1 = external clock
|
68 | T0CONbits.TMR0ON = 1; // switch timer0 on
|
69 |
|
70 | //Ethernet Setup
|
71 | ECON2bits.ETHEN = 1;
|
72 | ERXST = 0;
|
73 | ERXND = 0x3F;
|
74 | ERXRDPTL = 0x3F;
|
75 | ERXRDPTH = 0x00;
|
76 |
|
77 | ECON2bits.AUTOINC = 1;
|
78 | ECON1bits.TXRST = 0;
|
79 | ECON1bits.RXRST = 0;
|
80 | ECON1bits.CSUMEN = 0;
|
81 | ECON1bits.RXEN = 0; // dont receiv, i just wanna send
|
82 | while(!ESTATbits.PHYRDY);
|
83 | TRISBbits.RB4 = 0; // init LED
|
84 | PORTBbits.RB4 = 0; //
|
85 | PORTBbits.RB4 = !PORTBbits.RB4; //
|
86 |
|
87 | MACON1bits.MARXEN = 1;
|
88 | MACON3bits.PADCFG0 = 1;
|
89 | MACON3bits.PADCFG1 = 1;
|
90 | MACON3bits.PADCFG2 = 1;
|
91 | MACON3bits.TXCRCEN = 1;
|
92 | MACON3bits.FULDPX = 0;
|
93 | MACON3bits.FRMLNEN = 1; // ?
|
94 | MACON4bits.DEFER = 1;
|
95 | MAMXFL = 1518;
|
96 | MABBIPG = 0x12;
|
97 | MAIPGL = 0x12;
|
98 | MAIPGH = 0xC;
|
99 | MAADR1 = 0x01;
|
100 | MAADR2 = 0x11;
|
101 | MAADR3 = 0x1F;
|
102 | MAADR4 = 0x85;
|
103 | MAADR5 = 0xD3;
|
104 | MAADR6 = 0xD8;
|
105 |
|
106 |
|
107 |
|
108 | while(1);}
|