Generating Square Waveforms

Objective: In this lab we will use PIC18F45K20 microcontroller.

Other useful documents:

Pre-Lab:

Using the data sheet for PIC18F45K20 microcontroller, answer the following questions:
    1. What type of packaging the chip has?
    2. How many pins does the chip have?
    3. What is the size of the SRAM on the chip?
    4. How much EEPROM does this chip have?
    5. How may IO ports does the chip have?
    6. How many FSR registers does this chip have?
    7. How many bits are used to indicate the stack location?
    8. How wide is a stack?
    9. What is the address of the STKPTR register (see the data sheet page 76)?
    10. What are the TABLE POINTER OPERATIONS? Hint: There are 8 of them.
    11. What is the register address of POSTINC0?
    12. What is the register address of INDF2?
    13. Assuming the return address ontopof the stack is 0x001A34. What would b the content of the following registers: TOSL/H/U?
    14. Which bit in the STKPTR register is used for STKFUL? What is its purpose?
    15. What is the fundamental difference between a CALL and GOTO?

Procedure:

Homework:

PART I: Now that you are familiar with programming your chip, modify the assembly code to generate a 5KHz signal. Load the modified program into your chip. Your program must be such that when a Switch is pressed, the siganl STOPS. Use PORT D.

    1. Connect one output port to a scope and make sure the 5KHz signal is in fact there.
    2. Send the signal to a speaker. What do you hear?
    3. If you connect the signal to an LED do you see the LED blinking?
    4. Save this project as a new project: 5KHzGen. NOTE: Your delay function must be MACRO or SUBROUTINE. See code listing in Example 2.

PART II: Modify the assembly code to generate a binary FSK modulation. In this type of modulation we use two discrete frequencies (f1 & f2) to represent binary (0s and 1s). Assume your discrete frequencies are f1=4.8 KHz and f2=5.2 KHz square waveforms.

    1. Your modulated signal should represent 101010....; that is you must generate a signal with alternating period between T1 and T2, where T1 = 1/f1.
    2. Send the signal to a speaker. What do you hear? Save this project as a new project: BFSK. IMPORTANT: You must use subroutines or assembly macros to generate BFSK.

PART III: Design a binary counter that counts from 0-32 and it displayes the number on your LEDs. You should have about 1 second of delay between each display (count). Note that in this case you need several LEDs!

EXTRA CREDIT (10 points): Create your own LED blinking pattern. Here is one blinking example. Start thinking about your project....You just have to demonstrate!

Submit the following:

Code Example: Note that the second example is generating a DELAY using CALL function:

Example 1 Example 2