Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <avr/io.h>
#include <stdlib.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "ip_arp_udp_tcp.h"
#include "websrv_help_functions.h"
#include "enc28j60.h"
#include "net.h"
#define REMOTE_PORT 9600
#define LOCAL_PORT 2000
#define BUFFER_SIZE 650
static uint8_t mac_address[6] = {0x22,0x22,0x22,0x10,0x00,0x33};
static uint8_t local_host[4] = {192,168,100,101};
static uint8_t gateway[4] = {192,168,100,1};
static uint16_t local_port = 2000;
static uint8_t buf[BUFFER_SIZE+1];
static uint8_t data[] = "OKey";
static uint8_t ok[]="123456";
static char State_Led[1];
static void net_process(void);
static void net_init(void);
static void Int_Init(void);
int main(void)
{
sei();
Int_Init();
net_init();
net_process();
return(0);
}
//Trnh phuc vu ngat cua INT0
ISR(INT2_vect)
{
PORTC^=~PIND;
}
static void Int_Init(void)
{
DDRC=0xFF;
PORTC=0x00;
DDRB&=~(0x04);
PORTB|=0x40;
DDRD=0x00; // input
PORTD=0xFF;
GICR |= (1<<INT2); // Enable external interrupt INT2
MCUCSR |= (0<<ISC2); // INT2 is executed on rising edge - 1( r
ising)-0(falling)
}
static void net_init (void)
{
enc28j60Init(mac_address);
_delay_ms(20);
enc28j60clkout(2);
_delay_ms(20);
enc28j60PhyWrite(PHLCON,0x476);
_delay_ms(20);
init_ip_arp_udp_tcp(mac_address,local_host,local_port);
client_set_gwip(gateway);
}
static void net_process(void)
{
uint16_t plen;
uint8_t payloadlen=0;
while(1)
{
// get the next new packet:
plen = enc28j60PacketReceive(BUFFER_SIZE
, buf);