FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    [Single-chip experiment] button experiment (1, two, 3)

     

    Button experiment: Purpose: Control other components by pressing the button experiment one K1 ~ K4 controlled LED shift OBJECTIVE: To press the independent buttons K1 to K4, the LED shift display connected to the P0 and P2 ports can be controlled up and down, respectively. # include // Use the library function of the chip # include #define uchar unsigned char #define uint unsigned int SBIT LED1 = P0 ^ 0; SBIT LED2 = P0 ^ 1; SBIT LED3 = P0 ^ 2; SBIT LED4 = P0 ^ 3; SBIT K1 = P1 ^ 0; SBIT K2 = P1 ^ 1; SBIT K3 = P1 ^ 2; SBIT K4 = P1 ^ 3; Void delayms (uint x) { Uchar i; While (x -) For (i = 0; I < 120; i ++); } void main () { P1 = 0xFF; P0 = 0xFF; While (1) { LED1 = k1; LED2 = k2; IF (k3 == 0) { While (k3 == 0); LED3 = ~ LED3; } IF (k4 == 0) { While (k4 == 0); LED4 = ~ LED4; } DELAYMS (10); } } void main () { P1 = 0xFF; P0 = 0xFF; While (1) { LED 1 = K1; // k1 = 1, the lamp is off; K1 = 0, the light is on // LED1, 2, directly controlled by the button, the button status is the state of the lamp // LED3, 4, indirect control by the button, press the button for the first time IF (k3 == 0) // Press K3, K3 = 0 { While (k3 == 0); / / Keep the status of the lamp, wait for the release button; after the button is released, the next instruction is executed, that is, the opposite state. LED3 = ~ LED3; / / Realize the opposite state of the lamp, double button status switch } IF (k4 == 0) { While (k4 == 0) LED4 = ~ LED4; } DELAYMS (10); } } Focus -While (1) and while (1); (with a semicolon) - While (1) {...}: Yes, let the microcontroller have been executing {...}, ** Prevent procedures from running **, usually used for the main program, ensure that the program continues to execute While (1); : Yes, it is an instruction, which allows the single-chip to stop in this position, generally used to detect the interrupt, only the CPU receives the interrupt command, will only jump out of the While (1), enter the interrupt service subroutine; WHLIE (1) The essence is a dead cycle, and the instructions in While (1) will continue to be repeated, unless there is interruption, while (1); can be seen as a while (1) {// empty instruction}, it is empty instruction , * The microcontroller stops in this line code * - High and low levels of buttons - High low level of the button Obviously: We are valid at high power. When you are not pressed, it is high level, 1; when K1 = 1, the lamp is destroyed; from P0, P1 pin initialization can also be seen. Experiment three K1 ~ K4 packet controlled LED Experimental Content: 4 different operations are performed on the LEDs after the bond is drawn. # include #define uchar unsigned char #define uint unsigned char Void delayms (uint x) { Uchar t; While (--X) For (t = 0; t < 120; t ++); } void main () { Uchar K, T, Key_State; // Define variables, and keyboard P0 = 0xFF; // Initialization P0, P1 pin P1 = 0xFF; While (1) { T = P1; // Record the P1 initial value IF (t! = 0xff) //// { DELAYMS (10); IF (t! = p1) Continue; // Check the button again Key_State = -t >> 4; // get a 4-digit button value, // By the mode XXXX1111 (one bit is 0, the other is 1) / / Becomes a pattern 0000xxxx (one bit in X is 1, the other is 0) K = 0; // Check 1 location, accumulate the button number K While (key_state! = 0) { K ++; Key_State >> = 1; } / / 4 processing according to the button number K // (The current situation is within the cyclic body, the instructions in Switch will be judged and executed) Switch (k) { Case 1: IF (p0 == 0x00) P0 = 0xff; // 1111 1111 P0 << = 1; // p0 left shift a 1111 1110 left shift DELAYMS (200); Break; Case 2: p0 = 0xf0; Break; // Light [above] 4 Case 3: p0 = 0x0f; break; // Light [below] 4 // Recommended knowledge points: common cathode or anode, and pins Case 4: p0 = 0xff; // Close all } } } } Focus, read the full story

     

     

     

     

    List all Question

    Nickname

    Email

    Questions

    Our other product:

    Professional FM Radio Station Equipment Package

     



     

    Hotel IPTV Solution

     


      Enter email  to get a surprise

      fmuser.org

      es.fmuser.org
      it.fmuser.org
      fr.fmuser.org
      de.fmuser.org
      af.fmuser.org ->Afrikaans
      sq.fmuser.org ->Albanian
      ar.fmuser.org ->Arabic
      hy.fmuser.org ->Armenian
      az.fmuser.org ->Azerbaijani
      eu.fmuser.org ->Basque
      be.fmuser.org ->Belarusian
      bg.fmuser.org ->Bulgarian
      ca.fmuser.org ->Catalan
      zh-CN.fmuser.org ->Chinese (Simplified)
      zh-TW.fmuser.org ->Chinese (Traditional)
      hr.fmuser.org ->Croatian
      cs.fmuser.org ->Czech
      da.fmuser.org ->Danish
      nl.fmuser.org ->Dutch
      et.fmuser.org ->Estonian
      tl.fmuser.org ->Filipino
      fi.fmuser.org ->Finnish
      fr.fmuser.org ->French
      gl.fmuser.org ->Galician
      ka.fmuser.org ->Georgian
      de.fmuser.org ->German
      el.fmuser.org ->Greek
      ht.fmuser.org ->Haitian Creole
      iw.fmuser.org ->Hebrew
      hi.fmuser.org ->Hindi
      hu.fmuser.org ->Hungarian
      is.fmuser.org ->Icelandic
      id.fmuser.org ->Indonesian
      ga.fmuser.org ->Irish
      it.fmuser.org ->Italian
      ja.fmuser.org ->Japanese
      ko.fmuser.org ->Korean
      lv.fmuser.org ->Latvian
      lt.fmuser.org ->Lithuanian
      mk.fmuser.org ->Macedonian
      ms.fmuser.org ->Malay
      mt.fmuser.org ->Maltese
      no.fmuser.org ->Norwegian
      fa.fmuser.org ->Persian
      pl.fmuser.org ->Polish
      pt.fmuser.org ->Portuguese
      ro.fmuser.org ->Romanian
      ru.fmuser.org ->Russian
      sr.fmuser.org ->Serbian
      sk.fmuser.org ->Slovak
      sl.fmuser.org ->Slovenian
      es.fmuser.org ->Spanish
      sw.fmuser.org ->Swahili
      sv.fmuser.org ->Swedish
      th.fmuser.org ->Thai
      tr.fmuser.org ->Turkish
      uk.fmuser.org ->Ukrainian
      ur.fmuser.org ->Urdu
      vi.fmuser.org ->Vietnamese
      cy.fmuser.org ->Welsh
      yi.fmuser.org ->Yiddish

       
  •  

    FMUSER Wirless Transmit Video And Audio More Easier !

  • Contact

    Address:
    No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620

    E-mail:
    [email protected]

    Tel / WhatApps:
    +8618078869184

  • Categories

  • Newsletter

    FIRST OR FULL NAME

    E-mail

  • paypal solution  Western UnionBank OF China
    E-mail:[email protected]   WhatsApp:+8618078869184   Skype:sky198710021 Chat with me
    Copyright 2006-2020 Powered By www.fmuser.org

    Contact Us