Вы находитесь на странице: 1из 12

LAB 1: COMMAND LED ON/OFF (SENDING OUTPUT SIGNAL)

PART 1: TURN ON Test LED (Green LED)

We can use CoreChart software to program the PIC and make the test LED turn on and off.
Test LED is connected to Port B7 via a current limiting resistor.

39 R

390Ω

Pin 11= Port B Bit 5

Chip Diagram

B7 B6 B5 B4 B3 B2 B1 B0
0 0 0 0 0 0 0 0 Port B
Register

390Ω

Notes: Maximum output current sink/source by any I/O pin is 25 mA.


Maximum current sink/source by PORTA is 100 mA.
Maximum current sink/source by PORTB is 100 mA.
Exercise:

1. Open Astana at desktop and copy folder name ‘Codes’.

2. Go to My Computer> Program Files> CoreChart. Paste folder ‘Codes’ in CoreChart


folder.

3. Open CoreChart.

4. Choose File> Codes > Open template_819intclk.bst.

5. Save as Lab1.

Three icons will appear at the screen. Below are the icons and their functions:

Beginning of program.

End of program.
Setup Subroutine. The routine is to configure PIC16F819
to use its internal clock (8 MHz).

Double click on the “Setup” subroutine icon in the Main


Program to display the instruction.

The “Setup” subroutine performed two important tasks before the program is run:

1) The microcontroller internal clock is set to run at 8MHz with these instructions:

2) The “DigitalPort” subroutine sets all PORTA pins from the default “analogue
ports” to “digital ports” with these instructions:
6. In this exercise, we will use Set/Reset icon to turn on the yellow LED.

7. Click on Set/Reset icon.

Set/Reset icon is used to write either 1 or


0 on a particular memory register.

8. Assign Set PORTB Bit7 ON as shown and place it after Icon 2 by clicking on the
little black arrow under Icon 2.
In this part, PORTB memory register become:

B7 B6 B5 B4 B3 B2 B1 B0
1 0 0 0 0 0 0 0 Port B
Register

390Ω

Notes: We have assign Set Bit 7 is ON which means Bit 7 is ONE thus LED is ON.

9. Double click at Start icon, assign PIN 13 (RB7) as output pin (arrow pointing out
from IC).
If we have tick the statement, it means that we assign the program to be run
after we press the Push Button first. If we un-tick the statement, program will
be automatically run when we ON the power switch without need to wait for
press the Push Button.

10. Before load the program, we need to select programmer first.

Step1: Click on “Options” and then click “Hardware Settings”. “Hardware


Options” screen will appears. In the “Programmer” drop menu select
“USB Programmer” and then click “OK”. Leave the three “tick” boxes
“un-ticked”.

Step 2: Ensure that the USBP Programmer is connected to a USB socket on


the computer. Then connect the ribbon cable from the USBP
Programmer to the eLab16m controller. Finally connect the battery
pack to the eLab16m and turn on the power switch.
USB Programmer

eLab16m

Ribbon cable

USB Cable

11. Load the program by click on “Tools” drop menu and then click “Send to Chip”. The
step can also be done with the F9 function key.

When the program is successful download to the chip, a GREEN status bar will appear.
If it RED, check that all the cables are connected correctly and power on the eLab16m is
turned on.
12. Press the push button and LED will turn on.

PART 2: TURN OFF YELLOW LED

1. Open Lab1.
2. Change Set PORTB Bit7 ON to Set PORTB Bit7 OFF.
3. Load the program.
4. We will see the LED is off.
Now, Port B memory register become:
B7 B6 B5 B4 B3 B2 B1 B0
0 0 0 0 0 0 0 0 Port B
Register

390Ω

Notes: We have assign Set Bit 7 is OFF which means Bit 7 is ZERO, thus LED is OFF.

PART 3: TURN ON/OFF YELLOW LED

1. Open Lab1.

2. Use Set/Reset Icon to flash the yellow LED. Make it on, off, on, off.

Port B Bit 7 is set ON and


OFF to make the Yellow LED
flashing.
3. Load the program.

4. Switch on the switch button. Can you see the LED flashing?

Notes: The execution from one instruction to another instruction is at high speed
which is about 0.5µs. Thus, we cannot see the LED flashing. We need to include
delay program in order to see the LED flashing.
Refer Appendix.

PART 4: DELAY SUBROUTINE

1. Open Lab1.

2. Use delay subroutine for the LED flashing to be visible.

3. Click on “X=Y” icon (also called the “Assignment” icon).


Select “W” and type in 255 as shown in figure. Maximum value for W is 255.
If we want to make the length of the delay longer, add another delay subroutine in the
program.

4. Insert the assignment icon after Icon 3.

Assign W
Until now, your program
should look like this.

4. To get delay subroutine, click on the subroutine icon at Icons box. Subroutines box as
below will appear and click “OK”.

5. Insert “Delay” subroutine after Icon 4 “Assignment” icon.

6. Your program should look like this.

Select W=255
.
Delay subroutine.
7. Double click on the subroutine “DELAY” to open and view the coding of the
subroutine.

8. Return to Main Program by double click on Icon 8 “Return From Subroutine”.

Delay Subroutine

9. Load the program.


10. We will see the yellow LED will continue to flash after press the push button switch.

Вам также может понравиться