Click here to Skip to main content
Click here to Skip to main content

Counter based c8051

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

Introduction

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.

1.JPG

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.

Background

Silabs CP2201EK can be found on local Radioshack store (order from web?).
https://www.silabs.com/Support%20Documents/TechnicalDocs/CP2201-EK.pdf
https://www.silabs.com/products/mcu/Pages/CP2201EK.aspx

2.JPG

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.

3.JPG

Counter_based_c8051/3b.JPG
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.

UniSockProject.JPG 

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.

SafeFinder2.JPG

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
   PORT_Init();
   SYSCLK_Init();
   EMIF_Init();
   Timer2_Init();
  
   #if(UART_ENABLED)
   UART0_Init();
   printf("\n*** Reset ***\nC8051F34x MCU Initialized\n");
   printf("RSTSRC = %bx\n", RSTSRC);
   #endif
   if(RSTSRC & 0x03) netfinder_reset_event1();
 RED_LED=0; 
 while(1)
   {
      if (mn_init() < 0){while(1);}
      YELLOW_LED_STATE = BLINK_SLOW;
      establish_network_connection();
      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;}
      netfinder_reset_event2();
      if( netfinder_start() < 0 ){YELLOW_LED_STATE = SOLID_OFF; while(1);}
      //UDP();
      #if(TELNET_ENABLED)
      telnet_socket_no = mn_open(ip_dest_addr,DEFAULT_PORT,SEND_PORT,
		ACTIVE_OPEN,PROTO_UDP,STD_TYPE,TELNET_BUFF, TELNET_STR_SIZE);
      if (telnet_socket_no < 0) {
     TELNET_STATE = SOCKET_ERROR;
   printf("TELNET_STATE = SOCKET_ERROR=%bd",telnet_socket_no);
  }
  else {
  TELNET_STATE = CONNECTED;
   printf("TELNET_STATE = CONNECTED\n");
  }
      #endif
      retval = mn_server();
      YELLOW_LED_STATE = BLINK_SLOW;
   }
}

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 HIDtoUART_FW.zip - 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 usbhidio2.zip (VB6).

usbUART.JPG
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 USB_IR.zip (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.

History

  • 22nd February, 2009: Initial post

License

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

Share

About the Author

ingvar8

Estonia Estonia
No Biography provided

Comments and Discussions

 
GeneralTell me again... Pinmemberkaschimer11-Mar-09 9:15 
GeneralRe: Tell me again... Pinmemberingvar815-Mar-09 6:33 
GeneralRe: Tell me again... Pinmemberyesman30-Aug-09 18:48 
GeneralLooks cool...but... PinmemberShane Story26-Feb-09 12:13 
GeneralRe: Looks cool...but... Pinmemberingvar827-Feb-09 2:44 
GeneralRe: Looks cool...but... PinmemberShane Story27-Feb-09 3:30 
GeneralRe: Looks cool...but... Pinmemberingvar81-Mar-09 23:28 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 22 Feb 2009
Article Copyright 2009 by ingvar8
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid