Example 10 ASCII String to Binary Conversion

Slides:



Advertisements
Similar presentations
Numerical Recipes The Art of Scientific Computing (with some applications in computational physics)
Advertisements

Lecture 9: Character and String
Week 8 Arrays Part 2 String & Pointer
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Calculator 9S12DP256 Lab 2. \ Convert counted string at addr1 to double number ud2 \ ud1 normally zero to begin with \ addr2 points to first invalid character.
C and Assembler Subroutines: Using the LCD. Outline Basic structure of CW-created C programs for the HC12 How to incorporate assembly code How to use.
Example 11 Analog-to-Digital Converter Lecture L5.1.
C Language Programming. C has gradually replaced assembly language in many embedded applications. Data types –C has five basic data types: void, char,
LC-3 Assembly Language Programming Examples
Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.
Chapter 6 Programming in Machine Language The LC-3 Simulator
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Review: midterm #9 #include void main(void) { int c; c = getchar(); if(c>=48){ if(c
1 4-Integrating Peripherals in Embedded Systems (cont.)
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Practical Electronics & Programming
UniMAP Sem2-08/09 DKT121: Fundamental of Computer Programming1 Introduction to C – Part 2.
The miniDragon+ Board and CodeWarrior Lecture L2.1.
C Tokens Identifiers Keywords Constants Operators Special symbols.
CP104 Introduction to Programming Selection Structures_3 Lecture 11 __ 1 The Switch Statement The switch statement provides another means to select one.
Number Systems What is the Standard Base we
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
C Programming Laboratory I. Introduction to C Language /* the first program for user */ #include int a=0; int main(void) { printf(“Hello World\n”); return.
Arch1 LCD Lab Eric Freudenthal. Topics Score Demo LCD Panel Geometry Utilities to draw to the display Drawing characters Buttons Nuisance: multiple versions.
CISC105 – General Computer Science Class 9 – 07/03/2006.
Lecture 11: Chapter 2 Today’s topic –Numerical representations Reminders –Homework 3 posted, due 9/29/2014 –Homework 4 posted, due 10/6/2014 –Midterm 1.
Example 11 Analog-to-Digital Converter Lecture L5.1.
Example 12 Pulse-Width Modulation (PWM): Motors and Servos Lecture L8.1.
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
Programming Microcontrollers in C Lecture L7.1. C Data Types TypeSizeRange char1 byte-128 – 127 unsigned char1 byte0 – 255 Int2 bytes – unsigned.
1 Huffman Codes. 2 ASCII use same size encoding for all characters. Variable length codes can produce shorter messages than fixed length codes Huffman.
Lecture 2. Outline Sample programming question Sample C program Identifiers and reserve words Program comments Preprocessor directives Data types and.
The Stack Chapter 5 Lecture notes for SPARC Architecture, Assembly Language Programming and C, Richard P. Paul by Anu G. Bourgeois, Abinashi Dhungel.
UNIMAP Sem2-07/08EKT120: Computer Programming1 Week 2 – Introduction to Programming.
Examples Lecture L2.2. // Example 1a: Turn on every other segment on 7-seg display #include /* common defines and macros */ #include /* derivative.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
INTERFACING KEYBOARD WITH ATMEGA32 ELECTRONICS & COMMUNICATION TITLE.
EC310 6-week Review.
4-Integrating Peripherals in Embedded Systems (cont.)
Example 14 Real-time Interrupts
The Stack Chapter 5 Lecture notes for SPARC Architecture, Assembly Language Programming and C, Richard P. Paul by Anu G. Bourgeois.
Network Programming CSC- 341
4-Integrating Peripherals in Embedded Systems
BYTE AND STRING MANIPULATON
Example 19 Measuring Pulse Widths Using Interrupts
4-Integrating Peripherals in Embedded Systems
8051 Programming in C rhussin.
Data Type.
Example 5 Pushbutton Switches: S1 and S2
Lecture 22.
Introduction to Programming and the C Language
Example 9 Binary to ASCII String Conversion
Chapter 5 Analog Transmission
Example 6 Hex Keypad Lecture L3.2.
Example 15 Interrupt-Driven Controller
Data Type.
Example 16 Circular Queue
Example 13 The Serial Peripheral Interface (SPI)
Review of Arrays and Pointers
Example 17 SCI Receive Interrupts
Example 7 Liquid Crystal Display
Trees Addenda.
Example 18 Pulse Train Using Interrupts
Conversion Check your class notes and given examples at class.
C Programming Lecture-8 Pointers and Memory Management
Homework Finishing Chapter 2 of K&R. We will go through Chapter 3 very quickly. Not a lot is new. Questions?
Section 6 Primitive Data Types
Presentation transcript:

Example 10 ASCII String to Binary Conversion Lecture L4.3

ASCII number string to binary conversion 34671 = 3 x 104 + 4 x 103 + 6 x 102 + 7 x 10 + 1 = 1 + 10(7 + 10(6 + 10(4 + 10(3))))

Algorithms to convert a double number to an ASCII string

char* ptr; // pointer to keypad buffer char kbuf[12]; // keypad buffer ptr = kbuf; // point to keypad buffer

Example 10 // Example 10: Calculator with ASCII string to number conversion #include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { long op1, op2; // 32-bit operands char* ptr; // pointer to keypad buffer char* plus; // string pointers char* equals; char* blanks; char kbuf[12]; // keypad buffer ptr = kbuf; plus = "+ "; equals = "= "; blanks = " "; char c, a; int i;

Example 10 (cont.) // Example 10: (cont.) PLL_init(); // set system clock frequency to 24 MHz lcd_init(); // enable lcd keypad_enable(); // enable keypad set_lcd_addr(0x00); // display on 1st line i = 0; // kbuf index = 0 while(1) { c = getkey(); // read keypad a = hex2asc(c); // convert to ascii kbuf[i] = a; // and store in kbuf if(c < 10){ // if 0 - 9 data8(a); // display on LCD wait_keyup(); // wait to release key i++; // inc index } else { switch(c){

Example 10 (cont.) // Example 10: (cont.) case 0xE: // if enter (*) key op1 = number(ptr); // convert to binary set_lcd_addr(0x42); // display on 2nd line write_long_lcd(op1); set_lcd_addr(0x00); // clear 1st line type_lcd(blanks); wait_keyup(); // wait to release key i = 0; // reset kbuf index set_lcd_addr(0x00); // display on 1st line break;

Example 10 (cont.) // Example 10: (cont.) case 0xA: // if key A set_lcd_addr(0x42); // display op1 on 2nd line write_long_lcd(op1); op2 = number(ptr); // convert to binary set_lcd_addr(0x14); // display on 3rd line type_lcd(plus); write_long_lcd(op2); op1 = op1 + op2; // compute sum set_lcd_addr(0x54); // display on 4th line type_lcd(equals); set_lcd_addr(0x00); // clear 1st line type_lcd(blanks); wait_keyup(); // wait to release key i = 0; // reset kbuf index set_lcd_addr(0x00); // display on 1st line break;

Example 10 (cont.) // Example 10: (cont.) case 0xF: // if clear (#) key clear_lcd(); // clear lcd display wait_keyup(); // wait to release key i = 0; // reset kbuf index break; default: }