Phoenix Turbine Builders Club

Previous Back Next

Solar Targeting

Translating the Flowchart into Lines of Software

July 2005

By now some of our club members may have their electronic development systems set up and operational. This month we are going to cover programming the PIC 16F84 CPU to look at the high/low state of one of its pins, and then send a data statement via a programmable serial line.

First of all, let's review a wiring block diagram (figure 1) of the 16F84:

Wiring block diagram - 16F84

Figure 1

The CPU is wired for run mode. You will notice on pin 6 we have set up a toggle switch to change the status of the pin from high to low. When the switch is open, pin 6 is pulled high. Closing the switch pulls pin 6 low, resulting in a state change. 

Pin 9 is wired as a simple RS232 serial interface which may be plugged into any PC that comes with a standard serial port. This will allow us to communicate between the PIC and PC.

Now, following our flow chart from last month (figure 2), we will write a program for the PIC processor that will look for the status of pin 6 and then transmit that value across the serial cable.

Figure 2

Figure 3 is an example of program code to do the job.

 

Initialize:

Input 6: Output 9: Low 9

Main:

If Pin 6=1 Then Highvalue

Lowvalue:

Serout 9, N9600,("Low")

Goto Main

Highvalue:

Serout 9,N9600,("High")

Goto Main

Figure 3

We begin by initializing the PIC pins for data input or output. Since we are using only pins 6 and 9 initializing is quick.

We next set up a loop to continuously transmit status data. In the main part of the program we set up a conditional statement. If the toggle switch is closed, the If/Then statement is satisfied and execution branches to "Highvalue", sending the word "High" across the serial lines (Pin 9). The loop is completed with the Goto Main command. If pin 6 is low, the If/Then statement does not branch to Highvalue. Instead the Lowvalue routine is executed and a "Low" data word is transmitted.

That about wraps things up for now. Next month we will continue with our programming basics by examining a simple terminal program for PC's using the PowerBasic language.

Until then, keep up the good work.

Ken Rieli

Last updated: September 07, 2006 01:03 PM

Phoenix Turbine Builders Club

FREE Open Source Forum

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