MPLAB X IDE use the XC8 Compiler
Please use Mplap for pıc18f452
In the experiment you will write a code for defined led1, led2, and led3. Run these led orderly as led2, led3, led2, led1, and all of them (at the same time led 1, 2 and 3)if button still pressed after pressed 100ms. It should run led in giving order up to give up pressing the button.I give the head of the code completely, you should complete the inside of the while loop according to pseudo-code. Write your own run led code.Hint: use if and case statements. It can give a warning to TRISB but it is not an obstacle to build code successfully.
Pseudo code for inside of while:
If button is pressed 100 ms wait
If button is still pressed
Run led 2
Run led 3
Run led 2
Run led 1
Run led 1, led 2, and led 3 at the same time
Please use if and case comment
I DO LIKE THAT BUT WRONG NOT BUILD SUCCESS
#include
#include
#define _XTAL_FREQ 8000000UL
#include
#define BTN PORTBbits.RB0
#define led1 PORTBbits.RB1
#define led2 PORTBbits.RB2
#define led3 PORTBbits.RB3
char led_state=1;
void MSDelay(unsigned int ms);
void main ()
{
TRISBbits.TRISB1=0;
TRISBbits.TRISB2=0;
TRISBbits.TRISB3=0;
TRISBbits.TRISB0=1;
while(1)
{
if( BTN == 1)
{
MSDelay (100);
if(BTN == 1)
{
led2=1;
led2=0;
led3=1;
led3=0;
led1=1;
led2=1;
led3=1;
}
}
else (BTN == 0);
{
}
}
void MSDelay(unsigned int ms)
{
unsigned int x ;
unsigned char z;
for(x=0;x for(z=0;z
}
}