PICNIC

ABOUT PICNIC

■ABOUT PICNIC

1. Overview of PICNIC

2. PICNIC Firmware

3. Usage of PICNIC

4. Exclusive control protocol for PICNIC

 

→Click here if you have some questions and comments.

←Back to the table of contents

Updated April 29, 2005 21:54

 

●Overview of PICNIC

What is PICNIC?Features & Circuit DiagramNecessary items for operation checkPICNIC Specifications


1.1.1 What is PICNIC?

The name "PICNIC" comes from taking the initials of "PIC Network Interface Card", which is an I/O board kit to connect to Ethernet networks using the PIC microcomputer chip, Microchip PIC16F877. Compared to the previous ver. 1 kit, the ver. 2 which we are going to use here is more compact: 70mm x 100mm. (see Pic. 1)

→Links to Microchip PIC series

Picture 1: network featured PIC microcomputer, PICNIC ver 2

 

PICNIC is a product of TriState and can be purchased from Akizuki Denshi Tsusyo.

→Links to TriState

→Links to Akizuki Denshi Tsusyo

By preparing an application program that can control PIC microcomputer's parallel I/O ports via a network, we can easily build systems to control the power of a peripheral device connected to the kit or collect data from various sensors.

Controlling and observing parallel I/O ports via a network can be done through the http-server of the firmware of a PIC microcomputer. So, if we have a web browser on any kind of operating system, we can control the attached device without any programming.

The network interface uses the Ethernet protocol. So we can build any experimental environment by simply preparing Ethernet network devices (such as hubs, etc.) and cables, which are cheaply and easily available on the market. Note, external networks (WAN or Internet connections) will require connections like ADSL, CATV which can access the global Internet.

However, by building PICNIC control protocol on the client, a dedicated system which does not use a web-browser can also be built. The library for controlling the system can be downloaded from TriState's web site.


1.1.2 Features & Circuit Diagram

* Uses PIC16F877 manufactured by Microchip (RISC Enhanced x16, DIP300/40pin CMOS Flash 8bit microcontroller, 87x series). → Data sheet (original) here

* Uses NE2000(DP8390) compatible RTL-8019AS by Realtek Semiconductor (10BASE-T 100pin/QFP one-chip Ethernet controller, crab chip).

* Main LSI, chip resistors, capacitors already soldered to circuit board. Simple kit assembly involving only implementation of connectors, DIP-IC sockets, I/O connectors, LEDs, etc.

<Figure 1> Functional block diagram

<Figure 2> Circuit diagram(reprinted from ※ TriState company data sheet)
Click here to display PDF file

※ Additional notes

* The PIC16F877 controller provides analog input pins on the RA port and general (digital) I/O pins on the RB port outside of the board. The input/output terminals are the CN2 connector (26 pin 100mil pitch) in the circuit diagram.

* The output (temperature coefficient +10.0mV/degree Celsius) of the linear temperature sensor IC (LM35DZ) implemented on the board is connected to the analog input pin RA5. In this way, it is possible to monitor temperature (approximate room temperature) around the board.

* If we connect the LCD module (option) to connector CN5, it will be shared with digital output port RB connector CN2 and number of external ports that can be used will be decreased.

* In the serial EEPROM 93C46(U2), the unique MAC address for the EthernetNIC controller of this PICNIC is preset.

* Jumper SW JP2 on the board is used to select whether to start in "normal mode" or "boot strap mode (initial setting)" on power up.


1.1.3 Necessary items for operation check

* (AC adapter for)DC12V power supply (Akizuki DC12V adapter recommended

* PC with 10BASE-T NIC(for checking in bootstrap mode, connection by RS-232C serial interface is necessary)(Picture 2)

* Ethernet hub (HUB) device and straight cables (2).

* For one-to-one connections only, cross cables can be used.

* Web browser

* For firmware development, an MPLAB (MPASM) development environment and a PIC writer device are necessary.

* For development using client-side drivers, a language development system such as Visual BASIC, Visual C++, GNU gcc, etc. is necessary.

<Picture 2> Connection of PC and operation check

If the board is operating correctly, connecting from a browser will show this type of page.


1.1.4 PICNIC Specifications

* Communication method: Ethernet 10BASE-T

* Access method: CSMA/CD

* Ethernet NIC: RTL-8019AS(NE2000 compatible)

* Control CPU: PIC16F877-20/P(20MHz clock drive)

* Built-in interface:
 (a) Digital input/output: Output 4ch, input 4ch(during LCD module use, output 6ch, input 2ch)
 (b) Analog I/O: Input 4ch (0-5V, 10 bit resolution) + 1ch for temperature sensor(measurement range 0-100 degrees Celsius)
 (c) Serial input/output: 1ch(RS-232C, no flow control)

* Built-in firmware protocols: ARP, DHCP, ICMP, IP, UDP, TCP, HTTP(GET method only)
* Maximum number of IP connections: 5

* Communication buffer: 16Kbyte(shares ring buffer in EthernetNIC)

* Default IP address: 192.168.0.200/24

* Peripheral functions: RS-232C serial interface (SP232ACP), temperature sensor (LM35DZ), 16x2 LCD display module(SC1602B, option)

* LED display: Input/output port output port states x4ch, Ethernet - NIC state LEDx3(TX,RX,LINK)

* Power supply: DC 8-12V 100mA

●PICNIC Firmware

Built-in protocol stacks in firmwareFirmware downloadingOutline of firmwareInitial configuration sequence of firmware


1.2.1 Built-in protocol stack in firmware

The protocol stack implemented in the firmware of this PICNIC is as follows.

* Ethernet frame Tx/Rx processing
* ARP Rx processing
* IP Rx processing
* ICMP Rx processing
* UDP Rx processing
* TCP Rx processing
* HTTP Rx processing


1.2.2 Firmware downloading

Download the firmware (ver1.2) for MPASM assemblers for PICNIC ver.2 below.

Assembly source file(v12.asm)

Assembled HEX file v12.hex)


