| CODE |
/* This code is uses the RS-232 to display a simple text menu, take input from the serial port , turns on the LED you selected from the menu, prints the menu again and tell you what your input was and waits for another slection Thanks to Bob over at http://www.z8micro.com for stream lining my code Thanks to Deborah over at http://groups.yahoo.com/group/z8encore/ for the memory model tip (it has to be set to large instead of small) Thanks to Ed at Zilog for saying the same thing as Deborah */ #include <ez8.h> //Standard EZ8 library - nothing fancy here #include <stdio.h> //Standard IO library #include <sio.h> //Non standard library #include <string.h> //Library for string functions (strcpy()) //prototypes void init_led_gpio(void); //Init the LED ports (PORT A) prototype function void turn_off_led(void); //Prototype function to turn off all the LEDS (PORT A) //global variables char ss[25]; //string for selection output on menu int mm = 4; //main menu selection choice - (Off at the start) void init_led_gpio(void) { PAADDR = 0x01; // Port A Data Dir = output: updated PACTL = 0x00; // Port A Out Ctrl = push-pull PAOUT = 0X00; // Port A OUTPUT: updated } // Turns off ALL LED's void turn_off_led(void) { PAOUT |= 0x07; // Turn off all three leds } //start void main() { init_led_gpio(); //Init PORT A init_uart(_UART0, 18432000, 57600); //Init the RS-232 with a 18.432 Mhz crystal for 57.6 K turn_off_led(); //Turn off LEDs while(1) //While 1 (or TRUE) is an infinate while loop { switch(mm) //Being switch statement based on the input from getch() { case '1': //if mm equals 1 strcpy(ss, "Red"); //Copy string "Red" to string ss turn_off_led(); //Turn off LEDs PAOUT &= 0xFE; //Turn on red LED break; //break out of switch condition case '2': //if mm equals 2 strcpy(ss, "Yellow"); //Copy string "Yellow" to string ss turn_off_led(); //Turn off LEDs PAOUT &= 0xFD; //Turn on yellow LED break; //break out of switch condition case '3': //if mm equals 3 strcpy(ss, "Green"); //Copy string "Green" to string ss turn_off_led(); //Turn off LEDs PAOUT &= 0xFB; //Turn on green LED break; //break out of switch condition case '4': //if mm equals 4 (On boot up, mm equals 4) strcpy(ss, "OFF"); //Copy string "OFF" to string ss turn_off_led(); //Turn off LEDs break; //break out of switch condition default: strcpy(ss, "Error - Invalid value"); //Copy sting "Error - Invalid Value" to ss, do not change PORT A Data } printf("[1] Red\n"); //Print menu choice 1 to serial port printf("[2] Yellow\n"); //Print menu choice 2 to serial port printf("[3] Green\n"); //Print menu choice 3 to serial port printf("[4] Off\n"); //Print menu choice 4 to serial port printf("Status: %s\n", ss); //Print program/LED status printf("Select: "); //Print prompt mm = getch(); //get one character and put it into interger variable mm } } |