Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IS BELOW #include #pragma config WDT = OFF #define _XTAL_FREQ 16000000 int i = 0; char c; void main(void) { TRISD = 0x00; TRISB

image text in transcribedimage text in transcribedimage text in transcribed

CODE IS BELOW

#include #pragma config WDT = OFF #define _XTAL_FREQ 16000000

int i = 0; char c;

void main(void) { TRISD = 0x00; TRISB = 0b11111111; ADCON1 = 0x0f; while(1) { //i = i + 1; c = PORTB; LATD = c; //__delay_ms(1000); //if ( PORTBbits.RB0 == 0 ) { } } }

USING MPLABX (C++ language), please help finish the above code. Above is the existing code as mentioned in the question. having trouble with the IF statement. PLEASE DO QUESTION 5 ONLY. I HAVE ATTACHED QUESTIONS 3 AND 4 FOR BACK CONTEXT. SOME CODE HAS BEEN GIVEN ALREADY. THE CODE I HAVE UPLOADED VIA TEXT IS MY CODE FROM QUESTION 4. THANKS

Please only attempt if you know what you are doing, anything that does not work will unfortunately get a thumbs down. Thanks for your help

#include #pragma config WDT = OFF 3. Stop the debugger so you can edit and rebuild the program Alter your program as follows - Declare a character variable called c without an initial value Comment out // the increment line Change the statement to assign the value c into LATD Use MPLABX menus - Debug - Debug project, it will run at high speed (what do you see on the LEDs on PICsimlab?) #define _XTAL_FREQ 16000000 int i=0; char c: void main(void) { As c was not initialised, its value will be whatever value is in the memory at that location. It might be zero, it might not. TRISD = 0x00; while(1) 4. Stop the debugger so you can edit and rebuild the program (No code guide for this work it out yourself) Alter your program as follows - In the initialisation section (inside main but outside the loop) Initialise the TRISB register for port B as inputs (see datasheet) Also include the line ADCON1 = OxOF; (see note # below) { Ili=i+1; LATD=C; _delay_ms(1000); } Then within the loop - before the LATD = c; (already there) Read the value of PORTB and assign it to variable cle. C = PORTB; (Note - we read inputs from the PORT but write outputs to the LATch) Use MPLABX menus Debug - Debug project, it will run at high speed Click on any of the buttons on the PICsimLab labelled RBO, RB1, RB2, RB3 (what do you see on the LEDs on PICsimlab? Is there a delay in LED changes? Why? How can the program be made to respond faster) - 1 - ] X PICSimLab - PICGenios - PIC18F4520 File Board Microcontroller Modules Tools Help CIK(MHz) 16 RS485 Spd: 1.00x Debug SERIAL LCD hd44780 16x2 ee COOLER 888 HEATER RELAY 1 BUZZER LM35 RB2/INT2 093933 Heater TE RB1/INT1 BE RBO/INT DISP1 DISP2 DISP3 DISP4 RELAY 2 Cooler PICSimLab 1 2 3 RB3 RTC 2:8:::::: 4 5 O 6 RB4 EEPROM Temp: 27.50C 7 8 9 RB5 LED1/PORTO LEDI/PORTB DO BO D1 B1 D2 B2 P1-ANO P2-AN1 D3 B3 D4 el B4 D5 B5 em D6 B6 LOAD/RUN D7 B7 PIC1624526 O 0 # RAS OOOO 00 RESET ! PS2 as -- USB ICSP PORTD PORTC PORTE PORTAVE une a 5. Create a NEW project for a PIC18F4520 processor Copy lines of code from your previous program and paste them into a new main for this project Alter your program so it achieves the following - Set PORTB as all inputs Set PORTD as all outputs Use an IF test to test the value of PORTB bit o use if ( PORTBbits.RBO == 0 ) if it is equal to zero then the button is pressed When the button is pressed toggle (flip) the value in LATD between 0x00 and OxFF Test on PICSimLab

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

Review the basic concepts of recruitment and selection

Answered: 1 week ago

Question

2 What are the implications for logistics strategy?

Answered: 1 week ago