Recent Changes - Search:

Introduction to Microcontroller Programming

About PICmicro Chips

Clocking Your PICmicro Devices

E-Blocks

Flowcode Step By Step

PICmicro Projects

Labs

Lab 5 - Loop

<^< 4. Calculations | Course Index | 6. Input >^>

1. Introduction

Repeating a certain set of instructions, for an exact amount of times, while or until a condition is met is one of the most powerful programming operations known. You will experience this as you do the lab exercises below. The programs get a lot more interesting but also more complex to understand from now on. Use the slow simulation or 'Step Over' function in the Flowcode simulator to debug your programs from now on.

2. Setting up the equipment
3. Hardware settings
EB006 OptionsSettingJumper settings (EB006)Jumper settings (HP488)
Power supplyExternal, 14VJ29: PSUJ29: PSU
PICmicro device16F1937  
Programming methodUSBJ12,13,14: USBJ20: USB
Clocking methodXTALSW2: XTALS2: XTAL
R/C clock speed   
Xtal frequency19 660 800 Hz  
LVP Jumper selectionI/O PortJ11,16,17: I/O PortJ15,16,18: I/O
Port A E-block   
Port B E-blockLED board  
Port C E-block   
Port D E-block   
Port E E-block   
4. Flowcode and download settings
Build > Project Options... > General Options Build > Project Options... > Configure
OptionsSetting
Clock speed19 660 800 Hz
Simulation speed10
OptionsSetting
Device16F1937
RC/XTXTAL
Watchdog timerOff
5. Software learning objectives

Output, binary code training, Infinite loop, conditional loop, compiling a program to the PIC, clocking the PIC, PIC microcontroller basics.

6. Hardware learning objectives

LED’s, logic output levels, Multiprogrammer basics, microcontroller speed of execution.

7. Instructions

Construct the system shown from E-blocks.

In the course navigate to the ‘Flowcode step-by-step’ and review the section on Basic Loops (Step 4), LCD Display (Step 5) and Goto Connection Point (Step 6). In the course you will also find the sections on Clocking your PIC, and about PIC microcontroller basics useful. The descriptions of the Multiprogrammer board and the LED board are in the E-blocks section.

In lab L5-E7-G, you will need to know about Array variables. You will find info on this in the help-file of Flowcode 4 and in section String and Memory (Step 11).

Make use of the Help-function in Flowcode to get the info you need.

During these exercises you are going to send different 8-bit codes to Port B of your microcontroller . The PIC is very fast in Xtal mode. Be aware of this and use correct delays where needed to slow it down to ‘human’-speed.

8. Labs
Letter Meaning
L Lab x
B Basic complexity
I Intermediate complexity
E Expert complexity
L5-B1
Make an 8-bit binary counter that counts from 0-255, then repeats 0-255 and so on. Show the counter value on the LEDs of Port B. Use a loop-icon to do this.
L5-B2
Make an 8-bit binary counter that counts from 0-255 then back down from 255 to 0. These 2 loops have to be repeated for ever. Show all of the steps on the LEDs of Port B. Download the program to the PIC and demonstrate it at full speed.
L5-B3
Make a simple running light that runs from PB0 to PB7 and starts back from PB0 and so on. Use the 'multiply by 2' method to do this. Show all of the steps on the LEDs of Port B.
L5-B4
Make a simple running light that runs from PB0 to PB7 and starts back from PB0 and so on. Use the 'shift right' method to do this. Show all of the steps on the LEDs of Port B.
L5-I5
Change the program of the running light so that the light runs back when it reaches PB7. Use the 'multiply by 2' method. The sequence should now be PB0-PB7 and back from PB7-PB0 and so on. (Remember KITT From Knight Rider or the Cylon robots from Battlestar Galactica?).
L5-I6
Change the program of the running light so that the light runs back when it reaches PB7. Use the 'shift right' method to do this. The sequence should now be PB0-PB7 and back from PB7-PB0 and so on.
L5-I7
Change the program of [L5-I6] so that this is a 16-bit running light (LEDs at both Port C and D). Use only loops, no decisions. Save this program as [L5-I7-G], download it to the PIC
L5-E8
Define an Array of 4 variables called Matrix[x]. Fill the 4 variables of this Array with these values: Matrix[0]=129; Matrix[1]=66; Matrix[2]=36; Matrix[3]=24. Use 2 'do While loops' to create this infinite sequence: Matrix[0]-Matrix[1]-Matrix[2]-Matrix[3]-Matrix[2]-Matrix[1]-Matrix[0]-Matrix[1]-..... . Show this on the LEDs of Port B. You can only refer to these separate Matrix-variables as Matrix[x] where x is a separate variable that points to the variable that is needed at that moment. Save this program as [L5-E8-G], download it to the PIC.

<^< 4. Calculations | Course index | 6. Input >^>

Print - Search - Login

Page last modified on May 14, 2013, at 01:54 PM