📄 main.c
字号:
#include "uip.h"
#include "uip_arch.h"
#include "uip_arp.h"
#include "slipdev.h"
#include "httpd.h"
#include "my.h"
#include "serial.h"
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
unsigned char msec=0;//10毫秒钟
unsigned char sec=0;//秒钟
unsigned char min=0;//分钟
bit double_second=0;
sbit tcpled=P1^0;
//工作在16位定时模式,中断时间为10毫秒中断一次,误差小于千分之1,晶振使用22.1184Mhz
void timer0() interrupt 1
{
tl0=9;
th0=184;
msec++;
if(msec==100) //100分频,就是1秒一次
{
msec=0;
sec++;
double_second=1;
if(sec==60)
{
sec=0;//每分钟一次
min++;
if(min==60)
min=0;
}
}
}
void timer0_init()
{
timer0_mode_16bit;
th0=0;tl0=0;
timer0_run;
}
void interrupt_init(void)
{
timer2_interrupt_disable;
timer0_interrupt_enable;
timer1_interrupt_disable;
int0_interrupt_disable;
// timer0_priority_high;
int1_interrupt_disable;
serial_priority_high;
serial_interrupt_enable;
int0_mode_hightolow;
int0_priority_low;
}
/*-----------------------------------------------------------------------------------*/
void
main(void)
{
u8_t i;
//u16_t ii;
/*以下为单片机初始化 */
timer0_init();/*定时器初始化*/
serial_init();/*串口初始化*/
interrupt_init();/*中断初始化*/
putstring("8051 TCP/IP stack and web server running\n");
uip_init();
httpd_init();
slipdev_init();
tcpled = 0;
modem_request();
modem_reply();
while(1)
{
/* Let the tapdev network device driver read an entire IP packet
into the uip_buf. If it must wait for more than 0.5 seconds, it
will return with the return value 0. If so, we know that it is
time to call upon the uip_periodic(). Otherwise, the tapdev has
received an IP packet that is to be processed by uIP. */
uip_len = slipdev_read();
if(uip_len > 0)
{
tcpled = 1;
uip_process(UIP_DATA);
if(uip_len > 0)
slipdev_send();
}
tcpled = 0;
if(double_second)
{
double_second = 0;
for(i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
uip_arp_out();
slipdev_send();
}
}
}
}
}
/*-----------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -