Circuit:
#include<p18f452.h>
#pragma config WDT=OFF
#define a 100
void delay(unsigned char);
void main(){
TRISB=0x00;
TRISD=0x00;
while(1){
if(PORTDbits.RD0==0){
PORTB = 0b00000001;
delay(a);
PORTB = 0b00000100;
delay(a);
PORTB = 0b00000010;
delay(a);
PORTB = 0b00001000;
delay(a);
}
else{
PORTB = 0b00001000;
delay(a);
PORTB = 0b00000010;
delay(a);
PORTB = 0b00000100;
delay(a);
PORTB = 0b00000001;
delay(a);
}
}
}
void delay(unsigned char time){
unsigned char i,j;
for(i=0;i<165;i++)
for(j=0;j<time;j++);
}
Program:
#include<p18f452.h>
#pragma config WDT=OFF
#define a 100
void delay(unsigned char);
void main(){
TRISB=0x00;
TRISD=0x00;
while(1){
if(PORTDbits.RD0==0){
PORTB = 0b00000001;
delay(a);
PORTB = 0b00000100;
delay(a);
PORTB = 0b00000010;
delay(a);
PORTB = 0b00001000;
delay(a);
}
else{
PORTB = 0b00001000;
delay(a);
PORTB = 0b00000010;
delay(a);
PORTB = 0b00000100;
delay(a);
PORTB = 0b00000001;
delay(a);
}
}
}
void delay(unsigned char time){
unsigned char i,j;
for(i=0;i<165;i++)
for(j=0;j<time;j++);
}
Comments
Post a Comment