// Press 2nd switch first glow 1st LED, delay,2nd LED,
// delay, 5th LED, delay,6th LED
// Port description:
// Outport port : 6 pins from port D(lower bits) and 2 pin from port B(higher bits) of atmega 328p.
// Input port : 4 pins from port B(lower nibble) and 4 pins from port C (higher nibble)
void Delay();
void outport(char state);
void inport(char *state);
void glow_leds();
void setup() {
glow_leds( );
}
void Delay(){
volatile long i;
for(i=0;i<300000;i++);
}
void outport(char state){
volatile char* direcd = 0x2A;
volatile char* outd = 0x2B;
volatile char *direcb = 0x24;
volatile char *outb = 0x25;
*direcd = 0xFC;
*outd = ((state & 0x3F) << 2);
*direcb = 0xC3;
*outb = ((state & 0xC0) >> 6);
}
void inport(char *state){
volatile char* direcc = 0x27;
volatile char *inc = 0x26;
volatile char*direcb = 0x24;
volatile char *inb = 0x23;
*direcb = 0xC3;
*direcc =0xF0;
*state = (((*inc & 0x0F) << 4) | ((*inb & 0x3C)>>2));
}
void glow_leds( ){
unsigned char input_Switch;
int arr[] = {2,4,32,64};
while(1){
inport(&input_Switch);
if(input_Switch == 0x04){
for(short i=0;i<4;i++){
outport(arr[i]);
Delay();
}
outport(0x00);
Delay();
}
else{
outport(0x00);
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}