/* AUTHOR:Cagdas YILMAZ FILE: DCmotor.C DESC: Prompt user for decimal word. Returns associated analog voltage */ #include #include #include void main(void) { int Volt, Choice, PORT; int BASEADDR, PORTA, PORTB, PORTC, CNTRL; gotoxy(1,1); cprintf("Enter Base Address (decimal) e.g. 608\n"); gotoxy(1,2); scanf("%d", &BASEADDR); PORTA = BASEADDR; PORTB = BASEADDR + 1; PORTC = BASEADDR + 2; CNTRL = BASEADDR + 3; outportb(CNTRL, 128); /* configure all ports for output */ do { printf("Enter Port Choice\n"); printf("(1) Port A\n (2) Port B\n (3) Port C\n"); scanf("%d", &Choice); if(Choice < 1 || Choice > 3) { printf("Enter 1, 2 or 3\n"); }; } while (Choice < 1 || Choice > 3); switch (Choice) { case 1 : PORT = PORTA; break; case 2 : PORT = PORTB; break; case 3 : PORT = PORTC; break; }; printf("Enter 999 to quit\n"); printf("Input Decimal word (0 = -5V, 255 = +5V \n"); while(1) { scanf("%d", &Volt); if(Volt == 999) { printf("Goodbye!\n"); outportb(PORT, 0); /* quitting */ exit(0); }; outportb(PORT, Volt); }; } /* end of main */