UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2011 Lab 8 Morse code Introduction Reading This lab will perform Morse code decoding and encoding using the terminal, LCD, and push buttons on the Explorer 16 board. Working implementations of both the linked list and LCD libraries will be provided along with a pushbuttons library for you. Morse code article on Wikipedia Event-driven programming handout Provided files MorseTranscoder.h This file contains the API that you will be implementing in the aptly named MorseTranscoder.c file. It will use a Morse tree to decode Morse code strings. Encoding functionality is also provided. MorseEvents.h - This file includes a single function that will check the buttons for the various Morse code characters. Lab8SupportLib.a (Lcd.h, LcdDriver.h, Timers.h, LinkedList.h, Buttons.h) These files provide helper functions that you will need to use within your code. The header files contain comments that should clarify how the code is to be used. lab8.c - This file includes main() where you will implement the bulk of this lab's functionality. Please note the macro ReceivedInput() that you should use to read input a single character at a time over the terminal. Assignment requirements Morse code library: Implement all of the functions defined in MorseEvents.h and MorseTranscode.h. o Morse code input must be decoded using a Morse tree implemented on top of a linked list (using the functions in LinkedList.h). o The library should encode all alphanumeric characters ([0-9A-Za-z]) o It should decode all alphanumeric characters, representing alphabetic characters as only their upper-case representation. main(): Your main() within lab8.c must implement the following functionality using the provided code along with your Morse code library.
o User input must be read from the terminal. Each character received should be output back to the screen along with its Morse code representation (using '.'s and '-'s). The support code for this lab does not automatically echo the characters that are typed into the terminal. Invalid input should be output to the terminal in both its character and numeric representation stating that it's an invalid character. o User input is also captured by the 4 push buttons on the Explorer 16 board: S3, S6, S5, and S4. These will correspond to a DOT, DASH, CHARACTER_SPACE, and a WORD_SPACE respectively when pressed. The user can input DOTs and DASHes via the push buttons to specify a the Morse code representation of an alphanumeric character. These are shown on the bottom line of the LCD as they're entered. Pressing the CHARACTER_SPACE button attempts decoding of the inputted DOTs and DASHes when pressed. The bottom line is cleared and the character is decoded. If it is a valid character it is appended to the end of the top line. If it is invalid a '#' is appended instead. Once the top line is full of characters, it should be shifted left to make room for next character to be displayed giving the appearance of it scrolling as new characters arrive. The WORD_SPACE button signifies the end of a word and appends a space (' ') to the end of the top line. It also clears the bottom line and ignores the previous user input if there was any. Code style: Follow the standard style formatting procedures for syntax, variable names, and comments. o Add the following to the top of every file you submit as comments: Your name The names of colleagues who you have collaborated with Submission: o Submit your Morse code library, named MorseTranscode.c and "MorseEvents.c" along with your main program, named lab8.c, via ecommons before the due date (double check that it was accepted, again BEFORE the due date). Grading This assignment again consists of 10 points: 5 points Morse code library functionality as outlined in MorseEvents.h and MorseTranscoder.h
4 points The rest of the lab functionality 1 point Code is correctly formatted with good comments and variable names You will lose points for the following: -10 points: Code doesn t compile -2 points: Compilation produces warnings -2 points: Files besides MorseTranscode.c, MorseEvents.c, and lab8.c were submitted. -2 points: Files don't contain the appropriate comments with your name (and collaborators if any) at the top of every submitted file -2 points: gotos were used Example output Morse tree Morse code is represented by a sequence of dots and dashes. Because there can only be dots and dashes for representing a single character, a binary tree can store the patterns for all the characters representable by Morse code. While there are Morse code representations for many characters in many languages, this lab focuses on only the alphanumeric characters within the ASCII character set. A Morse tree with those characters in them is shown below.
So given the tree above, decoding a Morse string involves starting at the root of the tree and branching left or right depending on what character is next in the string until all the characters have been read. The node that you end up on is the character that the Morse string represented. For example, to decode "-.." you first start at the root node. The first character in the Morse string is a dash, so you branch to the right to the T node. The next two characters are then both dots and so you branch left twice going through the N node and ending on 'D', which is the alphanumeric character represented by the Morse string '-..'. Trees from linked lists Now it would be a pain to write another data structure library for representing a binary tree just to decode a Morse string. Luckily you have already implemented a doublylinked list, a data structure that relies on nodes having two links to other nodes. As that is exactly what a binary tree requires, you can implement this binary tree on top of the linked list you implemented for earlier labs. Since the linked list implementation you already wrote wasn't designed to support a tree-like data structure, this is going to be a little tricky to do. You will need to create a series of ListItems to be the nodes in the tree. After you have these nodes properly created and pointing to the correct data (the ASCII characters they represent) the points to the previousitem and nextitem will need to be manually rearranged into the Morse tree. This is a conceptually complicated task and easy to get wrong. It will be best to think about how this will be done and write it out in pseudo-code before starting. Debugging this portion of the lab will be difficult and it will be easier to have correct pseudo-code before starting to write the actual code.
Event-driven programming This lab will rely heavily on event-driven programming. Specifically the events that are important in this lab will be those generated by the functions in Buttons.h, MorseEvents.h, and from user input from the terminal (received via the macro ReceivedInput()). The Timers.h library has been provided as a way to repeatedly call these event checkers in the background. While the event checkers are continuously called in the background via the Timers.h library, the main program loop within main() will respond to these events with the appropriate service routines. Also be sure to clear the event flags when the service routines finish or the event will be continuously triggered!