Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Microcontroller Programming – Lab I/O Count Microcontroller Programming – Lab I/O Count Name: _________________________________ Date: __________________________ Objective: Control the I/O ports of the...

1 answer below »
Microcontroller Programming – Lab I/O Count
Microcontroller Programming – Lab I/O Count
Name: _________________________________    Date: __________________________
Objective:
Control the I/O ports of the PIC18F45K20 microcontroller to perform a binary count function from 5 to 250. Write code that will count up from 5 to 250, using eight LEDs connected to PORT D, to display the binary count at each stage of the count (i.e XXXXXXXXXX, XXXXXXXXXX, XXXXXXXXXX, etc). The count should be such that it is slow enough to be viewed comfortably.
Equipment:
· PICkit 4 Debug Express programme
Debugger (Book Store) (QTY = 1)
· LED A
ay
Registers required:
· OSCCON                     
· PORTD     
NOTE: How the registers are used is to be determined by the programmer. Refer to the PIC18F45K20 specification document for further details.
Procedure (Software):
1. Create a new project with MPLABS using CountLab.c skeleton code. Name the project CountLab and save to your C:\\ Drive. This skeleton code has to be used to receive credit for the lab.
a. The CountLab.c File is located in D2L – Hardware (PIC) Output.
. Compile the code to ensure it is functioning properly before making any changes. Save the project.
2. On a
eadboard, construct the circuit shown in Figure 1 below. The diagram shows the connections between the PIC Device and the PICKit4 Programme
Debugge
Figure 1 – PICKit 3/4 Wiring Diagram
3. Once constructed, wire the LED Bar Graph to PORTD of the PIC as shown in Figure 2. You are now ready to start Developing your code to program/control the PIC.
Figure 2 - LED Bar Graph Wiring
4. Add a comment block to the top of the source code area describing what the program does and what ports are being used to accomplish it (/*..*/ or
).
5. In the Function Init(), add the code required to set up PORT D to be an output and initialize PORT D to be all 0s (See comments in the code).
6. In main(), add the required code to make the LEDs count at a rate that is visible to the human eye.
a. Add delays (Use a for loop nested in a for loop to achieve the required delays) in main() to slow the LED count down.
i. Set the delays such that the last ten counts XXXXXXXXXXcount at one quarter the rate of the count from XXXXXXXXXXThe count rate from XXXXXXXXXXshould be approximately 2 Hz or every half second.
. For each iteration of the while(1) loop, the value of PORT D will have to be incremented by 1 (Count up).
c. When a count of greater than 250 is achieved reset the PORT D output to 5 to restart the count.
NOTE: use the comments embedded in the code to help determine what needs to be done.
7. Use the MPLAB debugger functions to verify the functionality of your code as you develop it by opening the watch window and observing the PORT D output to see if it is incrementing by one each time through the loop. Use
eakpoints as required.
Note: When stepping through the code it is a good idea to comment out the for-loops as they will interfere with the debugger.
8. Once the coding is complete, comment the code to ensure that someone new looking at the code would easily be able to determine what was done to accomplish the task. Place description header comments at the top of the main() and Init() functions describing what they are doing. Comment each line of code that isn’t immediately obvious as to its function.
NOTE: Remember to use ‘;’ at the end of each line of code and to use {} to set the bounds of each of your functions and loops. Comment each line of code to explain what is being accomplished (
… or /*….*/)
Procedure (Hardware):
1. Connect the USB cable to one of the USB Ports on your computer. There should be two available to you on the side of your monitor and two on the front of the computer.
2. Connect the PICKit 4 Programmer module to the other end of the USB Cable (micro USB).
3. Connect the PICkit 4 programmer module to your demo board Ensure the a
ow on the programmer is lined up with pin 1 on the demo board.
4. Compile the code to ensure there are no e
ors before making any changes.
5. Modify the code in accordance with the provided instructions above?
6. Once the LAB is working, step through and review the code to ensure you understand what is happening. Demonstrate the working code to your instructor and then answer the questions on the following sheet.
1. In your Lab, what is the purpose of the For-Loops? What was required to make the LEDs flash at a higher or slower rate?
2. What changes have to be made to the code so the count starts at 100 and stops at 200?
3. In your code, how did you ensure that PORTD was set to operate as an output? How could you have changed it to an input?
4. In your code, What arguments does the Init() function take in order to execute and what is it’s return type?
5. In the skeleton code, OSCCON was set to 0x7E. Explain what this means with regards to the operation of the program?
    
    
    
    NSCC ELCI HAZARD ASSESSMENT
    
    
    EETD 4001 Microcontroller Programming
    
    
    
    
    
    
    
    
    
    PLEASE PRINT CLEARLY
     
     
     
     
     
     
     
     
     
    Lab #:
    4715/4717
    Date of Assessment:
     
    Lab Name:
    
    Faculty/Supr:
    Troy Conrad
    
    
    
    
    
    
    
    
    
    Task Hazards
    Priority Ranking
    Hazard Control(s)
    Person Responsible
    Student Initials
    Computer Station Ergonomics
    4C
    Review SWP for Computer Station Ergonomics
    Student
     
    Working Near Electricity
    2D
    Review SWP for Electricity, working with or near electricity
    Student
     
    Housekeeping
    4B
    Maintain a clean work area. Review SWP for Housekeeping
    Student
     
    Cutters (Pliers and wire cutters)
    3C
    Proper use of pliers and cutters. Review SWP
    Student
     
    Metering (33210A Function Generator)
    4D
    Review SWP for 33210A Function Generator)
    Student
     
    Metering (DMM U3401A, U3402A)
    4C
    Review SWP for DMM U3401A, U3402A
    Student
     
    Metering (DSO1012A Oscilloscope)
    4C
    Review SWP forDSO1012A Oscilloscope
    Student
     
     
     
     
     
     
     
     
     
     
     
    Other Considerations/Comments:
    Always follow General Shop Rules listed on Green Safety Board. If you're unsure? Ask your faculty or
    Shop Assistant before proceeding.
     
    Priority Ranking Legend
    Risk
    Probability
    1
    Catastrophic
    May cause death, life threatening injury, or school shut down.
    A
    Likely to occur immediately or within a short period of time when exposed to the hazard.
    2
    Critical
    May cause severe injury or illness or major property damage.
    B
    Probably will occur in time.
    3
    Marginal
    May cause minor injury or illness, lost time or minor property damage.
    C
    Possible to occur in time.
    4
    Negligible
    Probably would not effect personnel safety.
    D
    Unlikely to occur.
