新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AVR單片機(jī)與網(wǎng)絡(luò)的連接

AVR單片機(jī)與網(wǎng)絡(luò)的連接

作者: 時間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
本文介紹關(guān)于ARV單片機(jī)通過一塊芯片W5100上網(wǎng)模塊與網(wǎng)絡(luò)進(jìn)行連接,一直以來對于嵌入式arduino怎么樣和網(wǎng)絡(luò)進(jìn)行連接一直是我很好奇的問題,難得這幾天公司給我一個關(guān)于利用嵌入式讓AVR連接的應(yīng)用,雖然對于英語水平還是很低下的我,沒辦法,為了興趣和工作,只好硬著頭皮看著外國一些關(guān)于AVR與網(wǎng)絡(luò)連接的論壇。其中收獲還是蠻大的,讓自己知道了一些關(guān)于網(wǎng)絡(luò)的知識和電路,特別是自己把一塊ENC28J60上網(wǎng)模塊的PCB順利畫出來進(jìn)行生產(chǎn),在畫這個板的時候也是費(fèi)了一番功夫,根據(jù)原理圖,我覺得第12和第13引腳不應(yīng)該是短路的,可是當(dāng)PCB板拿到手的時候進(jìn)行硬件測試,居然發(fā)現(xiàn)這兩個引腳連在了一起。百思不得其解,把PCB板和畫的圖進(jìn)行對比是沒有錯的,后來懷疑是IC的問題,但是經(jīng)過看數(shù)據(jù)手冊和IC不接在電路中的測試,沒有問題。最近對HR911105A網(wǎng)口進(jìn)行測試,興奮地發(fā)現(xiàn)了問題是第3和第6是連在一起的。找出問題根源。




一直對于arduino這種開發(fā)平臺和獨(dú)特的編程風(fēng)格的感興趣。特別是他具有一個實時和電腦進(jìn)行通訊的系統(tǒng)平臺,長話短說,還是把硬件進(jìn)行連接,以及代碼的編寫和調(diào)試,因為ardunio官方指代了一個關(guān)于Ethernet的庫,所以把它下載下來,加以研究。終于寫出了下面的一段代碼:
#include
//Test Code:
/*
* Web Server
*
* A simple web server that shows the value of the analog input pins.
*/
#include
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 48 };
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Client client =server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if weve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == n && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