// filename Interp12.C // Linked List Interpreter // Last modified 12/12/02 by Jonathan W. Valvano // Copyright 2003 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu // You may use, edit, run or distribute this file // as long as the above copyright notice remains #include "HC12.h" #include "SCI12.H" const struct Node{ unsigned char Letter; // type this letter void (*fnctPt)(void); // to execute this command const struct Node *Next;}; typedef const struct Node NodeType; typedef NodeType * NodePtr; //*****************OutCRLF*************** // Output a CR,LF to go to a new line void OutCRLF(void){ SCI_OutChar(CR); SCI_OutChar(LF); } //******** CommandA *************** // output a simple message void CommandA(void){ OutCRLF(); SCI_OutString("Executing Command a"); } //******** CommandB *************** // output a simple message void CommandB(void){ OutCRLF(); SCI_OutString("Executing Command b"); } //******** CommandC *************** // output a simple message void CommandC(void){ OutCRLF(); SCI_OutString("Executing Command c"); } //******** Help *************** // explain how to use this system void Help(void){ OutCRLF(); SCI_OutString("a executes Command a"); OutCRLF(); SCI_OutString("b executes Command b"); OutCRLF(); SCI_OutString("c executes Command c"); } NodeType LL[4]={ // linear linked list { 'a', &CommandA, &LL[1]}, { 'b', &CommandB, &LL[2]}, { 'c', &CommandC, &LL[3]}, { '?', &Help, 0 }}; //******** InitTimer *************** // Turn off COP, enable timer, PT6 is output void InitTimer(void){ COPCTL = 0x00; // disable COP DDRT |= 0x40; // PortT bit 6 is output to LED TSCR = 0x80; // TEN(enable) } void main(void){ NodePtr pt; char string[40]; SCI_Init(13); InitTimer(); // initialize COP, Port T OutCRLF(); SCI_OutString("Interpreter example 12/12/02 -JWV"); Help(); OutCRLF(); SCI_OutString("Enter a single letter command followed by "); while(1){ PORTT ^= 0x40; // toggle LED OutCRLF(); SCI_OutString(">"); SCI_InString(string,39); pt = &LL[0]; // first node to check while(pt){ if(string[0]==pt->Letter){ pt->fnctPt(); break; } else { pt = pt->Next; if(pt==0){ SCI_OutString(" Error"); } } } } } #include "SCI12.C" extern void _start(); #pragma abs_address:0xfffe void (*reset_vector[])() = { _start }; #pragma end_abs_address