Phoenix Turbine Builders Club

Previous Back Next

More Programming Basics

Examining a Simple Terminal Program

August 2005

Continuing on our computer programming study, this month we will look at the basics of receiving status values sent by the PIC processor to a PC and then printing those values to a computer screen. - Let's get started.

Even though PICBasic and PowerBasic are both Basic compilers, program statements are written in quite different ways.

Last month we showed how we send data in one direction over a two-wire cable from a PIC to a PC. Let's briefly examine a wiring diagram to make the hardware connection.

Wiring diagram

Figure 1

In Figure 1 we see that pin 5 on the PIC processor and pin 5 on the PC 9-pin serial connector are both ground. Pin 9 on the PIC is the transmitter and Pin 2 on the PC is the receiver with a 1 kohm resistor between them for current limiting. The 9-pin female serial connector may be found at any Radio Shack store. Telephone line may be used for the cable as long as the length is relatively short. Twisted line or coax is best to reduce interference noise from fluorescent lights, etc.

Let's move on now the programming. As I mentioned earlier, we will be using PowerBasic to program the PC. Other Basic compilers such as Visual Basic may be used, but the syntax of the programming statements will vary.

Again, we are following the flowchart (figure 2) covered in our June 2005 article.

Figure 2

Figure 3 is a simple Terminal program with a continuous loop looking for data at the serial port.

 

Initialize:

Screen 12: Defint A-Z: $COM 1024

Open "Com2:9600,N,8,1" For Random as #1

CLS

Locate 2,16:Print "Solar Tracker Communications Demo"

Beep:Delay 5

Print:Print

Main:

While 1

While Not Instat

While LOC(1)<>0

Line Input #1,Status$

Print Status$,

Wend

Wend

Wend

Quit:

End

Figure 3

The initialize routine sets up the PC computer with a VGA screen, Com 2 serial port, and then prints an opening statement on screen, delaying 5 seconds before beginning data polling.

The "Main" routine is an endless loop that waits for a block of data on the serial line.

The "High" or "Low" data statement sent from the PIC is received and then printed to screen in columns.

That about wraps things up for now on the basics of programming telecommunications between PIC and PC systems. Of course, developing more complicated software for running a solar tracking system takes a lot more time and effort, but that's what our experimenter's club is for. So members who are more inclined toward the high tech end of things will really begin to take the lead in developing our Solar Tracking Turbo Generator System.

Next month we'll start wiring up our dish and see if we can get it to move. Till then, keep on driving this motive power revolution forward.

Ken Rieli

Last updated: July 02, 2008 11:21 PM

Phoenix Turbine Builders Club

FREE Open Source Forum

http://phoenixnavigation.com/ptbc/home.htm