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 »
I need you to write the code for working this debugger as per intructions in word document



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. 00000000, 00000001, 00000010, etc). The count should be such that it is slow enough to be viewed comfortably. Equipment: · PICkit 4 Debug Express programmer/Debugger (Book Store) (QTY = 1) · LED Array 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. b. Compile the code to ensure it is functioning properly before making any changes. Save the project. 2. On a breadboard, construct the circuit shown in Figure 1 below. The diagram shows the connections between the PIC Device and the PICKit4 Programmer/Debugger 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 (240-250) count at one quarter the rate of the count from 5-240. The count rate from 240-250 should be approximately 2 Hz or every half second. b. 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 breakpoints 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 arrow on the programmer is lined up with pin 1 on the demo board. 4. Compile the code to ensure there are no errors 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 4001Page 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. 0b11111010 = 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 (0b00000000). } /* * 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) { for(i=0;i<255;i++) create="" a="" .75="" sec="" delay="" using="" nested="" loops="" for(j=""><255;j++); portd = ~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 16000000 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 breach 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 portd="~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="" 16000000="" 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="" breach="" 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="">
Answered 2 days AfterNov 04, 2021

Answer To: Microcontroller Programming – Lab I/O Count Microcontroller Programming – Lab I/O Count Name:...

Sathishkumar answered on Nov 05 2021
131 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 faster
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