1.2.3 Outline of firmware

The size of the entire firmware code is 7380 lines.
I will leave detailed explanations about the entire to the other article, but basic blocks are described below.

Lines 21-37: Definition of various constants
Lines 42-53: Working memory area
Lines 61-466: Definitions of various environment variables for protocol stacks

Line 470: Program start point(ORG 0)
Lines 482-621: Interrupt routines(Rx processing, timeouts)
Lines 628-815: Various functions(TCP frame number management, error return)

Lines 820-889: Main loop

Lines 902-1018: Ethernet frame Rx processing(RTL8019AS buffer management)
Lines 1025-1068: ARP protocol processing
Lines 1172-1341: IP protocol processing(Rx buffer management)
Lines 1349-1434: ICMP protocol processing
Lines 1441-1565: UDP protocol processing(parallel port output management)
Lines 1571-1682: DHCP (BOOTP) protocol processing(for IP address acquisition)
Lines 1690-2323: TCP protocol processing(server functions only, includes packet output routine)

Lines 2328-2393: A/D conversion input processing
Lines 2398-2500: Pre-processing routines for input and output states
Lines 2504-2558: Short message analysis processing
Lines 2563-2764: Making of network sockets, checksum calculations

Lines 2771-3032: Initialization of RTL8019AS
Lines 3037-3214: Checksum calculations, packet Rx processing(NIC level)
Lines 3221-3344: Ethernet frame, IP frame construction

Lines 3352-3578: UDP → parallel I/O control, A/D conversion functions
Lines 3584-3560: UDP checksum calculation
Lines 3655-3873: Serial interface control

Lines 3879-4024: Socket management
Lines 4030-4290: Ethernet broadcast processing

Lines 4295-4369: EEPROM data writes
Lines 4555-4577: EEPROM initialization
Lines 6063-6130: EEPROM-related library
Lines 7266-7306: EEPROM default value setting

Lines 4379-4548: URL designated CGI analysis processing
Lines 4583-4643: Changes in parallel I/O output value based on URL parameters

Lines 4651-4919: Startup routine(configurations on power up)
Lines 4625-5036: LCD display library
Lines 5042-5292: Various operation library functions group

Lines 5297-5404: Boot strap mode / initialization routine
Lines 5411-5944: Serial terminal operation commands
Lines 7015-7054: Boot strap mode / terminal display
Lines 7311-7374: Data for boot strap mode command analysis

Lines 5952-6056: Notification processing for current socket status(currently unused)

Lines 6139-6266: Processing for displaying acquired IP address to LCD panel
Lines 6431-6697: IP address acquisition processing from a DHCP server

Lines 6273-6424: Processing for serial port → UDP message Tx
Lines 6703-7009: UDP message Rx → serial port output, LCD panel display

Lines 7061-7258: Web browser HTML reply message / format storage area


Of these, the various protocol stacks already implemented will rarely ever be modified on the user side. Changes to the control page displayed in a web browser are done by modifying the HTML reply message and format storage area beginning at line 7061.

Because of the limitations on Ethernet frame length, we cannot send the entire HTML format text all at once. Instead, we break the text into four blocks (four transitions from ESTAB0 to ESTAB9) for sending. This transmission processing is implemented as a TCP packet processing sequencer from line 1690.

To allow for recovery from various freeze states of protocol processing such as Ethernet cable or network disconnection, an automatic reset function is implemented in the timer interrupt routine. For example, after a freeze, the system is designed to force a return to the TCP LISTEN state after about 15 seconds.

The PICNIC works as a simple HTTP server and based on the request from a web browser, the parameters contained in a URL are first analyzed, saved to the PIC internal EEPROM, and then each of the various external interfaces are controlled. After that, the currect PICNIC information (HTML text above) is sent to the browser.


1.2.4 Firmware initialization sequence

The sequence of the firmware startup routine (configurations on power up, from line 4651) is as follows.

(1) The necessary data for initialization (IP address, etc.) are copied from the built-in EEPROM to the RAM

(2) Initialization of the LCD (liquid crystal display) panel

(3) Initialization of EthernetNIC(RTL8019AS), loading of CONFIG register to NIC

(4) MAC address acquisition from external serial EEPROM 93C46

(5) Writing of MAC address acquired in(4)to the PAR register of NIC

