/* The program decribes the concept of multipexing in Embedded System, meaning that only 1 pin
is used to control multiple devices (here A0 (PORTF pin 0) used to control two pins) */
void time_delay(volatile long);
int main(void)
{
//Setup Diretion register
volatile char *dir;
// set the direction of PORTF to OUTPUT
dir = (char *) 0x30; // Address of DDRF
*dir = 0xFF; // makes all pins of PORTF as OUTPUT
// set the direction of PORTK to OUTPUT
dir = (char *) 0x107; // Address of DDRK
*dir = 0xFF; // Makes all pins of PORTK as OUTPUT
while (1)
{
// Setup OUTPUT Register
volatile char *out;
// setup output register of PORTK
out = (char *) 0x108; // Address of PORTK OUTPUT Register
*out = 0x02;
// Setup output register of PORTF
out = (char *) 0x31; // Address of PORTF OUTPUT Register
*out = 0x01;
time_delay(1000000);
// setup output register of PORTK
out = (char *) 0x108; // Address of PORTK OUTPUT Register
*out = 0x01;
// Setup output register of PORTF
out = (char *) 0x31; // Address of PORTF OUTPUT Register
*out = 0x01;
time_delay(1000000);
}
}
void time_delay(volatile long del)
{
for (volatile long i = 0; i < del; i++);
}