Question
1. a PIC18F has 8 LEDs connected to Port A and 8 switches connected to Port B, write a C program for the following task
1. a PIC18F has 8 LEDs connected to Port A and 8 switches connected to Port B, write a C
program for the following task : The code will continually read the value of the switches, if the
value is zero it turn off all LEDs. If the value is between 0 and 5, turn on/off the first half of the
LEDs 5 times then switch them off. If the value is larger than 5 turn on/off all LEDs 10 times
then keep them on.
Hints: the PIC will switch on/off the LEDs very fast so you need a delay. You can use the
PIC18F predefine function __delay_ms(100); to introduce 100ms delay.
2. Write a C code that read 5 values (no value higher than 20) from port A (there is 8 switches
connected to Port A ) and store them in an array. When user finish input each value, he/she push
a button connected to pin 0 in port B. Once all the 5 values are stored in the array, an LED
connected to pin 7 in Port B will turn on. The PIC18F then computes the average if the average
is less or equal to 10 then toggle both LEDs connected to Port B pin 3 and pin 4 with low
frequency (they should switch on/off slowly). If the average is higher than 10 then toggle both
LEDs connected to Port B pin 3 and pin 4 with high frequency (they should switch on/off fast)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started