(6) Confirmation of the operation mode from jumper SW state (normal or boot strap). Enter main routine of the indicated mode.

(7) If IP address acquisition (IP =0.0.0.0) from a DHCP server is necessary, send out a DHCP protocol DISCOVER broadcast message.

※ When the above processing is completed, enter a wait for Rx frame state.

●Usage of PICNIC

Remote input/output control from a web browserLCD moduleTest program using an exclusive control protocol


1.3.1 Remote input/output control from a web browser

In Fig. 3, we see the screen shown when we connect to the IP address assigned to the PICNIC using Microsoft Internet Explorer via Ethernet.
In this example, we connect using the global IP address: 160.252.131.19/25.

<Figure 3>An example of the remote input/output control screen using a web browser (HTML version)

The remote input/output control screen is divided roughly into three sections described below.

(1) Input/output Ports section

The current states of the input/output ports are displayed. Since the values are not updated in real time, to obtain the current readings, we need to use the [Reload/refresh] button of the browser or we can click the [Reload] button at the bottom of the section.

For the port states, the following information is displayed: analog input ports (RA0 to RA3), temperature sensor value (RA5, centigrade value), input and output states of digital input/output ports.

Changing of the output values can be controlled only for the ports RB2 to RB7 which are indicated as OUT.
When the [H] or [L] control values are clicked, the values are changed correspondingly to high or low.

On the server side, we assume a virtual CGI program called modify.cgi to respond and we can change the output values by passing parameters in the form output port number = value as parameters within the URL. For example, in the case of setting this PICNIC, if we use the following URL:
http://160.252.131.19/modify.cgi?RB7=H
the output port RB7 value will be changed to High.
The corresponding LED on the board concerned is also turned on.

The URL specifications for input/output port control are summarized below.

[Reloading of the current values]
http://160.252.131.19/modify.cgi?

[Example: Changing output port RB7 -> H]
http://160.252.131.19/modify.cgi?RB7=H

[Example: Changing output port RB7 -> L]
http://160.252.131.19/modify.cgi?RB7=L


(2) Configuration section

The current configuration for IP address,netmask value, gateway IP address, port numbers for various functions is displayed.

In the display example of Fig. 3, we see that the following configuration is used: IP address: 160.252.131.19, net mask 25bit, gateway: 160.252.131.1.

To change the configuration values, it is necessary to input the new values in the corresponding text fields, click the [Save] button, shutdown the power,and power up or press the reset button.

If the [Default] button is clicked, the defaults for a local IP segment, i.e., IP address: 192.168.0.200, net mask 24bit will be set.

By using the IP address to 0.0.0.0, the mode will be set to obtain an IP address from a DHCP (Dynamic Host Configuration Protocol) server.

The URL specifications for network configurations are summarized below.

[default values]
http://160.252.131.19/submit.cgi?00b=192.168.0.200&04b=255.255.255.0&08b=0.0.0.0
&10w=80&12w=0&14w=10001&16w=10002

[Return to initial values]
http://160.252.131.19/submit.cgi?INIT=Default

 

(3) Status section

The number of the packets and the current IP address value are displayed. In addition, the IP address display is meaningful only in the case of DHCP address acquisition.


1.3.2 LCD module

When the LCD liquid crystal display panel is connected, the current IP address will be displayed. If in DHCP address acquisition mode an address has been successfully assigned, the IP address will be displayed.

※ Note: If there is no value assigned to LCD Port UDP:# (all 0), the LCD panel will show ■■■■■.In an IP address display, this value should be set to some number, such as 10000.

When an LCD panel is not used:
RB0 - RB3 are inputs and RB4 - RB7 are outputs (available to the user)

When an LCD panel is used:
RB0,RB1 are inputs, RB2 - RB7 are the LCD output controls(shared with the user ports)


1.3.3 Test program using an exclusive control protocol

A test program (pictest.exe) using an exclusive control protocol which operates on Windows is distributed from the TriState company web site.

http://www.tristate.ne.jp/picnic/menu.html

Download the LZH file containing the sample program (pictest) + installer
http://www.tristate.ne.jp/picnic/pictest.lzh

Then decompress the file using a tool such as Lhasa and run setup.exe.

From [Start]→[Programs], run PICNIC test and set the IP address, LCD panel port number for displaying the acquisition time. By pressing the [Connect] button,connections to the PICNIC will be made at the intervals set and the currect I/O states will be displayed. On line 2 of the PICNIC LCD panel, the connection and data acquisition times of pictest will be displayed.

<Figure 4> Example of remote I/O state data acquisition using a test program

●Exclusive control protocol for PICNIC

Control API drivers for various platforms/languages can be downloaded from the TriState company web site below.

The 1.3.3 test programs (pictest.exe) mentioned above was developed using the PICNIC.DLL library and Visual C++ on Windows.

In this exercise, we will not address the exclusive control protocol. Please study it on your own.

http://www.tristate.ne.jp/picnic/menu.html

Shinshu University Graduate School on the Internet

wasaki@cs.shinshu-u.ac.jp
Copyright(c) 2005 Katsumi Wasaki. All rights reserved.