Click here to Skip to main content
14,030,532 members
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 22 Feb 2009
Licenced CPOL

Counter based c8051

, 22 Feb 2009
Rate this:
Please Sign up or sign in to vote.
Counter based c8051


UniSockProject is a NetFinder like utility to find Silabs CP2201EK in local network and update firmware images (boot1, boot2, boot3) to device.

  • boot1: image which counts every 1 rotation of disk to count 1 meter of plastic made 
  • boot2: 2 rotation of disk(2 sensor counts)= 1 m
  • boot3: 3 ticks = 1m

prClient is a desktop version for client monitoring the counter.


Sensor connected to P0.3-> grnd
P0.2 reset input
If counts is bigger, then reset value of the output P2.6 (the so called LS_EN) goes high
(you can put a 5V small relay or transistor there that switches other load) - see documentation for allowed current.

Software used: Silabs IDE ver.'3.42' - this is with 'toolstick' package CD or from Silabs download.

Keil Compiler ver. '8.16a' downloadable from web.
There is a software forum for questions here.


Silabs CP2201EK can be found on local Radioshack store (order from web?).


Using the Code

To use this VB6 source code, you must update the Silabs chip with hex file provided.
To update firmware, use 'toolstick' from Silabs - as I did.

Prototype board: Protot
Firmware can be updated by 'toolstick' (if you can solder that - look also at another ver of toolstick like 'Toolstick Base Adapter'- which has a better - bigger pin interface for soldering wires). I preferred as small as possible.


Anyway you need this only once - for the first firmware upload. After that, you can use the 'LAN' ethernet interface.

To do, just use the File-> 'boot1' button.
To do so, you must first find the device by pressing 'Search' menu and 'Ping' does not hurt.
If the device is in bootloader mode, then you must see this image.


Options are:

  • '1'-the chip increments automatically the sensor data
  • '2'-restart device
  • '3'-reset counter
  • '4'-bootloader mode

If string is longer then one character - sends its reset value to device.
Example '33' puts ResetValue to '33' meters (originally alarm is set on 150m).

Or you can view all that in the PocketPC- the SafeFinder C# VS 2005 .NET version.


With this program all commands suites to VB6 version UniSockProject.
Additional that pocket will signal with vibration and sound that it is time to change the roll of plastic.
You can change the sound for that in app dir 'tada.wav'- where you put the boot-files also.
For those that want some true code, I give the main of a modified code for c8051f340 a.k. CP2201EB.

void main(void)
   int retval;
bootload = 0;
autoload = 0;
reset = 0;
   // Disable watchdog timer
   PCA0MD = 0x00;
   // Initialize the MCU
   printf("\n*** Reset ***\nC8051F34x MCU Initialized\n");
   printf("RSTSRC = %bx\n", RSTSRC);
   if(RSTSRC & 0x03) netfinder_reset_event1();
      if (mn_init() < 0){while(1);}
      if (mn_dhcp_start(PTR_NULL, dhcp_default_lease_time) <= 0)
      {  dhcp_lease.infinite_lease = 1;// Override DHCP
         dhcp_lease.dhcp_state = DHCP_OK;         
         ip_src_addr[0] = 0;// Specify a static IP address
         ip_src_addr[1] = 0;
         ip_src_addr[2] = 0;
         ip_src_addr[3] = 1;}
      if( netfinder_start() < 0 ){YELLOW_LED_STATE = SOLID_OFF; while(1);}
      telnet_socket_no = mn_open(ip_dest_addr,DEFAULT_PORT,SEND_PORT,
      if (telnet_socket_no < 0) {
   printf("TELNET_STATE = SOCKET_ERROR=%bd",telnet_socket_no);
  else {
   printf("TELNET_STATE = CONNECTED\n");
      retval = mn_server();

This is really a modified Silabs TelNet sample so do not put attention to a TELNET port or other used constants - I really used port 8 to listen for broadcasted UDP messages.
So any computer that is a local network (and listening UDP port 8) can monitor the incoming messages.

Messages are sent by Silabs used Netfinder port - default 3040 - so you can use the Silabs made Netfinder program to find the device in network also.

As you can see, the interface can be monitored by 'hyperterminal' and allowed to see what is really happening there. You must set baudrate to 115200 no parity ...
I also make the interface to 'toolstick' (.hex again)- for that I suppose you need another 'toolstick' to update like I did. In case you broke your 'toolstick' original software - there is an original hex file '2.hex' in the zip file and you can put it back in order again.

Download - no drivers needed- its a 'Human intelligent device' - HID for USB Debug Adapter.(the smaller one) and VB6 Terminal that can read USB - UART interface download (VB6).

For interest, I can using that program to read any IR codes from any remote control - like WinLirc does. Just set baudrate to 4800 and you are set. But that is another story I suppose. For those interested, download (VB6).

Points of Interest

Silabs chips to not implement the real socket class - really only the udp protocol is suitable.
I can't find another way to monitor that 'counter' I made with multiple computers.


  • 22nd February, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Estonia Estonia
No Biography provided

Comments and Discussions

GeneralTell me again... Pin
kaschimer11-Mar-09 8:15
memberkaschimer11-Mar-09 8:15 
GeneralRe: Tell me again... Pin
ingvar815-Mar-09 5:33
memberingvar815-Mar-09 5:33 
GeneralRe: Tell me again... Pin
yesman30-Aug-09 17:48
memberyesman30-Aug-09 17:48 
GeneralLooks cool...but... Pin
Shane Story26-Feb-09 11:13
memberShane Story26-Feb-09 11:13 
GeneralRe: Looks cool...but... Pin
ingvar827-Feb-09 1:44
memberingvar827-Feb-09 1:44 
GeneralRe: Looks cool...but... Pin
Shane Story27-Feb-09 2:30
memberShane Story27-Feb-09 2:30 
GeneralRe: Looks cool...but... Pin
ingvar81-Mar-09 22:28
memberingvar81-Mar-09 22:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190419.4 | Last Updated 22 Feb 2009
Article Copyright 2009 by ingvar8
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid