📄 main.c.bak
字号:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <absacc.h>
#include <intrins.h>
#include "cp2200.h"
#include "arp.h"
//#include "icmp.h"
#include "udp.h"
#include "eth.h"
//#include "ip.h"
#include "regdefine.h"
#include "ne2000.h"
#include "reg.h"
#include "pubilc.h"
/*************************************全局变量的声明**********************************/
unsigned xdata timer0_count; //定时器2中断使用 用于清狗
union NetNode xdata myNode;//定义本机网络地址
//extern union arp_table_type arp_tab[MaxLenARPtable];
unsigned char xdata udp_test[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
union ip_address_type xdata pc_ip_addr;
/************************************初始化函数声明************************************/
void cp2201_restart ();
/*void init_watchdog();
void start_on_watchdog();*/
//void stop_watchdog();//看门狗
//void pfarpb( );
/*************************************主函数*******************************************/
int main(void)
{
unsigned int tmp,i;
INT8U xdata inbuf[342];
SP=0x80; //设置椎栈起点
// IE=0x97;//开除了T1的所有中断
EA=1;
ET0=1;
ET2=1;
// EX1=1;
TMOD = 0x21; /*time1,8bit auto-reload,mode 2*/
TL1 = 0xf7;
TH1 = 0xf7; /* crystal oscillator clock 33Mhz,PCON=1,and so baud-rate=19200 */
SCON = 0x50; /* SM0=0,SM1=1,SM2=0,select mode 1,REN=1 */
PCON = 0x80; /* double the baud rate */
TR1 = 1; /* start timer1 */
TL0 = 0x41;
TH0 = 0xf5;
TR0 = 1;
// init_watchdog();
// start_on_watchdog();
TI=1;
// printf ("\n test=%.2x \n",(unsigned int)test);
printf ("PACBRIDGE");
cp2201_restart ();
INT0EN = 0x03;
INT1EN = 0x05;
tmp=PHY_Init();
printf ("\ntmp=%d\n" ,tmp);
MAC_Init();
arptab_init();
myNode.node.ip = IP4_ADDR(192,168,1,218);
myNode.node.mask = IP4_ADDR(255,255,255,0);
// myNode.node.gate = IP4_ADDR(192,168,1,1);
pc_ip_addr.dwords=IP4_ADDR(192,168,1,104);
RXCN = RXCLEAR; //清除接受缓冲
while(1)
{
if(CPRcv()) // Check if the current packet is valid
{ // On detection of a valid packet:
num_bytes = CP220x_Receive(inbuf);
if(num_bytes > 0)
{
eth_rcve( inbuf);
updatearptab();
}
}
}
}
/***********************************************中断函数************************************************/
void Timer0_ISR (void) interrupt 1 //1ms
{
TR0=0;
TH0 = 0xF5;
TL0 = 0x41;
if (Count1ms) Count1ms--;
TR0=1;
}
void timer2_int(void) interrupt 6 using 0
{
TR2=0;
TL2 = 0;
TH2= 0;
TF2=0;
timer0_count++;
if(timer0_count == 80)
{
timer0_count = 0;
WDT = 1; //refresh watchdog
}
TR2 = 1;
}
/******************************************初始化函数**********************************/
/*void init_watchdog() //看门狗程序初始化
{
WDTD = 0x00; /*period=(255-WDTD)*344604*1/fosc*/
// WDTC = 0x18; /*WDOUT=1,WDRE=1;*/
//}
/*void Timer0_Init (void)
{
TMOD|=0x1; //16Bit
TH0 = 0xF5; // set Timer0 to overflow in 1ms
TL0 = 0x41;
TR0 = 1; // START Timer0
}*/
/*void init_serial() //串口初始化 定时器1为波特率发生器 19200 数据位8 奇偶校验无 停止位1
{
TMOD = 0x21; /*time1,8bit auto-reload,mode 2
TL1 = 0xf7;
TH1 = 0xf7; // crystal oscillator clock 33Mhz,PCON=1,and so baud-rate=19200
SCON = 0x50; //SM0=0,SM1=1,SM2=0,select mode 1,REN=1
PCON = 0x80; //double the baud rate
TR1 = 1; // start timer1
TI = 0;
}*/
/*void start_on_watchdog()
{
SWDT = 1;
TR2 = 1;
}
void stop_watchdog()
{
SWDT = 0;
TR2 = 0;
}*/
/*void pfarpb( )
{
INT8U i,j;
printf ("\n");
for(j=0;j<2;j++)
{
for(i=0;i<12;i++)
{
printf ("%.2x",(unsigned int)arp_tab[j].bytes[i]);
printf ("-");
Delay1ms(10);
}
printf ("\n");
}
}*/
void cp2201_restart ()
{
printf ("\CP2201 restart start \n");
RST=0;
//加延时
Delay1ms(50);
Delay1ms(50);
Delay1ms(500);
RST=1;
Delay1ms(200);
Delay1ms(200);
if(INT0RD&0x30)
{
// regint0_value=INT0RD;
printf ("\CP2201 restart succeed \n");}
else
printf ("\CP2201 restart lost \n");
// printf ("\nINT0RD_RESTART=%.2x \n",(unsigned int)regint0_value);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -