51 MCU driver for proximity switch

Publisher:CyborgDreamerLatest update time:2019-11-16 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Today I made a little thing: the digital tube displays the change value of the proximity switch. The proximity switch is connected to the microcontroller through external interrupt 0; the digital tube reading increases to 50 and then clears to zero;


#include // Reference the header file of the standard library

#include

#define uchar unsigned char

#define uint unsigned int


#define NoOp 0x00 // No operation register 

#define Digit0 0x01 // Digital tube 1 register 

#define Digit1 0x02 // Digital tube 2 register 

#define Digit2 0x03 // Digital tube 3 register  

#define Digit3 0x04 // Digital tube 4 register  

#define Digit4 0x05 // Digital tube 5 register  

#define Digit5 0x06 // Digital tube 6 register  

#define Digit6 0x07 // Digital tube 7 register  

#define Digit7 0x08 // Digital tube 8 register  

#define DecodeMode 0x09 // Decode mode register  

#define Intensity 0x0a // Brightness register  

#define ScanLimit 0x0b // Scanning bit number register 

#define ShutDown 0x0c // Low power mode register

#define DisplayTest 0x0f // Display test register

#define ShutdownMode 0x00 // Low power consumption mode  

#define NormalOperation 0x01 // Normal operation mode 

#define ScanDigit 0x07 // Scan digit setting, display 8-digit digital tube

#define DecodeDigit 0xff // Decode setting, all 8 bits are BCD code

#define IntensityGrade 0x0a // Brightness level setting 

#define TestMode 0x01 // Display test mode,

#define TextEnd 0x00 // Display test ends and resume normal working mode



sbit DIN = P0^3; //Serial data input


sbit CLK = P0^4; //Serial clock


sbit LOAD = P0^5; // Display data latch control





uchar DisBuffer[8]={0,0,0,0,0,0,0,0}; //Display buffer 0x06

uchar a[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};


uchar num11;


/* Delay t milliseconds*/


void delay(uint a)


{uchar x,y;

  for(x=a;x>0;x--)

  for(y=110;y>0;y--);



/* Write byte (8 bits) to MAX7219 */


void SendChar (uchar ch)


{


    uchar i,temp;


    _nop_();


   for(i=0;i<8;i++)


    {


       temp=ch&0x80;


       ch=ch<<1;


       if(temp)


        {


               DIN=1;


               CLK=0;


               CLK=1;


        }


        else


        {


               DIN=0;


               CLK=0;


               CLK=1;


        }


    }


}




/* Write word (16 bits) to MAX7219 */


void WriteWord (uchar addr,uchar num)


{


    LOAD=0;


    _nop_();


    SendChar(addr);


    _nop_();


    SendChar(num);


    _nop_();


    LOAD=1; //Latch into the corresponding register


}




/* MAX7219 initialization */


void InitDisplay (void)


{


    WriteWord (ScanLimit,ScanDigit); // Set the scan limit


    WriteWord (DecodeMode,DecodeDigit); // Set the decoding mode


    WriteWord (Intensity,IntensityGrade); // Set the brightness


    WriteWord (ShutDown,NormalOperation); // Set to normal working mode


}


//show




// External interrupt 0

void show1(uchar dat)

{uchar shi,ge;

shi=dat/10;

ge=dat%10;

delay(1);

WriteWord (Digit6,a[ge]);

WriteWord (Digit7,a[shi]);


}






/* Main function */

void main(void)


{


     InitDisplay (); // MAX7219 initialization

         


         IE=0x81;

         IT0=1;


      show1(0);

          WriteWord (Digit1,0xff);

          WriteWord (Digit0,0xff);

      WriteWord (Digit2,0xff);

          WriteWord (Digit3,0xff);

          WriteWord (Digit4,0xff);

          WriteWord (Digit5,0xff);

while(1)


{

        if(num11==50)

    num11=0;


    show1(num11);


}

}



void exint0(void)interrupt 0

{

num11++;


InitDisplay();

delay(1);

show1(num11);

delay(1);


}


Reference address:51 MCU driver for proximity switch

Previous article:L297, L298 drive stepper motor schematic diagram proteus simulation + program LCD display speed
Next article:Design of Waveform Generator Based on 51 Single Chip Microcomputer

Recommended ReadingLatest update time:2024-11-16 11:25

Character Device Driver (II)
In the section Character Device Driver (I), we learned the general framework of character device driver design. But how is the character device driver implemented? In this section, we will have a deeper understanding of how the kernel driver is connected to the application. First, we create a read_mem.c file in Linu
[Microcontroller]
Character Device Driver (II)
Tiny6410 LED bare metal driver notes
1. First check the "Tiny6410-1170 CPU Core Board Schematic Diagram" and find the LED part: As can be seen from the above figure, when nLED_1 is at a low level, LEDx will light up. 2. Find the nLED_x connection diagram in the Tiny6410-1170 CPU Core Board Schematic (it should be nearby):
[Microcontroller]
Tiny6410 LED bare metal driver notes
Application of arm driver linux waiting queue blocking interrupt IO
" Linux waiting queue blocking interrupt IO application" involves four kernel driver functions and zero kernel structures, and analyzes four kernel driver functions; one related application template or kernel driver template for reference, and one related application template or kernel driver for reference 1. Concept:
[Microcontroller]
VeriSilicon's Zeng Yi: More system IPs are needed to drive the development of the Internet of Things
During the 7th Shanghai FD-SOI Forum, Zeng Yi, Director of VeriSilicon's IoT Interconnect Platform, shared a keynote speech titled "Low-power IoT Technology Based on FD-SOI Technology". He said that the IoT has grown rapidly in recent years, and many companies are deploying short-distance IoT such as smart homes and l
[Embedded]
VeriSilicon's Zeng Yi: More system IPs are needed to drive the development of the Internet of Things
iTOP-4412 development board_driver_adc driver upgrade and test routine
This document introduces the upgrade and test routines of the ADC driver of the iTOP-4412 development board. The built-in driver can only support one ADC. This article introduces how to modify the control to support 4 ADCs. 1 Hardware Introduction As shown in the figure below, this is a screenshot of the 4412 datashee
[Microcontroller]
iTOP-4412 development board_driver_adc driver upgrade and test routine
Getting started with the first 74HC595 driver in C language
/******** Experimental driver 74HC595 chip********      MCU model: ATMEGA48PA     /********** 74HC595 level logic ***************************    SI SCK SCLR RCK OE Output pin    X X X X H QA--QH Output high impedance    X X X X L QA--QH output effective value    X X L X X Clear the bit register    L rising edge H X
[Microcontroller]
89c52 MCU Simulation ILI9341 LCD Screen Driver
The MCU simulation schematic diagram of ILI9341 is as follows For your reference. ILI9341 8-bit mode, 16-bit color ILI9341 microcontroller source program is as follows: //#include REGX52.H #include REGX55.H #include intrins.h #include "map.h" //#define RED 0XF800 //Red //#define GREEN 0X07E0 //Green //#define
[Microcontroller]
89c52 MCU Simulation ILI9341 LCD Screen Driver
Omdia: Only five foundries can drive production for HV 40 and 28nm AMOLED
On December 20, Omdia released a report stating that currently, there are five foundry companies that can provide mature production capacity for HV 40nm and 28nm process AMOLED driver chips, including Samsung Foundry, UMC, TSMC, Global Foundries and SMIC. Among them, since HV 28nm production capacity will still be u
[Mobile phone portable]
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号