Single chip microcomputer EC1 digital rotary encoder simulation program

Publisher:人妙果华Latest update time:2019-11-14 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

一个按键正转,另一个按键反转.模拟输出编码信号.正转1110 00 10  反转11 01 00 01
//1H=GP2  2H=GP1  3H=GP0  4H=GP4  KEY=GP3 
QQ picture 20170706075725.png 
#include
__CONFIG(0xFEA);
#define uchar unsigned char 
#define CW_A GP4 //
#define CW_B GP5 //
#define KEY_A GP0 //
#define KEY_B GP1 //
uchar tmp=1,at=0; 

void delay_ms(unsigned int count) 
{unsigned char i,j; 
for(i=0;ifor(j=0;j<120;j++); 


void main()
{
TRIS=0x03;
OPTION=0;
KEY_A=1;KEY_B=1;CW_A=0;CW_B=0;
while(1)
{
  if(CW_A==0&&CW_B==0)
  {if(KEY_A==0)
   {delay_ms(10);
    if(KEY_A==1)
    {CW_A=1;CW_B=0;delay_ms(200);CW_A=1;CW_B=1;}
   }
   if(KEY_B==0)
   {delay_ms(10);
    if(KEY_B==1)
    {CW_A=0;CW_B=1;delay_ms(200);CW_A=1;CW_B=1;}
   }
  }

  if(CW_A==1&&CW_B==1)
  {if(KEY_A==0)
   {delay_ms(10);
    if(KEY_A==1)
    {CW_A=0;CW_B=1;delay_ms(200);CW_A=0;CW_B=0;}
   }
   if(KEY_B==0)
   {delay_ms(10);
    if(KEY_B==1)
    {CW_A=1;CW_B=0;delay_ms(200);CW_A=0;CW_B=0;}
   }
  }
}
}

Keywords:MCU Reference address:Single chip microcomputer EC1 digital rotary encoder simulation program

Previous article:PIC18 Series Family Instructions Quick Index
Next article:Students who like single chip microcomputers, come and have a look, the experience of those who have experienced it

Recommended ReadingLatest update time:2024-11-16 15:35

C language HT microcontroller hardware operation instructions
1. How to define variables in C language  -The variable definition syntax in C language is:    #pragma rambank0; it starts with the keyword #pragma, and rambank0 indicates that the data block is block 0.   unsigned char m_acc; ; Define an unsigned character type variable m_acc.   unsigned char m_ststus; ; Define
[Microcontroller]
51 single chip microcomputer stepper motor rotation angle control
#include  reg52.h       typedef unsigned char uchar;   typedef unsigned int uint;   typedef unsigned long ulong;      uchar code beatCode  = {       0xE, 0xC, 0xD, 0x9, 0xB, 0x3, 0x7, 0x6   };   head beats = 0;   fly T0RH = 0, T0RL = 0;      void turnMotor(ulong angle){       EA = 0;       beats = angle
[Microcontroller]
Common methods for hardware anti-interference of single-chip microcomputer system
Common methods for hardware anti-interference of single-chip microcomputer system       The main factors that affect the reliable and safe operation of the single-chip microcomputer system mainly come from various electrical interferences inside and outside the system, and are affected by the system structure design,
[Microcontroller]
PIC microcontroller assembly language explanation (Part 1)
Pic microcontroller is one of the most commonly used microcontrollers, and many programs are developed based on pic microcontrollers. Therefore, it is particularly important to be proficient in pic microcontroller programming. In order to ensure that everyone can accurately and proficiently master the use of pic micro
[Microcontroller]
PIC microcontroller assembly language explanation (Part 1)
MCU---HLK-W801 Bluetooth remote control lighting
Yesterday, we understood how to run the demo. Today, let's see how to remotely light up the LED of the development board via Bluetooth. Although this is not a typical use of low-power Bluetooth, it is a blessing to be able to quickly learn the disgusting SDK code of W801 through this method. Oh, this chip is produced
[Microcontroller]
MCU---HLK-W801 Bluetooth remote control lighting
51 single chip microcomputer lights up the two-way water lamp
#include reg51.h #include intrins.h #define uint unsigned int  #define uchar unsigned char sfr P0M0 = 0x94; sfr P0M1 = 0x93; void delay(uint ms){     uint i,j;     for(i = 0 ;i ms ; i++)         for (j = 0;j 121;j++); } void display(){     uint i,j;     for(i = 0;i 7;i++){          P0 = _crol_(P0,1);         dela
[Microcontroller]
How to use PIC microcontroller's data memory RAM as registers
I believe everyone is familiar with PIC microcontrollers. Among them, the introduction to PIC microcontrollers, the advantages of PIC microcontrollers, and the shortcomings of PIC microcontrollers are all entry-level knowledge. This article will introduce you to the advanced application of PIC microcontrollers - using
[Microcontroller]
How to use PIC microcontroller's data memory RAM as registers
Analytical solution for communication between a microcontroller and a PCI device
1 PCI interface design principle 1.1 Introduction to PCI Bus Protocol Here we only discuss the PCI bus 2.0 protocol. Other protocols are just some extensions based on 2.0. As far as the communication between the microcontroller and the PCI device is concerned, it is of little significance. The PCI bus is a
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号