zoukankan      html  css  js  c++  java
  • Embedded之Introduction

    1  Embedded system

      An embedded system is a combination of computer hardware and software, and perhaps additional mechanical or other parts, designed to perform a specific function. (E.g. microwave oven)

    2  Infinite loop

      One of the most fundamental differences between programs developed for embedded systems and those written for other computer platforms is that the embedded programs almost always end with an infinite loop.

      The infinite loop is necessary because the embedded software's job is never done. It is intended to be run until either the world comes to an end or the board is reset, whichever happens first.

    3  Blinking LED

     1 /********************************************************************** 
     2  * 
     3  * Function:    main() 
     4  * 
     5  * Description: Blink the green LED once a second. 
     6  *  
     7  * Notes:       This outer loop is hardware-independent.  However,  
     8  *              it depends on two hardware-dependent functions. 
     9  * 
    10  * Returns:     This routine contains an infinite loop. 
    11  * 
    12  **********************************************************************/ 
    13 void main(void) 
    14 { 
    15     while (1) 
    16     { 
    17         toggleLed(LED_GREEN);      /* Change the state of the LED.    */ 
    18         delay(500);                /* Pause for 500 milliseconds.     */ 
    19     } 
    20 }

      3.1  toggleLed

     1 /********************************************************************** 
     2  * 
     3  * Function:    toggleLed() 
     4  * 
     5  * Description: Toggle the state of one or both LEDs. 
     6  * 
     7  * Notes:       This function is specific to Arcom's Target188EB board. 
     8  * 
     9  * Returns:     None defined. 
    10  * 
    11  **********************************************************************/ 
    12  
    13 #define LED_GREEN   0x40        /* The green LED is controlled by bit 6.*/ 
    14 #define P2LTCH      0xFF5E      /* The offset of the P2LTCH register. */ 
    15 
    16 void toggleLed(unsigned char ledMask) 
    17 { 
    18     asm { 
    19         mov dx, P2LTCH          /* Load the address of the register.  */ 
    20         in  al, dx              /* Read the contents of the register. */ 
    21  
    22         mov ah, ledMask         /* Move the ledMask into a register.  */ 
    23         xor al, ah              /* Toggle the requested bits.         */ 
    24  
    25         out dx, al              /* Write the new register contents.   */ 
    26     }; 
    27  
    28 }   /* toggleLed() */ 

      3.2  delay

     1 /********************************************************************** 
     2  * 
     3  * Function:    delay() 
     4  * 
     5  * Description: Busy-wait for the requested number of milliseconds. 
     6  * 
     7  * Notes:       The number of decrement-and-test cycles per millisecond 
     8  *              was determined through trial and error.  This value is 
     9  *              dependent upon the processor type and speed. 
    10  * 
    11  * Returns:     None defined. 
    12  * 
    13  **********************************************************************/ 
    14  
    15 void delay(unsigned int nMilliseconds) 
    16 { 
    17     #define CYCLES_PER_MS 260 /* Number of decrement-and-test cycles. */ 
    18  
    19     unsigned long nCycles = nMilliseconds * CYCLES_PER_MS; 
    20  
    21     while (nCycles--); 
    22  
    23 }   /* delay() */ 
  • 相关阅读:
    URL解析模式(伪静态)
    PHP各环境下的伪静态配置
    亚马逊-购书(电子)
    前端路由-JS实现
    SpringBoot 2.3.0.RELEASE版本后自定义404页面,SpringBoot 404错误兼容Ajax请求
    不设置DIV宽度水平居中,div不设置宽度居中
    js 保留两位小数,Js四舍五入,JavaScript Math四舍五入
    Laravel 自定义公共函数的引入
    EF Core3.1 CodeFirst动态自动添加表和字段的描述信息
    Android 高德地图API INVALID_USER_SCODE 错误
  • 原文地址:https://www.cnblogs.com/mengdie/p/4430207.html
Copyright © 2011-2022 走看看