搜索
bottom↓
回复: 24

再贴一个地址,看看AVR的BASIC语言是如何实现TCP/IP的!!!!!!!

[复制链接]

出0入0汤圆

发表于 2005-12-28 23:55:22 | 显示全部楼层 |阅读模式
http://www.mcselec.com/index.php?option=com_content&task=view&id=154&Itemid=41



采用的网络芯片是NM7010A,这块板子的用户手册如下,非常详细,连电路图和PCB图都有!!!

点击此处打开armok0194786.pdf



怎么样?使用C语言的人们,看了感想如何???呵呵不要对号入座哦!!!



呵呵我的实际设计和这几个例子可以完全说明,BASIC语言在AVR中会有比较光明的前途,而且对于快速控制也是比较好的,呵呵呵想不到吧。。。。。
-----此内容被JAMESKING于2005-12-29,00:01:14编辑过

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2005-12-29 02:09:30 | 显示全部楼层
还添加一个文件,从网页上转下来的变成pdf的:

点击此处打开armok0194789.pdf

出0入0汤圆

发表于 2005-12-29 08:43:18 | 显示全部楼层
搞混了吧?

TCP/IP不是由AVR实现的。

用硬件实现TCP/IP协议的芯片在韩国面市



韩国一家互联网通信芯片设计公司用硬件实现了TCP/IP协议,因此只用一颗芯片就可简单方便地提供互联网接入功能。Wiznet公司的互联网解决方案已经被用于网络DVR、互联网机顶盒、网络摄像头和安全系统的监控设备中。它还可用于工业设备,如各种各样的控制、数据采集和测量设备等。该解决方案正在迅速流行,尤其是在无操作系统的互联网接入设备中。该公司还开发出了针对下一代IPv6网络的硬件芯片,目前正致力于该产品的商业化。



Wiznet公司行销部经理Son Jeong-Ho表示:“很多厂商提供以软件方式实现的TCP/IP解决方案。但我们是用硬件实现的,在性能上更出色。”Wiznet芯片的速度比软件解决方案快五倍。由于只用一个芯片就可取代互联网接入产品所必需的高价CPU和存储器,因此它既降低了成本又缩短了开发时间。



软件解决方案基本上要依赖操作系统,而Wiznet的TCP/IP单芯片解决方案使得在非PC环境中实现互联网接入成为可能,因为它把各种不同的协议嵌入在硬件中。



“即使在高端产品中使用Wiznet芯片,主要应用还将是MCU性能有限且要求具有价格竞争力的产品,以及那类既要求小尺寸又要求进行大量数据处理(面向多媒体和非操作系统应用)的产品。”Son Jeong-Ho表示。



他声称,Wiznet的TCP/IP单芯片解决方案事实上没有竞争对手。“这是因为该技术在一到两年内还无人能及。我们从20世纪90年代初期的一个Z.F.项目做起,从事这方面的研究已经大约10年了。我们花了很大力气,通过无数次测试,先是用逻辑电路实现它,最终在2002年初推出了我们首款产品原型。结果,我们现在成为具有明显优势的领先者。”Son说。 Wiznet产品的唯一潜在竞争对手是软件解决方案。如果不采用Wiznet的芯片,“任何想推出相关产品的公司别无选择,只能用软件实现。”Son说。



芯片目前是Wiznet的主要产品,大约占其销售总量的60%。该公司计划推出W3150,这是其互联网芯片W3100A的升级版本,并将从今年10月起开始量产。其它产品线包括基于网络的应用产品,如网络模块(NM7010A和NM7000A)和嵌入式门阵列(EGSR-7100A)。EGSR-7100A的月产量为7,000颗,面向韩国本土和美国市场。总体上看,模块产品主打欧洲市场,芯片产品面向台湾地区、香港和中国国内以及韩国的本地市场。



“Wiznet在2004年的销售额是30亿韩元(大约300万美元)),今年我们预期达到70亿韩元(大约700万美元)。目前,Wiznet正在推广面向应用的产品,包括互联网机顶盒、MP3模块、VoIP模块等等。”Son介绍道。



他表示,随着时间的推移中国国内对产品的需求量正在上升。“尽管中国国内的市场广阔,但我们为满足其需求所做的各种努力还不是非常有效。”Son说,“因此,我们目前正在加强我们的分销商系统,计划在今年内将现有的三家分销商扩展到五家。”



他还表示,Wiznet计划同Atmel和Microchip这样的MCU公司以及相关的应用开发商建立合作关系,以开发“应用开发套件”。“我们打算在明年上半年推出一种产品,它将Wiznet的IP核集成进Atmel公司的AVR微控制器中。我们的条件是从Atmel公司收取芯片版权税。”Son说,“此外,我们还计划在今年下半年销售一种带嵌入式PHY芯片的产品。”



据Wiznet公司总裁Lee Yoon-Bong预测,带有互联网接入功能的微控制器的需求量将会有大幅增长,而嵌入式互联网设备的市场将从2004年的大约4亿套上升到2009年的100亿套以上。

出0入0汤圆

 楼主| 发表于 2005-12-29 10:13:44 | 显示全部楼层
多谢HJJourAVR,昨天我又仔细看了一下,确实是用NM7010A实现TCP/IP的,采用Mega8控制,本网站的东西好像也是这样的,就是那个8019AS板子,我看了照片,虽然没有看到实物。



顺便说一句,DS18B20的温度值读取和ID码读取也可以用BASCOM-AVR和FASTAVR编程实现,这个时序要求比较高,可以参见www.basicavr.co论坛m和www.avrdiy.com的实例,这两个网站都有这方面的例子,是联合开发的。



这个主题请版主改成“看看如何用BACOM-AVR语言和NM7010A实现TCP/IP!!!!”,谢谢版主提醒!!

-----此内容被JAMESKING于2005-12-29,10:16:47编辑过


-----此内容被JAMESKING于2005-12-29,10:46:22编辑过

出0入0汤圆

发表于 2005-12-29 10:18:51 | 显示全部楼层
这个DS18B20的代码,呵呵,跟我也有关系。



另外 ,1wire的操作时序恐怕是由ASM做成的库来完成的。





8019AS只是MAC+PHY,TCP/IP协议必须由MCU来完成。

出0入0汤圆

 楼主| 发表于 2005-12-29 10:43:36 | 显示全部楼层
[转贴]采用BASCOM-AVR实现的DS18B20温度值和ID码读取:

$regfile = "M8515.dat"

$crystal = 8000000

Config 1wire = Porta.0                                      '定义BS18B20接在PA0上

Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.2 , Rs = Portb.3

Config Lcd = 16 * 2

'*************************************************

Dim Id(8) As Byte

Dim I As Byte

Dim C(2) As Byte

Dim T As Word                                               '由于温度原始数据是16位,所以变量C要word双字节整型变量

'***********这个程序暂时没有CRC校验***************

Do

  Cls

  1wreset

  If Err = 0 Then                                           'ERR可能是1wire总线专用语句,如果初始化有应答ERR就为0,如果没有应答就为1?

    Lcd "18B20"

    Else

    Lcd "ERROR"

  End If

'*************************************************

  1wreset                                                   '初始化1wire总线

  1wwrite &H33                                              '&H33是读64位ROM

  For I = 1 To 8                                            '将64位ID保存在数组ID()里

    Id(i) = 1wread()

  Next

'*************************************************

  1wreset

  1wwrite &HCC                                              '&HCC是跳过ID匹配,多个DS18B20并联时要先匹配

  1wwrite &H44                                              '&H44是启动DS18B20内部温度转化

'*************************************************

  1wreset

  1wwrite &HCC

  1wwrite &HBE                                              '&HBE是读取温度命令,并且分开保存在2个字型节变量里,不能保存为一个双字节型变量word

  For I = 1 To 2

    C(i) = 1wread()

  Next

'*************************************************

  Locate 1 , 7                                              '显示温度原始数据,两个字节,C(2)是高位,C(1)是低位

  Lcd Hex(c(2))

  Lcd Hex(c(1))

'*************************************************

  Locate 1 , 12

  T = C(2) * 256                                            '把C(2)数据由字节变量转变为双字节变量,并且左移动8位(就是乘以256)

  T = T + C(1)                                              '再把左移8位的C(2)和C(1)相加就得到了16位的原始温度数据



  If C(2) > 15 Then                                         '然如果C(2)的第五位数据是1,那就说明测量的温度为负温度

    T = Not T                                               '负温度的计算,LCD T 是以十进制显示温度

    T = T + 1

    T = T / 16

    Lcd "-" ; T ; "C"

  Else

    T = T / 16                                              '正温度计算

    Lcd "+" ; T ; "C"

  End If

'*************************************************

  Locate 2 , 1                                              '光标定位在第二行第一列

  For I = 1 To 8                                            '显示64位ID,8个字节

     Lcd Hex(id(i))

  Next

  Wait 1

Loop

End





[转贴]采用FASTAVR读取18B20的温度值和ID码:

'/////////////////////////////////////////////////////////

'///   FastAVR Basic Compiler for AVR by MICRODESIGN   ///

