1 / 9

Example 10 ASCII String to Binary Conversion

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

sunee
Download Presentation

Example 10 ASCII String to Binary Conversion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Example 10 ASCII String to Binary Conversion Lecture L4.3

  2. 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))))

  3. Algorithms to convert a double number to an ASCII string

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

  5. 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;

  6. 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){

  7. 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;

  8. 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); 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;

  9. 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: break; } } } }

More Related