Signature:
EETD 4001    Page 5

**********************************************************
*************Student - Add Program Description Here*******
**********************************************************
#include Configuration bits found in PIC18F45K20
Sets the oscillator to internal with no clock I/O on RA6 and RA7
Set s the Watch Dog Timer to Off
Sets Low Voltage Programming to Off
Function Prototypes
void Init();    
Global declaration of the Init() function.
**********************************************************
Function : main()
****Student to place comment describing the function of main()****
**********************************************************
int main(void)
{
                                    
Define i and j as chars for the For Loop delays required in main
    Init();                                
call the init()function so the PIC18F45K20 is configured to operate as required
                                    
Initialize Port D to all zeros
    while(1)                            
Infinite loop to cause the LEDs to flash continuously.
    {
                                    
outer delay loop
                                    
Inner Loop
                                    
Increment port D (count up)
                                    
(if ())Check for full count on PORTD. 0b XXXXXXXXXX = 250 decimal
        
                                    
On full count, reset PORTD to 5
                    
    }
}
**********************************************************
Function: Init()
****Student to add comments describing what Init() is doing****
**********************************************************
void Init(void)
{
    OSCCON = 0x7E;            
This chooses the internal oscillator frequency
                            
Sets all pins on PORTD to output
                            
Initializes PORTD outputs to 0x00 (0b XXXXXXXXXX).
}

*
* File: flash.c
* Author: w0257311
*
* Created on October 18, 2019, 8:41 AM
*
#pragma config FOSC = INTIO67
Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
#pragma config WDTEN = OFF
Watchdog Timer Enable bit (WDT is controlled by SWDTEN bit of the WDTCON register)
#pragma config LVP = OFF
Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#include void Init();
*This program will flash the LEDs at a 1 second rate between two values
Delays will be created using nested for loops and bitwise compliment
will be accomplised using the tild operator*
void main()
{
int i,j;
Iterator variables
Init();
while(1)
{
XXXXXXXXXXfor(i=0;i<255;i++)
Create a .75 sec delay using nested loops
XXXXXXXXXXfor(j=0;j<255;j++);
XXXXXXXXXXPORTD = ~PORTD;
Use bitwise compliment to toggle PORTD bits
}
}
* Init() set up a 16MHz oscillator and sets pPORTD to output functionality
PORTD is initialized to 0xF0;*
void Init()
{
OSCCON = 0x7E;
Set internal osc to XXXXXXXXXX
TRISD = 0x00;
Set PORTD to output
PORTD = 0xF0;
Initialize PORTD outputs to zero
}


PIC18F2XK20/4XK20 Data Sheet
 2010 Microchip Technology Inc. DS41303G
PIC18F23K20/24K20/25K20/26K20
43K20/44K20/45K20/46K20
Data Sheet
28/40/44-Pin Flash Microcontrollers
with nanoWatt XLP Technology
Note the following details of the code protection feature on Microchip devices:
• Microchip products meet the specification contained in their particular Microchip Data Sheet.
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to
each the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
Answered 2 days After Nov 04, 2021

Solution

Sathishkumar answered on Nov 05 2021
132 Votes
Microcontroller Programming – Lab I/O Count
Microcontroller Programming – Lab I/O Count
1. In your Lab, what is the purpose of the For-Loops? What was required to make the LEDs flash at a higher or slower rate?
For Loop is used for delay,
Integer inside for loop is low for LED flash faste
High for...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here