'///   Name of Your project

'/////////////////////////////////////////////////////////

$Device= m8515 ' used device

$Stack = 32 ' stack depth

$Clock = 8.000 ' adjust for used crystal

$1Wire = PORTA.0                                      '定义BS18B20接在PA0上

$Lcd=PORTB.4, RS=PORTB.3, EN=PORTB.2, 16, 2



'*************************************************

Dim Id(8) As Byte

Dim I As Byte

Dim C(2) As Byte

Dim T As Word                                               '由于温度原始数据是16位,所以变量C要word双字节整型变量

Dim err As Byte

'***********这个程序暂时没有CRC校验***************

Do

  Cls

  1Wreset

  err=1Wread

  Lcd err

'*************************************************

  1Wreset                                                   '初始化1wire总线

  1Wwrite &H33                                              '&H33是读64位ROM

  For I = 1 To 8                                            '将64位ID保存在数组ID()里

    Id(i) = 1Wread

  Next

'*************************************************

  1Wreset

  1Wwrite &HCC                                              '&HCC是跳过ID匹配,多个DS18B20并联时要先匹配

  1Wwrite &H44                                              '&H44是启动DS18B20内部温度转化

'*************************************************

  1Wreset

  1Wwrite &HCC

  1Wwrite &HBE                                              '&HBE是读取温度命令,并且分开保存在2个字型节变量里,不能保存为一个双字节型变量word

  For I = 1 To 2

    C(i) = 1Wread

  Next

'*************************************************

  Locate 1 , 7                                              '显示温度原始数据,两个字节,C(2)是高位,C(1)是低位

  Lcd Hex(c(2))

  Lcd Hex(c(1))

'*************************************************

  Locate 1 , 12

  T = C(2) * 256                                            '把C(2)数据由字节变量转变为双字节变量,并且左移动8位(就是乘以256)

  T = T + C(1)                                              '再把左移8位的C(2)和C(1)相加就得到了16位的原始温度数据

'*************************************************

If C(2) > 15 Then                                         '然如果C(2)的第五位数据是1,那就说明测量的温度为负温度

    T = T / 16                                              '正温度计算

    Lcd "+" ; T ; "C"

    Else

    T = Not T                                               '负温度的计算,LCD T 是以十进制显示温度

    T = T + 1

    T = T / 16

    Lcd "-" ; T ; "C"

  End If

'*************************************************

  Locate 2 , 1                                              '光标定位在第二行第一列

  For I = 1 To 8                                            '显示64位ID,8个字节

     Lcd Hex(id(i))

  Next

  Wait 1

Loop

End



以上程序来自于www.basicavr.com和www.avrdiy.com,在www.basicavr.com网站上的地址为:

http://basicavr.web4.seaidc.com/bbs/topicdisp.asp?bd=12&id=69&toPage=1



这个程序不是我开发的,在此我谢谢阿贵站长和阿艺站长!!



可以很清楚地看到,任何编译器都是需要转成ASM才能执行的,C语言也同样需要调用库文件,不管你用C程序库还是ASM程序库,最终结果都是变成ASM才能执行,这是个常识。调用basic库文件实现1wire很方便,可能灵活性比较小,但是快,就好!!



对于网络和TCP/IP,我不懂,好像8019等芯片都要外部控制才能实现TCP/IP???如果是这样,那么51的也可以控制,在网上原来我见过,可惜忘记了是哪个地方了。

出0入0汤圆

发表于 2005-12-29 10:49:36 | 显示全部楼层
重点在这三条指令程序。

1Wreset

1Wwrite

1Wread



C语言可以使用库,可以嵌入汇编,也可以用C语言自己编写。

BASIC能调用库,可以嵌入汇编,但却无法用BASIC语法自己编写。

出0入0汤圆

 楼主| 发表于 2005-12-29 12:28:02 | 显示全部楼层
HJJouAVR大哥,你好,请看看这段程序,程序的地址链接如下(此程序不是我的原创,只是转贴):

http://basicavr.web4.seaidc.com/bbs/topicdisp.asp?bd=11&id=81

程序如下,通过实物测试的:

$Device= m16

$Stack = 32

$Clock = 8

$GLCD Nokia3310, SCLK=PORTB.7, SDIN=PORTB.5, DC=PORTB.1, SCE=PORTB.4

$Def RES=PORTB.0

$LeadChar=" ", Format(3,0)



Dim s As String*15

Dim ss As String*15

Dim n As Byte, m As Byte

Dim x As Byte, y As Byte

Dim Clown As Flash Byte

Dim F0HD As Flash Byte

Dim Sclk1616HD As Flash Byte



Set DDRA.4: Nop 3: Set RES



GLcdInit

ImgSet(0, 0), Clown

FontSet F0HD

GLcd(0,0),"agui2008"

Do

For n=0 To 255

GLcd(60, 0), n

ImgSet(68, 2, m), Sclk1616HD

Incr m

If m>7 Then m=0

WaitMs 250

x=n mod 20

If x=0 Then

Inverse(0)

ElseIf x=10 Then

Inverse(1)

End If

Next

GLcd(0,0),"agui2008"

Loop



$Include "C:\FastAVR\Nokia3310\Sclk1616HD.bas"

$Include "C:\FastAVR\Nokia3310\Clown.bas"

$Include "C:\FastAVR\Nokia3310\F0HD.bas"



以上三个bas文件上传如下:

点击此处下载armok0194906.rar



我没有3310的LCD,但是别人已经测试成功,你如果有3310的LCD,可以测试看看,看这个程序是不是对的,上面三个bas文件可不可以看成是库函数或者库函数的雏形呢?请自己判断,也请大家一起判断,谢谢!!!!!
-----此内容被JAMESKING于2005-12-29,12:29:02编辑过

出0入0汤圆

发表于 2005-12-29 12:33:21 | 显示全部楼层
当然不是了。

原始的库由下面这几句调用和配置。

$Device= m128                ' used device

$Stack = 32                        ' stack size

$Clock = 10

$GLCD Nokia3310, SCLK=PORTA.0, SDIN=PORTA.1, DC=PORTA.2, SCE=PORTA.3

$Def RES=PORTA.4



那些BAS仅仅是个数据表格(数组)而已。

出0入0汤圆

 楼主| 发表于 2005-12-29 12:56:49 | 显示全部楼层
应该是这么说,BASCOM-AVR可以调用和修改自己的库函数,而FASTAVR就别想了,安装以后根本连库文件都找不到,但是,平心而论,你能确保你的库函数比那些开发编译器的公司或者组织开发的库函数更加合理吗?,除非你本身就是开发小组的,否则我想比较困难。



作为一个网站,面对广大网友,也许用免费的GCC是一个很好的选择,因为很多人可以用得起,还免去了法律上的一些问题,从网站商业的角度考虑,我也会这么做,但是如果是一个公司,我肯定选用以下几个编译器:

1。CVAVR,(99美元,好像是的吧)

2。FASTAVR或者BASCOM-AVR(99美元/79欧元)

3。AVRSTUDIO(free)

然后给每个开发小组员工发一根并口ISP下载线,带4MHz有源晶振的,然后就开始做事情了,不要笑,我们现在计划就这样,JTAG和STK500本来就没有太多用处,特别是双龙推出了SLISP1.4.2.3版本以后。

一个年产值在2000万元的公司,购买上述编译器的价格可以自己看看,不超过2000元人民币(不含关税价格),九牛一毛。



自己编写库函数,当然可以,但是,作为一个比较好的软件,一般库函数都非常丰富,至少,上面列举的三种高级语言编译器的库函数都很多,而GCC呢???DIY其实作为业余爱好我无话可说,但是真正要做事情了,对不起,我还是相信开发这个软件的软件公司开发的库函数,因为我花了钱的,就可以享受这个服务,给员工自己开发库函数,还有一些想不到的问题出现,比如技术的延续性等等,我开过公司,知道这个的重要性。



当然,本网站是国内AVR的DIY最出名的网站,用GCC或者自己编写库函数无可厚非,但是,真正来说,作为一个综合性开发(机械、电气、液压、焊接或者建筑)的公司,有此必要么???请深思,谢谢!!!



以上观点,请勿对号入座,谢谢!!

出0入0汤圆

发表于 2005-12-29 14:02:53 | 显示全部楼层
只能表明你是没有用过C语言,而且编程的时间也不长。



"自己编写库函数,当然可以,但是,作为一个比较好的软件,一般库函数都非常丰富,至少,上面列举的三种高级语言编译器的库函数都很多,而GCC呢???DIY其实作为业余爱好我无话可说,但是真正要做事情了,对不起,我还是相信开发这个软件的软件公司开发的库函数,因为我花了钱的,就可以享受这个服务,给员工自己开发库函数,还有一些想不到的问题出现,比如技术的延续性等等,我开过公司,知道这个的重要性。 "



不敢苟同。

我认为编程是一种富有创造性的行为。

出0入0汤圆

 楼主| 发表于 2005-12-29 14:28:27 | 显示全部楼层
