TheByteWorks

    Quality ready made and affordable custom software

Home

Software

PHP Serial
rsterm
Easy Control
Rack Designer
EzCom2Web

Quick Texts
Wallpaper Slideshow

Articles

All articles
WS2300 weather station PHP project
Your own terminal in 17 lines
PC PIC Voltmeter
Network messenger in 22 lines
Phone Dialer

Download
Purchase

Support

Details
E-mail

Copyright for the past, present and future
© Cosmin Buhu

  PIC Port Analyzer
Screenshot

PIC Ports Analyzer

Dumps status of your PIC microcontroller ports into a nice rack.

In this project we'll use a Microchip PIC16x84 microcontroller connected on a PC serial port.
The code burnt in microcontroller will send to the Easy Control status of its ports to be displayed
into a nice rack designed in Rack Designer.

Step 1
Design rack in Rack Designer, or you may download example archive which contains the
picports rack (see screenshot on the left side of this article).
Controls on this rack are:
- a few borders
- a few labels
- a few leds

Step 2
Write for your microcontroller a program that will do next:
- make all ports inputs. Don't forget to enable weak pull-ups or (better) place pull-ups yourself (if needed)
- wait for the "go" string to be received on its rx pin
- fill a 16 bit variable (for PIC16c84) with state of the ports, like this:
portb.0(bit0)...portb.7(bit7) porta.0(bit8)...porta.4(bit12)
- send this variable as ASCII representation of its binary value on its tx pin
- and repeat, and repeat all

Below is the equivalent PicBasic code for this.
PicBasic is a very good Basic compiler for PIC microcontrollers. Take a look and you'll love it
for sure.

meanless var byte
ports var word
myportb var ports.lowbyte
myporta var ports.highbyte
option_reg.7=0
trisa=255 'PORTA input
trisb=%11111011 'PORTB.2 output (for tx), the rest inputs
pause 2000
starthere: serin portb.6,6,["go"],meanless
myporta=porta
myportb=portb
serout2 portb.2,16468,[bin16 ports,13,10]
goto starthere
end

Step 3
Write or open in Easy Control this script code (note: syntax is for Easy Control v. 1.4):

crlf=chr(13)&chr(10)
#Open rack. Don't forget to write the right file path
openrack (d:\analyzer\analyzer.res)
#Setup and open port
setport
openport (myport,9600,8,n,1)
label39="Connected on port "&myport
#You may show terminal window if you want to watch data flow
#showterm (myport)
again:
#Send "go" command to PIC
send (myport,"go1")
#Wait for data ended with CRLF to be received from PIC
repeat
received=receive (myport)
posofcrlf=pos (crlf,received)
until (posofcrlf<>0)
#Extract bit by bit and set leds accordingly
temp=mid (received,16,1)
led1=temp
temp=mid (received,15,1)
led2=temp
temp=mid (received,14,1)
led3=temp
temp=mid (received,13,1)
led4=temp
temp=mid (received,12,1)
led5=temp
temp=mid (received,11,1)
led6=temp
temp=mid (received,10,1)
led7=temp
temp=mid (received,9,1)
led8=temp
temp=mid (received,8,1)
led9=temp
temp=mid (received,7,1)
led10=temp
temp=mid (received,6,1)
led11=temp
temp=mid (received,5,1)
led12=temp
temp=mid (received,4,1)
led13=temp
#Flush receive buffer, to have fresh data next time
flush (myport)
goto again

Download this project :
PIC Ports Analyzer

More ?
Well,change code for bigger/other microcontrollers, timeouts, memory dumps, visual enhancements,...

Enjoy !