这点我承认,我没有学过任何C语言,我只学过GWBASIC和FASTAVR,现在正在学习CVAVR,还没入门,对于PC机编程我更加是一窍不通,我在9年内做过的东西(12个产品),全部都是单片机控制的,程序量从来没有上过8K,只是用很小很小的单片机控制几十吨或者几百吨的工程机械罢了,简单得很,粗活一堆,与TCP/IP控制不可同日而语。。。。。。。



自己编写库函数,在家电和民用控制方面可能有些优势,但是在“用现代的电子技术改造传统的制造业”方面似乎用处不大,我个人这么认为,很多语言,可以调用函数,但是更多的功能,可以采用内嵌ASM或者调用子程序实现,在“钢铁加芯片”这个行业里,软件更新不是很快,因为用户不允许你很快更新,他们需要保持生产的连续性,同样,硬件的版本也不能更新很快,因为需要一年甚至好几年的时间来验证你的硬件是否有问题,软件是否有问题,我们的焊接设备,5年只更新了4次,软件一直就是没有更新的,因为够用就好。更新软件很大程度上不是为了使产品完美,而是为了欺骗客户,更好的赚钱。



编译器和使用什么语言编写,只是手段,只是笔和纸,真正的问题是程序思路问题,或者系统要求问题,用BASCOM-AVR或者FASTAVR或者GCCAVR或者CVAVR编写DS18B20的程序,对用户来说也许并没有任何区别,但是对于一个公司来说,可能存在员工资源的问题和技术延续性的问题,如果作为一个精明的企业家,我宁可逼着员工使用BASIC语言编写AVR,而不愿员工自己开发什么“自己的库函数”,因为,至少BASIC语言编写的,不论FASTAVR还是BASCOM-AVR,我能看懂,不怕员工跳槽,跳槽我也不会马上就死,但是C语言呢?不是专业程序员,恐怕很难有人说清楚“位”和“位域”的区别,你跳槽倒是好,员工认为自己应该发展得更好一些,可以跳槽,但是公司怎么办????

出0入0汤圆

发表于 2005-12-29 14:43:17 | 显示全部楼层
道不同不相为谋。

有 愚民政策 的倾向---------古代的国王君主没几个希望百姓是聪明的,越笨越好控制。



所以时至今日,中国依然不能出现 IBM,INTEL 之类的技术巨人。

IBM,INTEL的这些IT巨子都是具备锐意创新的意识,跑在技术的最前端,才能傲视同行,领军全球。

出0入0汤圆

 楼主| 发表于 2005-12-29 14:50:32 | 显示全部楼层
“有 愚民政策 的倾向”



呵呵者现在就是“挨踢”行业和别的很多行业的真实写照,现实如此。



创新,很大程度上是在工艺流程或者工况上的改善,才叫一点点创新(对于机电控制和工业电气自动化而言),这关系到一个系统工程的问题。恕我无知,软件创新,可以说叫做软件的艺术,我不是很清楚,特别是对于底层的东西。



看看我的签名档,我也是有感而发的。。。。。

出0入0汤圆

发表于 2005-12-29 15:13:34 | 显示全部楼层
哟,又来进行B和C的争论啦,其实自己喜欢、用得爽就是最好的。

出0入0汤圆

 楼主| 发表于 2005-12-29 19:03:58 | 显示全部楼层
彩虹大哥,请你看看BASCOM-AVR1.11.8.1版本可不可以解密?非常想用这个版本,这个版本也非常好用,谢谢你了!!!

出0入0汤圆

发表于 2005-12-29 22:03:15 | 显示全部楼层
破解的话可以编译大于4K的程序,但编译的文件有问题,不能使用,估计在整个程序里都有校验编译文件大小的安全机制,单纯跳过编译出错段不行。说实在的,我也想买一套正版的,只是不知如何操作。

出0入0汤圆

 楼主| 发表于 2005-12-29 22:18:48 | 显示全部楼层
我知道哪个文件限制:Basc-avr.dll、Bascavr.exe、bscavrl.dll,这三个文件对编译代码有关键性的影响。但是,我没法子破解,晕:( 我也很想自己买一套正版的,看看还有没有人能够合起来买一套,至少注册码和程序可以共用,或者,明年上半年可以买一套正版的了。。。。。



找到了,北京交通大学有代理:



663#,Beijing Jiaotong University  

Beijing, China  

China  

100044  



  +86 0 13810345698  

还有一个是香港的代理:

DIY Electronics (HK) Ltd.   

  

  

P.O. Box 88458  

Sham Shui Po, Hong Kong  

China  



  +852 2720 0255  

  +852 2725 0610  



  China, Japan, Singapore, Malaysia, Taiwan, Thailand and Hongkong

WWW : http://kitsrus.com

Responsible person : Peter Crowcroft  



看看价格如何,可别太黑了,说实在的,1500大元我还是能接受的。。。





此处有详细列表,请需要的自己看看:

http://www.mcselec.com/index.php?option=com_contact&catid=82&Itemid=59
-----此内容被JAMESKING于2005-12-29,23:03:10编辑过

出0入0汤圆

 楼主| 发表于 2005-12-30 12:59:39 | 显示全部楼层
把BASCOM-AVR控制TCP/IP的程序集中一下,方便大家特别是想做TCP/IP的网友参考。

这个程序是我转贴的,我没有测试,请懂得这个东西的朋友们测试,谢谢!!

'----------------------------------------------------------------------------------

' Embedded UDP&WebServer   -   Atmega32 and RTL8019AS    -   Embedded UDP&WebServer

'----------------------------------------------------------------------------------

'

' Version X - April 1 2005 - Ben Zijlstra - Netherlands - http://members.home.nl/bzijlstra



' history:

'

' 03-06-2004 Added some extra LCD-routines

' 05-06-2004 HTTP shows portstatus on LCD

'            PCF8574 or PCF8574A for LCD can be chosen

' 06-06-2004 Idle-time for the LCD-display

'            Added 24LC256 testroutine

'            Added LM76 testroutine

' 01-10-2004 Small alteration so Linux browsers do work (tcp_psh-routine)

' 02-10-2004 Tested with Bascom-AVR 1.11.77 running well

' 20-10-2005 Optimized some LCD-routines and misc.

' 21-10-2005 Tested with Bascom-AVR 1.11.79 running well

'

'

'

' Fusebits:

' A987:1111 = Crystal/Boden enabled

' H:      1 = JTAG disabled

' G:      0 = Preserve EEprom when chip erase

'

' Hardware:

'

' PA0 - SD0 - Databus

' PA1 - SD1

' PA2 - SD2

' PA3 - SD3

' PA4 - SD4

' PA5 - SD5

' PA6 - SD6

' PA7 - SD7



' PB0 - SA0 - Addressbus

' PB1 - SA1

' PB2 - SA2

' PB3 - SA3

' PB4 - SA4

' PB5 - MOSI

' PB6 - MISO

' PB7 - SCK



' PC0 - I2c SLC

' PC1 - I2c SDA

' PC2 - PC2

' PC3 - PC3

' PC4 - PC4

' PC5 - PC5

' PC6 - PC6

' PC7 - PC7



' PD0 - RXD

' PD1 - TXD

' PD2 - INT0

' PD3 - LE - Latch Enable

' PD4 - RSTDRV

' PD5 - EEDO

' PD6 - IORB

' PD7 - IOWB





' In the EEPROM:

'

' 00 = .0 - 0 if LCD present (2 x 20)

' 00 = .1

' 00 = .2

' 00 = .3

' 00 = .4

' 00 = .5

' 00 = .6

' 00 = .7

' 01 = IP-number msb

' 02 = IP-number

' 03 = IP-number

' 04 = IP-number lsb

' 05 = MAC-address

' 06 = MAC-address

' 07 = MAC-address

' 08 = MAC-address

' 09 = MAC-address

' 10 = MAC-address

' 11 = Portnumber

' 12 = Portnumber

' 13 = Length URL-refresh string

' 14 = start of URL-refresh string

' .... upto end of URL-refresh string

'100 = address of PCF8574 or PCF8574A





$crystal = 7372800

$regfile = "M32def.dat"

$baud = 57600

$hwstack = 64

$swstack = 64

$framesize = 64



Declare Sub Write_rtl8019as(byval Regaddr As Byte , Byval Regdata As Byte)

Declare Sub Read_rtl8019as(byval Regaddr As Byte)

Declare Sub Init_rtl8019as

Declare Sub Getpacket

Declare Sub Overrun

Declare Sub Arp

Declare Sub Icmp

Declare Sub Icmp_checksum

Declare Sub Write_dest_mac

Declare Sub Packetshape

Declare Sub Echopacket

Declare Sub Setipaddrs

Declare Sub Ip_header_checksum

Declare Sub Udp

Declare Sub Udp_checksum

'

Declare Sub General_part_checksum(byval Val1 As Byte , Byval Val2 As Word)

'

'

Declare Sub Lcd_init

Declare Sub Lcd_char(byval Lcd_c As Byte)

Declare Sub Lcd_txt

Declare Sub Lcdhome                                         ' CLS/Home

Declare Sub Firstline                                       ' goto 0/0 of LCD

Declare Sub Secondline



Declare Sub Setup_packet

Declare Sub Assemble_ack



Declare Sub Relayon(byval X As Byte)

Declare Sub Relayoff(byval X As Byte)

Declare Sub Status



Declare Sub Configure

Declare Sub Read_mac

Declare Sub Print_ip

Declare Sub Read_ip

Declare Sub Print_mac

Declare Sub Default_message



Dim Val1 As Byte

Dim Val2 As Word                                            ' up to 65535 characters

Dim Val3 As Byte

Dim Val4 As Byte





Dim Regaddr As Byte

Dim Regdata As Byte

'Ethernet header layout

Dim Byte_read As Byte

Dim Hulp1 As Byte

Dim Mymac(6) As Byte

Dim I As Integer

Dim Rxlen As Word

Dim Hulp2 As Word

Dim Hulp3 As Word

Dim Hulp4 As Byte





Dim Data_l As Byte

Dim Data_h As Byte

'RTL8019AS

Dim Txlen As Word



Dim I_header_length As Word

Dim I_odd As Byte

Dim I_chksum32 As Long

Dim I_x As Word

Dim I_checksum16 As Word

Dim Resend As Byte

Dim T As Byte





'variables with overlays

Dim Hulp6 As Word

Dim Hulp6h As Byte At Hulp6 + 1 Overlay

Dim Hulp6l As Byte At Hulp6 Overlay



Dim I_value16 As Word

Dim I_value16h As Byte At I_value16 + 1 Overlay

Dim I_value16l As Byte At I_value16 Overlay



Dim Result16 As Word

Dim Result16h As Byte At Result16 + 1 Overlay

Dim Result16l As Byte At Result16 Overlay



Dim Hulp5 As Word

Dim Hulp5h As Byte At Hulp5 + 1 Overlay

Dim Hulp5l As Byte At Hulp5 Overlay



Dim Myip(4) As Byte

Dim My_ip As Long At Myip Overlay



Dim Pageheader(4) As Byte

Dim T_enetpacketlenl As Byte At Pageheader + 2 Overlay

Dim T_enetpacketlenh As Byte At Pageheader + 3 Overlay



Dim Packet(1000) As Byte At &HC0

'Ethernet packet destination

Dim T_enetpacketdest0 As Byte At &HC0 Overlay

Dim T_enetpacketdest1 As Byte At &HC1 Overlay

Dim T_enetpacketdest2 As Byte At &HC2 Overlay

Dim T_enetpacketdest3 As Byte At &HC3 Overlay

Dim T_enetpacketdest4 As Byte At &HC4 Overlay

Dim T_enetpacketdest5 As Byte At &HC5 Overlay

'Ethernet packet source

Dim T_enetpacketsrc0 As Byte At &HC6 Overlay

Dim T_enetpacketsrc1 As Byte At &HC7 Overlay

Dim T_enetpacketsrc2 As Byte At &HC8 Overlay

Dim T_enetpacketsrc3 As Byte At &HC9 Overlay

Dim T_enetpacketsrc4 As Byte At &HCA Overlay

Dim T_enetpacketsrc5 As Byte At &HCB Overlay

'Ethernet packet type

Dim T_enetpackettype As Word At &HCC Overlay

Dim T_arp_hwtype1 As Byte At &HCF Overlay

'Arp

Dim T_arp_prttype1 As Byte At &HD1 Overlay

Dim T_arp_hwlen As Byte At &HD2 Overlay

Dim T_arp_prlen As Byte At &HD3 Overlay

Dim T_arp_op1 As Byte At &HD5 Overlay

'arp source ip address

Dim T_arp_sipaddr0 As Byte At &HDC Overlay

Dim T_arp_sipaddr1 As Byte At &HDD Overlay

Dim T_arp_sipaddr2 As Byte At &HDE Overlay

Dim T_arp_sipaddr3 As Byte At &HDF Overlay

'arp target IP address

Dim T_arp_tipaddr As Long At &HE6 Overlay

'IP header layout IP version and header length

Dim T_ip_vers_len As Byte At &HCE Overlay



'packet length

Dim T_ip_pktlen0 As Byte At &HD0 Overlay

Dim T_ip_pktlen1 As Byte At &HD1 Overlay



'protocol (ICMP=1, TCP=6, UDP=11)

Dim T_ip_proto As Byte At &HD7 Overlay





'header checksum

Dim T_ip_hdr_cksum0 As Byte At &HD8 Overlay

Dim T_ip_hdr_cksum1 As Byte At &HD9 Overlay

Dim T_ip_hdr_cksum As Word At &HD8 Overlay

'IP address of source

Dim T_ip_srcaddr0 As Byte At &HDA Overlay

Dim T_ip_srcaddr1 As Byte At &HDB Overlay

Dim T_ip_srcaddr2 As Byte At &HDC Overlay

Dim T_ip_srcaddr3 As Byte At &HDD Overlay



Dim T_ip_srcaddr As Long At &HDA Overlay



'IP address of destination

Dim T_ip_destaddr0 As Byte At &HDE Overlay

Dim T_ip_destaddr1 As Byte At &HDF Overlay

Dim T_ip_destaddr2 As Byte At &HE0 Overlay

Dim T_ip_destaddr3 As Byte At &HE1 Overlay



Dim T_ip_destaddr As Long At &HDE Overlay



Dim T_icmp_type As Byte At &HE2 Overlay

Dim T_icmp_code As Byte At &HE3 Overlay

Dim T_icmp_cksum0 As Byte At &HE4 Overlay

Dim T_icmp_cksum1 As Byte At &HE5 Overlay

Dim T_icmp_cksum As Word At &HE4 Overlay



'UDP header

Dim T_udp_srcport0 As Byte At &HE2 Overlay

Dim T_udp_srcport1 As Byte At &HE3 Overlay



Dim T_udp_destport0 As Byte At &HE4 Overlay

Dim T_udp_destport1 As Byte At &HE5 Overlay

Dim T_udp_destport As Word At &HE4 Overlay



Dim T_udp_len0 As Byte At &HE6 Overlay

Dim T_udp_len1 As Byte At &HE7 Overlay



Dim T_udp_chksum0 As Byte At &HE8 Overlay

Dim T_udp_chksum1 As Byte At &HE9 Overlay



'LCD variables

Dim Temparray(80) As Byte

Dim Lcd_t As String * 80 At Temparray Overlay

Dim Temparray2(4) As Byte

Dim Lcd_tempstr As String * 1

Dim Lcd_temp As Byte

Dim Lcd_x As Byte

Dim Lcd_hulp As Byte

Dim Lcd_h As Byte

Dim Lcdpresent As Byte



Dim Msg_temp As String * 80

Dim Y As Word

Dim Tempstring1 As String * 1



Dim Triggerstr As String * 80

'idle time

Dim Idletime As Long

Dim Yn As String * 1

Dim Mymacs(6) As String * 2

Dim Pcf8574 As Byte



Const Debug = 0                                             ' put 1 for debug, 0 for no debug

Const Rstport = &H18

Const Isr = &H07

Const Msg_initfail = "Init failed"

Const Cr = &H00

Const Dcrval = &H58

Const Dcr = &H0E

Const Rbcr0 = &H0A

Const Rbcr1 = &H0B

Const Rcr = &H0C

Const Tpsr = &H04

Const Txtstart = &H40

Const Tcr = &H0D

Const Pstart = &H01

Const Rxstart = &H46

Const Bnry = &H03

Const Pstop = &H02

Const Rxstop = &H60

Const Curr = &H07

Const Imr = &H0F

Const Imrval = &H11

Const Tcrval = &H00

Const Rdmaport = &H10

Const Rsar0 = &H08

Const Rsar1 = &H09

Const Tbcr0 = &H05

Const Tbcr1 = &H06



'IP protocol types

'icmp

Const Prot_icmp = &H01

'udp

Const Prot_udp = &H11



'LCD

Const Rs = 4

Const E = 7



'RTL8019AS ISR Register definitions

Const Rdc = &H40



Config Int0 = Rising

'I2c

Config Scl = Portc.0

Config Sda = Portc.1

Config I2cdelay = 20



#if Debug = 1

Print "Hello world"

#endif



Databus Alias Porta

_databus Alias Pina

Rtldata Alias Porta

Databus_ddr Alias Ddra



Addrbus Alias Portb

Addrbus_ddr Alias Ddrb



Resetport Alias Portd

Eeprom Alias Portd

Ior_pin Alias Portd.6

Iow_pin Alias Portd.7

Resetport_ddr Alias Ddrd



Inputport1 Alias Pinc

Inputport2 Alias Portc



Latch Alias Portd.3

Resetport_ddr = &HF8                                        ' leave RXD and TXD





' Main program

'

Main:

Reset Latch

Databus_ddr = &HFF

Databus = 0                                                 ' put zero's on relays-port

Set Latch

Reset Latch

'Relaystatus = 0                                             ' put zero's in the relaystatus byte

Readeeprom Pcf8574 , 100

Readeeprom Hulp1 , 0                                        ' Should I put something on the LCD?

If Hulp1.0 = 0 Then

   Lcdpresent = 1

   Call Lcd_init

   Lcd_t = "VA3TO/EIO-board"

   Call Lcd_txt

   Call Secondline

   Lcd_t = "UDP-server/client"

   Call Lcd_txt

End If

Call Configure

Call Default_message

Call Init_rtl8019as



'Call Showregs



Enable Interrupts

Enable Int0

On Int0 Rtl8019as_interrupt

'start the NIC

Call Write_rtl8019as(cr , &H22)

Do

If Lcdpresent = 1 Then

      'idle-time

      Incr Idletime

      If Idletime > 5000000 Then

         Disable Int0

         Lcd_t = "*VA3TO/EIO-Board#Idle..."

         Call Lcd_txt

         Enable Int0

         Idletime = 0

      End If

End If

Loop

End





' Routine to handle an interrupt on the RTL8019AS

'

Rtl8019as_interrupt:

   #if Debug = 1

      Print "Interrupt from RTL8019as"

   #endif

   Disable Int0

   'read the interrupt status register

   Call Read_rtl8019as(isr)

   'if the receive buffer has been overrun

   If Byte_read.4 = 1 Then

      Call Overrun

   End If

   'if the receive buffer holds a good packet

   If Byte_read.0 = 1 Then

      Call Getpacket

   End If

   'make sure the receive buffer ring is empty. If BNRY = CURR, the buffer is empty

   Call Read_rtl8019as(bnry)

   Data_l = Byte_read

   Call Write_rtl8019as(cr , &H62)

   Call Read_rtl8019as(curr)

   Data_h = Byte_read

   Call Write_rtl8019as(cr , &H22)

   'buffer is not empty, get next packet

   If Data_l <> Data_h Then

      Call Getpacket

   End If

   'reset the interrupts bits

   Call Write_rtl8019as(isr , &HFF)

   Call Write_rtl8019as(cr , &H22)

   Enable Int0

Return





' Routine to Write to NIC Control register

'

Sub Write_rtl8019as(regaddr , Regdata)

   Addrbus = Regaddr

   Databus = Regdata

   Databus_ddr = &HFF

   nop

   Reset Iow_pin

   nop

   Set Iow_pin

   nop

   Databus_ddr = &H00

   Databus = &HFF

End Sub





' Routine to read from NIC Control register

'

Sub Read_rtl8019as(regaddr)

   Databus_ddr = &H00

   Databus = &HFF

   Addrbus = Regaddr

   Reset Ior_pin

   nop

   Byte_read = Pina

   nop

   Set Ior_pin

   nop

End Sub





' Routine to initialise the RTL8019AS ethernetchip

'

Sub Init_rtl8019as

Databus_ddr = &H00

Databus = &HFF

Addrbus_ddr = &HFF

Addrbus = &H00

Resetport_ddr = &HF8

Reset Eeprom.5

Set Iow_pin

Set Ior_pin

Set Resetport.4

Waitms 2

Reset Resetport.4

Call Read_rtl8019as(rstport)

Call Write_rtl8019as(rstport , Byte_read)

Waitms 10

'check for good soft reset

Call Read_rtl8019as(isr)

If Byte_read.7 = 0 Then

      Print Msg_initfail

End If

Call Write_rtl8019as(cr , &H21)

Waitms 2

Call Write_rtl8019as(dcr , Dcrval)

Call Write_rtl8019as(rbcr0 , &H00)

Call Write_rtl8019as(rbcr1 , &H00)

Call Write_rtl8019as(rcr , &H04)

Call Write_rtl8019as(tpsr , Txtstart)

Call Write_rtl8019as(tcr , &H02)

Call Write_rtl8019as(pstart , Rxstart)

Call Write_rtl8019as(bnry , Rxstart)

Call Write_rtl8019as(pstop , Rxstop)

Call Write_rtl8019as(cr , &H61)

Waitms 2

Call Write_rtl8019as(curr , Rxstart)

For Hulp1 = 1 To 6

     Call Write_rtl8019as(hulp1 , Mymac(hulp1))

Next Hulp1

Call Write_rtl8019as(cr , &H21)

Call Write_rtl8019as(dcr , Dcrval)

Call Write_rtl8019as(cr , &H22)

Call Write_rtl8019as(isr , &HFF)

Call Write_rtl8019as(imr , Imrval)

Call Write_rtl8019as(tcr , Tcrval)

End Sub





Sub Overrun

   Call Read_rtl8019as(cr)

   Data_l = Byte_read

   Call Write_rtl8019as(cr , &H21)

   Waitms 2

   Call Write_rtl8019as(rbcr0 , &H00)

   Call Write_rtl8019as(rbcr1 , &H00)

   Hulp1 = Data_l And &H04

   If Hulp1 <> 0 Then

      Resend = 0

      Else

         If Hulp1 = 0 Then

            Call Read_rtl8019as(isr)

            Data_l = Byte_read

            Hulp1 = Data_l And &H02

            Hulp4 = Data_l And &H08

            Hulp3 = Hulp1 Or Hulp4

               If Hulp3 > 0 Then

                  Resend = 0

                  Else

                  Resend = 1

               End If

         End If

   End If

   Call Write_rtl8019as(tcr , &H02)

   Call Write_rtl8019as(cr , &H22)

   Call Write_rtl8019as(bnry , Rxstart)

   Call Write_rtl8019as(cr , &H62)

   Call Write_rtl8019as(curr , Rxstart)

   Call Write_rtl8019as(cr , &H22)

   Call Write_rtl8019as(isr , &H10)

   Call Write_rtl8019as(tcr , Tcrval)

End Sub





' Routine to execute send packet command to retrieve the packet

'

Sub Getpacket

   Call Write_rtl8019as(cr , &H1A)

   For I = 0 To 4

      Call Read_rtl8019as(rdmaport)

      Pageheader(i + 1) = Byte_read

   Next I

   'watch it. overlay variables

   Result16h = T_enetpacketlenh

   Result16l = T_enetpacketlenl

   Rxlen = Result16

   Hulp2 = Rxlen + 1

   For I = 1 To Hulp2

      Call Read_rtl8019as(rdmaport)

      'dump any bytes that will overrun the receive buffer

      If I < 1000 Then

         Packet(i + 1) = Byte_read

      End If

   Next I

   Hulp1 = Byte_read And Rdc

   If Hulp1 <> 64 Then

      Call Read_rtl8019as(isr)

   End If



   Call Write_rtl8019as(isr , &HFF)





   ' Routine to process an ARP packet

   '

   If T_enetpackettype = &H0608 Then

      If T_arp_hwtype1 = &H01 Then

         If T_arp_prttype1 = &H00 Then

            If T_arp_hwlen = &H06 Then

               If T_arp_prlen = &H04 Then

                  If T_arp_op1 = &H01 Then

                     If My_ip = T_arp_tipaddr Then

                        Call Arp

                     End If

                  End If

               End If

            End If

         End If

      End If

   End If





   ' Routine to go ahead with icmp or udp

   '

   If T_enetpackettype = &H0008 Then

         If T_ip_destaddr = My_ip Then

            Select Case T_ip_proto

               Case Prot_icmp : Call Icmp

               'Case Prot_tcp : Call Tcp

               Case Prot_udp : Call Udp

            End Select

         End If

   End If

End Sub





' Routine to handle ARP-traffic

'

Sub Arp

   'Start the NIC

   Call Write_rtl8019as(cr , &H22)

   'load beginning page for transmit buffer

   Call Write_rtl8019as(tpsr , Txtstart)

   'set start address for remote DMA operation

   Call Write_rtl8019as(rsar0 , &H00)

   Call Write_rtl8019as(rsar1 , &H40)

   'clear the interrupts

   Call Write_rtl8019as(isr , &HFF)

   'load data byte count for remote DMA

   Call Write_rtl8019as(rbcr0 , &H3C)

   Call Write_rtl8019as(rbcr1 , &H00)

   'do remote write operation

   Call Write_rtl8019as(cr , &H12)

   'write destination MAC address

   Call Write_dest_mac

   'write source address

   For I = 1 To 6

       Call Write_rtl8019as(rdmaport , Mymac(i))

   Next I

   'arp target IP address

   'arp_op1 = packet(&h16)

   Packet(&H16) = &H02

   For I = 0 To 9

      Hulp1 = &HCC + I

      T = Peek(hulp1)

      Call Write_rtl8019as(rdmaport , T)

   Next I

   'write ethernet module mac address

   For I = 1 To 6

      Call Write_rtl8019as(rdmaport , Mymac(i))

   Next I

   'write myip

   For I = 1 To 4

      Call Write_rtl8019as(rdmaport , Myip(i))

   Next I

   'write remote mac address

   Call Write_dest_mac

   'write remote IP address

   Call Write_rtl8019as(rdmaport , T_arp_sipaddr0)

   Call Write_rtl8019as(rdmaport , T_arp_sipaddr1)

   Call Write_rtl8019as(rdmaport , T_arp_sipaddr2)

   Call Write_rtl8019as(rdmaport , T_arp_sipaddr3)

  'write som pad characters to fill out the packet to the minimum length

   For I = 0 To &H11

      Call Write_rtl8019as(rdmaport , &H00)

   Next I

   'make sure the DMA operation has succesfully completed

   Byte_read = 0

   Do

      Hulp1 = Byte_read And Rdc

      Call Read_rtl8019as(isr)

   Loop Until Hulp1 = 0

   'load numbers of bytes to be transmitted

   Call Write_rtl8019as(tbcr0 , &H3C)

   Call Write_rtl8019as(tbcr1 , &H00)

   'send the contents of the transmit buffer onto the network

   Call Write_rtl8019as(cr , &H24)

End Sub





Sub Write_dest_mac

   Call Write_rtl8019as(rdmaport , T_enetpacketsrc0)

   Call Write_rtl8019as(rdmaport , T_enetpacketsrc1)

   Call Write_rtl8019as(rdmaport , T_enetpacketsrc2)

   Call Write_rtl8019as(rdmaport , T_enetpacketsrc3)

   Call Write_rtl8019as(rdmaport , T_enetpacketsrc4)

   Call Write_rtl8019as(rdmaport , T_enetpacketsrc5)

End Sub





Sub Icmp

'set echo reply

T_icmp_type = &H00

T_icmp_code = &H00

'setup the IP-header

Call Setipaddrs

Call Icmp_checksum

Call Echopacket

End Sub





' Routine to handle the source/destination address

'

Sub Setipaddrs

T_ip_destaddr = T_ip_srcaddr

'make ethernet module IP address source address

T_ip_srcaddr = My_ip

Call Packetshape

Call Ip_header_checksum

End Sub





' Routine to echo a complete packet

'

Sub Echopacket

Call Write_rtl8019as(cr , &H22)

Call Write_rtl8019as(tpsr , Txtstart)

Call Write_rtl8019as(rsar0 , &H00)

Call Write_rtl8019as(rsar1 , &H40)

Call Write_rtl8019as(isr , &HFF)

Hulp1 = T_enetpacketlenl - 4

Call Write_rtl8019as(rbcr0 , Hulp1)

Call Write_rtl8019as(rbcr1 , T_enetpacketlenh)

Call Write_rtl8019as(cr , &H12)

Result16h = T_enetpacketlenh

Result16l = T_enetpacketlenl

Result16 = Result16 - 4

Txlen = Result16

'write the complete packet to the RTL8019AS from packet(1) to packet(txlen+1)

Hulp2 = Txlen + 1

For I = 1 To Hulp2

Call Write_rtl8019as(rdmaport , Packet(i))

Next I

Byte_read = 0

While Hulp1 <> 0

Hulp1 = Byte_read And Rdc

Call Read_rtl8019as(isr)

Wend

Hulp1 = T_enetpacketlenl - 4

Call Write_rtl8019as(tbcr0 , Hulp1)

Call Write_rtl8019as(tbcr1 , T_enetpacketlenh)

Call Write_rtl8019as(cr , &H24)

End Sub





Sub Packetshape

'move hardware source address to destination address

T_enetpacketdest0 = T_enetpacketsrc0

T_enetpacketdest1 = T_enetpacketsrc1

T_enetpacketdest2 = T_enetpacketsrc2

T_enetpacketdest3 = T_enetpacketsrc3

T_enetpacketdest4 = T_enetpacketsrc4

T_enetpacketdest5 = T_enetpacketsrc5

' 'Make ethernet module mac address the source address

T_enetpacketsrc0 = Mymac(1)

T_enetpacketsrc1 = Mymac(2)

T_enetpacketsrc2 = Mymac(3)

T_enetpacketsrc3 = Mymac(4)

T_enetpacketsrc4 = Mymac(5)

T_enetpacketsrc5 = Mymac(6)

End Sub





' Routine to calculate a ICMP-checksum

'

Sub Icmp_checksum

   'clear the ICMP checksum

   T_icmp_cksum = &H00

   'calculate the ICMP checksum

   I_header_length = T_ip_pktlen1 - 20

   'I_header_length = I_header_length - 20

   I_odd = I_header_length Mod 2

   '14 for MAC-part

   '20 for IP-header

   'start on 35

   'ip_pktlen = 00 3c (60)

   'icmp-packetlengte = ip_pktlen - ip_header

   I_chksum32 = 0

   'Total packetlength - ip_header - 1

   Hulp6h = T_ip_pktlen0

   Hulp6l = T_ip_pktlen1

   Val1 = 35

   Val2 = Hulp6 + 13

   Call General_part_checksum(val1 , Val2)

   T_icmp_cksum0 = Val3

   T_icmp_cksum1 = Val4

End Sub





' Routine to calculate a IP-header checksum

'

Sub Ip_header_checksum

   Local Ip_x As Byte

   Local Ip_hulp1 As Byte

   Local Ip_chksum32 As Long

   Local Ip_checksum16 As Word

   Local Ip_temp16 As Word

   Local Ip_header_length As Byte

   'calculate the IP header checksum

   T_ip_hdr_cksum = &H00

   I_chksum32 = 0

   Ip_header_length = T_ip_vers_len And &H0F

   Ip_header_length = 4 * Ip_header_length

   I_chksum32 = 0

   I_odd = 0

   Val1 = 15

   Val2 = &H0E + Ip_header_length

   Call General_part_checksum(val1 , Val2)

   T_ip_hdr_cksum0 = Val3

   T_ip_hdr_cksum1 = Val4

End Sub





' Routine to handle UDP-traffic

'

Sub Udp

Local Udp_port As Word

Local Udp_porth As Byte

Local Udp_portl As Byte

Local Lhulp1 As Word

Local Lhulp2 As Word

Local Lhulp3 As Word

Local Lhulp4 As Word



Readeeprom Udp_porth , 11

Readeeprom Udp_portl , 12

Udp_port = Udp_porth

Shift Udp_port , Left , 8

Udp_port = Udp_port + Udp_portl



      'From within a VB-program

      If T_udp_destport = Udp_port Then



            Triggerstr = ""

            Lhulp1 = &HEA

            Lhulp3 = Lhulp1 + T_udp_len1

            Decr Lhulp3

            'remove header

            Lhulp3 = Lhulp3 - 8

            For Lhulp2 = Lhulp1 To Lhulp3

               Lhulp4 = Inp(lhulp2)

               Triggerstr = Triggerstr + Chr(lhulp4)

            Next Lhulp2



            Lcd_t = "*" + Triggerstr

            Call Lcd_txt



            Print Triggerstr



            'Build The Ip Header

            Call Setipaddrs

            'swap the UDP source and destinations port

            Swap T_udp_srcport0 , T_udp_destport0

            Swap T_udp_srcport1 , T_udp_destport1

            Call Udp_checksum

            Call Write_rtl8019as(cr , &H22)

            Call Echopacket

      End If

End Sub





' Routine to calculate the Udp-checksum

'

Sub Udp_checksum

   T_udp_chksum0 = &H00

   T_udp_chksum1 = &H00

   'checksum TCP header

   I_chksum32 = 0

   I_value16h = T_ip_srcaddr0

   I_value16l = T_ip_srcaddr1

   I_chksum32 = I_chksum32 + I_value16

   I_value16h = T_ip_srcaddr2

   I_value16l = T_ip_srcaddr3

   I_chksum32 = I_chksum32 + I_value16

   I_value16h = T_ip_destaddr0

      I_value16l = T_ip_destaddr1

   I_chksum32 = I_chksum32 + I_value16

   I_value16h = T_ip_destaddr2

   I_value16l = T_ip_destaddr3

   I_chksum32 = I_chksum32 + I_value16

   'proto

   I_chksum32 = I_chksum32 + T_ip_proto

   'packet length

   I_value16h = T_udp_len0

   I_value16l = T_udp_len1

   I_chksum32 = I_chksum32 + I_value16

   I_odd = T_udp_len1 Mod 2

   Result16h = T_udp_len0

   Result16l = T_udp_len1

   Val1 = &H23

   Val2 = &H23 + Result16

   Val2 = Val2 - 2

   Call General_part_checksum(val1 , Val2)

   T_udp_chksum0 = Val3

   T_udp_chksum1 = Val4

End Sub





Sub General_part_checksum(byval Val1 As Byte , Byval Val2 As Word)

   For I_x = Val1 To Val2 Step 2

      I_value16h = Packet(i_x)

      Hulp3 = I_x + 1

      I_value16l = Packet(hulp3)

      I_chksum32 = I_chksum32 + I_value16

   Next I_x

   If I_odd = 1 Then

      Incr Val2

      I_value16h = Packet(val2)

      I_value16l = 0

      I_chksum32 = I_chksum32 + I_value16

   End If

   I_checksum16 = Highw(i_chksum32)

   I_checksum16 = I_checksum16 + I_chksum32                 ' only 16 lower bits of i_chksum32 is taken...

   I_checksum16 = Not I_checksum16

   Val3 = High(i_checksum16)

   Val4 = Low(i_checksum16)

End Sub





'Subroutine to initialize the LCD-display



Sub Lcd_init

Waitms 15

'set 8-bit mode (attention)

'toggle the E -line

'set 8-bit mode (attention)

'set 8-bit mode (attention)

'set 4-bit operation

Temparray(1) = &B10000011

Temparray(2) = &B00000011

Temparray(3) = &B10000011

Temparray(4) = &B00000011

Temparray(5) = &B10000011

Temparray(6) = &B00000011

Temparray(7) = &B10000010

Temparray(8) = &B00000010

Temparray(9) = &B10000010

Temparray(10) = &B00000010

Temparray(11) = &B10001000

Temparray(12) = &B00001000

Temparray(13) = &B10000000

Temparray(14) = &B00000000

Temparray(15) = &B10001000

Temparray(16) = &B00001000

Temparray(17) = &B10000000

Temparray(18) = &B00000000

Temparray(19) = &B10001100

Temparray(20) = &B00001100

Temparray(21) = &B10000000

Temparray(22) = &B00000000

Temparray(23) = &B10000001

Temparray(24) = &B00001001

I2csend Pcf8574 , Temparray(1) , 24

End Sub





' Routine to send a character to the LCD-display

'

Sub Lcd_char(lcd_c As Byte)

If Lcd_c = 42 Then                                          '* CLS/HOME

Call Lcdhome

Elseif Lcd_c = 35 Then                                      '# second line

Call Secondline

Else

Lcd_temp = Lcd_c And &HF0

Rotate Lcd_temp , Right , 4

I2csend Pcf8574 , Lcd_temp

Set Lcd_temp.e

Set Lcd_temp.rs

Temparray2(1) = Lcd_temp

Reset Lcd_temp.e

Reset Lcd_temp.rs

Temparray2(2) = Lcd_temp

I2csend Pcf8574 , Temparray2(1) , 2

Lcd_temp = Lcd_c And &H0F

I2csend Pcf8574 , Lcd_temp

Set Lcd_temp.e

Set Lcd_temp.rs

Temparray2(1) = Lcd_temp

Reset Lcd_temp.e

Reset Lcd_temp.rs

Temparray2(2) = Lcd_temp

I2csend Pcf8574 , Temparray2(1) , 2

End If

End Sub





' Routine to send a string to the LCD-display

'

' Fill lcd_t with the text and call lcd_txt

'

Sub Lcd_txt

Lcd_hulp = Len(lcd_t)

For Lcd_x = 1 To Lcd_hulp

   Lcd_tempstr = Mid(lcd_t , Lcd_x , 1)

   Lcd_temp = Asc(lcd_tempstr)

   Call Lcd_char(lcd_temp)

Next Lcd_x

End Sub





Sub Lcdhome

Temparray2(1) = &B10000000

Temparray2(2) = &B00000000

Temparray2(3) = &B10000001

Temparray2(4) = &B00000001

I2csend Pcf8574 , Temparray2(1) , 4

Waitms 2

End Sub





Sub Secondline

Call Firstline

For Lcd_h = 1 To 40

     Temparray2(1) = &B10000001

     Temparray2(2) = &B00000001

     Temparray2(3) = &B10000100

     Temparray2(4) = &B00000100

     I2csend Pcf8574 , Temparray2(1) , 4

Next Lcd_h

End Sub





Sub Firstline

Temparray2(1) = &B10000000

Temparray2(2) = &B00000000

Temparray2(3) = &B10000010

Temparray2(4) = &B00000010

I2csend Pcf8574 , Temparray2(1) , 4

End Sub









Sub Setup_packet

'Move IP source address to destination address

T_ip_destaddr = T_ip_srcaddr

'Make ethernet module IP address source address

T_ip_srcaddr = My_ip

'Move hardware source address to destinatin address

Call Packetshape

Call Ip_header_checksum

End Sub





' Routine to get a configuration-screen on the RS232 port

'

Sub Configure

Local Adr As Word

Local Row As Byte

Local Ipnr As String * 15

Local Dot1 As Byte

Local Dot2 As Byte

Local Dot3 As Byte

Local Dot4 As Byte

Local Dot5 As Byte

Local Iptemp As String * 1

Local Ippart As String * 3

Local Macadr As String * 20

Print Chr(&H1b) ; "[2J";                                    ' ANSI goto 0/0

Print "VA3TO Atmega32 Loader Version 1.20"

Print

Print "Source written by Ben Zijlstra october 2005"

Print

Print "Present configuration:"

Print

Print "Network:"

Print

Print "IP-number: ";

Call Read_ip

Call Print_ip

Call Read_mac

Print

Print "MAC-address: ";

Print Hex(mymac(1)) ; "-" ; Hex(mymac(2)) ; "-" ; Hex(mymac(3)) ; "-" ; Hex(mymac(4)) ; "-" ; Hex(mymac(5)) ; "-" ; Hex(mymac(6))

Print

Print

Print "Press 'y' to get into configuration mode"



Test:

Incr Hulp3

If Hulp3 = 65000 Then

   Incr Hulp1

   Hulp3 = 0

End If

If Hulp1 = 25 Then

   Goto Noresponse

End If

sbis USR,7

rjmp test



Configuremode:

If Lcdpresent = 1 Then

   Call Lcd_init

   Lcd_t = "Configure-mode"

   Call Lcd_txt

End If

Print Chr(&H1b) ; "[2J";                                    ' ANSI goto 0/0 Print

Print "Configure mode:"

Print

Print "Network:"

Print

Print "IP-number: ";

Call Print_ip

Input "Change IP-number (y/n) " , Yn

If Yn = "y" Then

   Print

   Print "Input IP-numbers as decimals, seperated by a dot (like 192.168.1.106)"

   Print

   Input Ipnr

      Hulp1 = Len(ipnr)

   For Hulp2 = 1 To Hulp1

      Incr Dot1

      Iptemp = Mid(ipnr , Hulp2 , 1)

      If Iptemp = "." Then

         Exit For

      End If

   Next

   Dot2 = Dot1

   Incr Dot1

   For Hulp2 = Dot1 To Hulp1

      Incr Dot2

      Iptemp = Mid(ipnr , Hulp2 , 1)

      If Iptemp = "." Then

         Exit For

      End If

   Next

   Dot3 = Dot2

   Incr Dot2

   For Hulp2 = Dot2 To Hulp1

      Incr Dot3

      Iptemp = Mid(ipnr , Hulp2 , 1)

      If Iptemp = "." Then

         Exit For

      End If

   Next

   Incr Dot3



   Ippart = Mid(ipnr , 1 , Dot1)

   Myip(1) = Val(ippart)

   Hulp1 = Dot2 - Dot1

   Ippart = Mid(ipnr , Dot1 , Hulp1)

   Myip(2) = Val(ippart)

   Hulp1 = Dot3 - Dot2

   Ippart = Mid(ipnr , Dot2 , Hulp1)

   Myip(3) = Val(ippart)

   Ippart = Mid(ipnr , Dot3)

   Myip(4) = Val(ippart)



   Print

   Print "New IP-number: ";

   Call Print_ip

   Print

   Input "Accept IP-number (y/n) " , Yn

   If Yn = "y" Then

      Writeeeprom Myip(1) , 1 : Writeeeprom Myip(2) , 2

      Writeeeprom Myip(3) , 3 : Writeeeprom Myip(4) , 4

    End If

    Print

    Print "IP-number: ";

    Call Read_ip

    Call Print_ip

End If

Print

Input "Change MAC-address (y/n) " , Yn

If Yn = "y" Then



Mac:

Print

Print "Input MAC-address in hexadecimals, seperated by a - (like 00-34-35-36-37-48)"

Print

Input Macadr

If Len(macadr) <> 17 Then Goto Mac



Mymacs(1) = Mid(macadr , 1 , 2)

Mymacs(2) = Mid(macadr , 4 , 2)

Mymacs(3) = Mid(macadr , 7 , 2)

Mymacs(4) = Mid(macadr , 10 , 2)

Mymacs(5) = Mid(macadr , 13 , 2)

Mymacs(6) = Mid(macadr , 16 , 2)



Mymac(1) = Hexval(mymacs(1))

Mymac(2) = Hexval(mymacs(2))

Mymac(3) = Hexval(mymacs(3))

Mymac(4) = Hexval(mymacs(4))

Mymac(5) = Hexval(mymacs(5))

Mymac(6) = Hexval(mymacs(6))



   Print

   Print "New MAC-address: ";

   Call Print_mac

   Print

   Input "Accept MAC-address (y/n) " , Yn

   If Yn = "y" Then

      Writeeeprom Mymac(1) , 5 : Writeeeprom Mymac(2) , 6

      Writeeeprom Mymac(3) , 7 : Writeeeprom Mymac(4) , 8

      Writeeeprom Mymac(5) , 9 : Writeeeprom Mymac(6) , 10

    End If

    Print

    Print "MAC-address: ";

    Call Read_mac

    Call Print_mac

End If

Print

Input "Would you like to use it's own IP-number as refresh-URL (y/n) " , Yn

If Yn = "y" Then

      Hulp1 = 255

      Writeeeprom Hulp1 , 13

   Else

      Print

      Input "Would you like to have another refresh-URL (y/n) " , Yn

      If Yn = "y" Then

        Input "Type the complete refresh URL " , Msg_temp

        Print

        Print "Refresh URL " ; Msg_temp

        Print

        Input "Accept Refresh-URL (y/n) " , Yn

        If Yn = "y" Then

             Hulp2 = Len(msg_temp)

             Writeeeprom Hulp2 , 13                         ' write length of Refresh URL

             For Y = 1 To Hulp2

                Hulp1 = Y + 13

                Tempstring1 = Mid(msg_temp , Y , 1)

                Hulp2 = Asc(tempstring1)

                Writeeeprom Hulp2 , Hulp1

             Next Y

        End If

      End If

End If



Print

Hulp5 = 5000

Writeeeprom Hulp5h , 12                                     ' &h1388 = 5000 dec = 19 high, 136 low.

Writeeeprom Hulp5l , 11



Input "Would you like to change to UDP Portnumber. It's default is 5000 (y/n) " , Yn

If Yn = "y" Then

   Print

   Input "Type the portnumber < 65536 as decimal " , Hulp5

   Print

   Print "Portnumber UDP " ; Hulp5

   Print

   Input "Accept Portnumber UDP (y/n) " , Yn

   If Yn = "y" Then

      Writeeeprom Hulp5h , 12

      Writeeeprom Hulp5l , 11

   End If

End If

Print





Print Chr(&H1b) ; "[2J";                                    ' ANSI goto 0/0 Print

Input "Would you like to see all devices on the I2c-bus (y/n) " , Yn

If Yn = "y" Then

   Print "I2c-device locator   1 = no device     0 = device"

   Print

   Print "       0    2    4    6    8    A    C    E"

   Print " 0000 ";

   For Adr = 0 To 254 Step 2

      Row = Adr Mod 16                                      ' addresses

      If Row = 0 And Adr > 0 Then

         Print                                              ' end of line?

         Print " " ; Hex(adr) ; " ";

      End If

      I2cstart                                              ' generate start

      I2cwbyte Adr

      Print " " ; Err ; "   ";                              ' 1 no device, 0 device

      I2cstop

   Next Adr

   Print

End If

Print

Input "Any key to continue...." , Yn

Print



Input "Would you like to use a LCD-display? " , Yn

Readeeprom Hulp1 , 0

If Yn = "y" Then

   Hulp1.0 = 0

   Writeeeprom Hulp1 , 0

   Print

   Print "There are two kinds of PCF8574 I2c-I/O-ports"

   Print

   Print "The PCF8574  has base address 40"

   Print "The PCF8574A has base address 70"

   Print

   Inputhex "At what address is the I2c-PCF8574x located : " , Pcf8574

   Writeeeprom Pcf8574 , 100

   Print

   Call Lcd_init

   Lcd_t = "LCD Testmessage"

   Call Lcd_txt

   Else

   Hulp1.0 = 1

   Writeeeprom Hulp1 , 0

End If



Noresponse:

Print Chr(&H1b) ; "[2J";                                    ' ANSI goto 0/0

Print "Summary:"

Print

Print "Network:"

Print

Print "IP-number  : " ; Myip(1) ; "." ; Myip(2) ; "." ; Myip(3) ; "." ; Myip(4)

Print

Print "Mac-address: " ; Hex(mymac(1)) ; "-" ; Hex(mymac(2)) ; "-" ; Hex(mymac(3)) ; "-" ; Hex(mymac(4)) ; "-" ; Hex(mymac(5)) ; "-" ; Hex(mymac(6))

Print

Print "URL-refresh: ";

Readeeprom Hulp1 , 13

If Hulp1 = &HFF Then

      Print "http://" ; Myip(1) ; "." ; Myip(2) ; "." ; Myip(3) ; "." ; Myip(4)

   Else

      Msg_temp = ""

      For Y = 1 To Hulp1

         Hulp3 = Y + 13

         Readeeprom Hulp2 , Hulp3

         Msg_temp = Msg_temp + Chr(hulp2)

      Next Y

      Print Msg_temp

End If

Print

Print "UDP-port   : ";

Readeeprom Hulp5h , 12

Readeeprom Hulp5l , 11

Print Hulp5

Print

If Lcdpresent = 0 Then

   Print "LCD-display: not used"

   Else

   Print "LCD-display: used"

   Print

   Readeeprom Pcf8574 , 100

   Print "Address hex: " ; Hex(pcf8574)

End If

Print

Print

Print "Running..."

End Sub





' Routine to read the IP-numbers from the EEPROM

'

Sub Read_ip

   Readeeprom Myip(1) , 1 : Readeeprom Myip(2) , 2

   Readeeprom Myip(3) , 3 : Readeeprom Myip(4) , 4

End Sub





' Routine to print the IP-number

'

Sub Print_ip

   Print Myip(1) ; "." ; Myip(2) ; "." ; Myip(3) ; "." ; Myip(4)

End Sub





' Routine to read the MAC-address from the EEPROM

'

Sub Read_mac

   Readeeprom Mymac(1) , 5 : Readeeprom Mymac(2) , 6

   Readeeprom Mymac(3) , 7 : Readeeprom Mymac(4) , 8

   Readeeprom Mymac(5) , 9 : Readeeprom Mymac(6) , 10

End Sub





' Routine to print the MAC-address

'

Sub Print_mac

   Print Hex(mymac(1)) ; "-" ; Hex(mymac(2)) ; "-" ; Hex(mymac(3)) ; "-" ; Hex(mymac(4)) ; "-" ; Hex(mymac(5)) ; "-" ; Hex(mymac(6))

End Sub





' Routine to send a default-message to the LCD

'

Sub Default_message

Call Read_ip

If Lcdpresent = 1 Then

   Call Lcd_init

   Lcd_t = "Embedded Server#IP: "

   Call Lcd_txt

   Lcd_t = Str(myip(1)) + "." + Str(myip(2)) + "." + Str(myip(3)) + "." + Str(myip(4))

   Call Lcd_txt

End If

End Sub

出0入0汤圆

发表于 2006-3-30 10:40:12 | 显示全部楼层
看来avr的Basic暂时还没有实现tcp/ip

出0入0汤圆

 楼主| 发表于 2006-3-30 13:03:51 | 显示全部楼层
呵呵呵早在bascom-avr11174版本上面就实现了TCP/IP语句的调用,在1118X上更加完善了,这个可以参考bascom-avr11182build6使用手册,那上面清清楚楚。

出0入0汤圆

发表于 2006-4-1 16:24:44 | 显示全部楼层
If T_enetpackettype = &H0608 Then

      If T_arp_hwtype1 = &H01 Then

         If T_arp_prttype1 = &H00 Then

            If T_arp_hwlen = &H06 Then

               If T_arp_prlen = &H04 Then

                  If T_arp_op1 = &H01 Then

                     If My_ip = T_arp_tipaddr Then

                        Call Arp

                     End If

                  End If

               End If

            End If

         End If

      End If

   End If



这样的写法真是令人惊愕

出0入0汤圆

发表于 2006-4-1 20:55:14 | 显示全部楼层
呵呵,不要惊愕,这是Bascom令人用得很不爽的地方之一,表达式中变量不能超过3个,所以每个判断只能用一个条件,有时用着就冒火!



看来还是有些人想买正版Bascom的,看阿莫老大能不能操作一下,和阿贵联手,与 bascomchina商量看能不能针对中国内地出一批内地版的Bascom,售价在10欧元(¥100)以内我就买,我想大家也能接受,毕竟现在国内很多软件也是卖几十块嘛。

她现在每套卖¥800,就会逼着几位哥们合买一套共用,凑不够数还买不成,如果把价降下来,大伙也没必要想办法D去,各得其所,多好?



虽然 bascomchina 帮着要做内地市场,但没有合适的渠道是很难运作的,Ouravr和Basicavr就是很好的渠道,bascomchina 应该想到呀?制定一个合理的价格策略,软件这东西,能卖点钱总比守着发霉好。

出0入0汤圆

 楼主| 发表于 2006-4-1 21:08:27 | 显示全部楼层
favr老大你还别说,bascom除了这个,令人更冒火的就是那个不能连续书写算数式,非要每一个定义一个中间变量,比如说我要计算F=A+B+C+D+E,在fastavr里面倒还好办,直接连写就可以了,但是bascom里面需要个temp才能操作,还有很多地方跟我提到的这个问题类似,很晕菜的,虽然高度兼容了QB,但是带来了很多麻烦。



内地版当然好,但是别就一个裤头就打发人了,那样不爽啊,起码内地版功能要同现在800元的Z版一模一样才行,也不要求功能更多了。哎,不知道Mark是如何想的。。。

出0入0汤圆

发表于 2011-8-22 13:33:16 | 显示全部楼层
mark
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-12 12:27

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表