Single chip microcomputer timer duty cycle button adjustment Proteus simulation program

Publisher:缘到泉Latest update time:2019-12-04 Source: elecfansKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The simulation schematic is as follows

 

The microcontroller source program is as follows:

#include "reg52.h" 

#define uchar unsigned char 

#define uint unsigned int 

float COUNT100,PWMCOUNT; 

/*LCD port definition*/ 

sbit RS=P3^7; 

sbit RW=P3^6; 

sbit E=P3^5; 

sbit PWM=P1^0; 


sbit K1=P3^0; //add 1

sbit K2=P3^1; // minus 1


sfr LCDData=0x80;//0x80--P0,0X90--P1,0xa0--P2,0xb0--P3 

/************LCD driver************************/ 

/*Delay function delay*/  

void delay(uint i)

{

        while(i--);                        

}


/*******LCD driving function*******/  

void write_instruction(uchar x) //byte write

{

   delay(1000);

   E=0;

   RW=0;

   RS=0;

   LCDData=x;

   E=1;

   delay(20);

   E=0;

}

void write_data(uchar x) //data write

{

   delay(1000);

   E=0;

   RW=0;

   RS=1;

   E=1;

   LCDData=x;

   E=0;

}

void cla(void)                           //清屏

{

        write_instruction(0x01);

void initlcd(void) //initialization

{

        write_instruction(0x38); //Display mode

        delay(200);

        write_instruction(0x0c); //Set the display to on and not to display the cursor

        delay(200);

        write_instruction(0x06); //Address pointer plus one after writing a character

        delay(200);

        cla();

//        delay(200);

}

void write_string(uchar x,uchar *p) // string writing

{

        write_instruction(x);

        while(*p!=0x00)

        {

                write_data(*p);

                p++;

                if(x++==0x8f)

                {

                        write_instruction(0xc0);

                }

        }

}

/************ LCD driver ends **************************/ 

void DISPPWM(float add, float p) 

        write_instruction(add); 

        write_data(p/100+0x30); 

        write_data(p%100/10+0x30); 

        write_data(p%100%10+0x30); 

        write_data('%'); 

/*******Keyboard driver******************/ 


void pwmScanKey()

{                

                if(K1==0)

                {

                        while(K1==0); //Wait for the button to be released 

                        if(PWMCOUNT<100)

                                PWMCOUNT=PWMCOUNT+10;

                }

                

                if(K2==0)

                {

                        while(K2==0); //Wait for the button to be released 

                        if(PWMCOUNT>0)

                                PWMCOUNT=PWMCOUNT-10;

                }

                                

                DISPPWM(0x84, PWMCOUNT); 

                

}


void main(void) 

        initlcd(); //Initialize LCD 

        delay(0xffff); 

        COUNT100=0; 

        PWMCOUNT=50;

        

        write_string(0x80,"PWM="); 

        DISPPWM(0x84, PWMCOUNT); 

        

        TMOD=0x01; //Set timer 0 mode 1, 16-bit timing mode 

        EA=1; //Open the interrupt enable general control bit 

        ET0=1; //Turn on timer 0 overflow interrupt enable bit 

        TL0=0x66; //Timer 0 counter initialization, t=(2^16-a)*12/fosc, fosc=11.059sMHz 

        TH0=0xfc; 

        TR0=1; //Start timer 0 

        while(1)

        {

                pwmScanKey();


        }

                //Wait for interrupt 

        

void TIME0ISR(void)         interrupt 1 

         // PWM = 0;

        TL0=0x66; 

        TH0=0xfc; 

        COUNT100++; 

        if(COUNT100==100) 

        { 

                COUNT100=0; 

        } 

        if(COUNT100        { 

                PWM=1; 

        } 

        else 

        { 

                PWM=0; 

        } 

}

Keywords:MCU Reference address:Single chip microcomputer timer duty cycle button adjustment Proteus simulation program

Previous article:Proteus simulation program for single chip microcomputer low frequency signal generator
Next article:Microcontroller Course Design Report - Temperature Alarm

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

Using PROTEUS to simulate the communication between the microcontroller and the keypad interface
(It is really inconvenient that the higher version of protues is not compatible with the lower version) Design requirements: Implementing the Interface of Keyboard Matrix in Proteus ISIS with 8051 Microcontroller. In the previous project, we implemented the interface of LCD with 8051 microcontroller to dis
[Microcontroller]
Using PROTEUS to simulate the communication between the microcontroller and the keypad interface
MSP430 MCU drives LCD1602 C language program
/*******************************************************************************/                         1.msp430 single chip C language /************************************************************************/ #include"msp430f6638.h" /*********************************************** P5.3----E P57 P56 P55 P54 P
[Microcontroller]
51 MCU AD conversion
In the digital logic course, we have learned the concept of AD conversion: converting analog signals into digital signals after sampling, quantization, and encoding. However, we have not learned how to display the results through microcontroller programming. There are two types of coding: rounding up and down, and onl
[Microcontroller]
The relationship between microcontroller instruction set and operating system
1 First, discuss the relationship between various microcontrollers and operating systems When it comes to single-chip microcomputers, the first thing that comes to mind is the 51 single-chip microcomputer, right? Yes, we also think it is acceptable to call the more advanced AVR a single-chip microcomputer. Then we a
[Microcontroller]
Homemade 51 MCU common header files (DS18B20)
/*-------------------------------------------------------------------------- TEMPERATURE.H The user function is C51. Copyright (c) 1988-2004 Keil Elektronik GmbH sum zhaojun All rights reserved. --------------------------------------------------------------------------*/ #ifndef __TEMPERATURE_H__ #define __TEMP
[Microcontroller]
MCS-51 MCU Memory Expansion
Main content: Part 8 MCS-51 MCU memory expansion (1) 1. Overview 2. System bus and bus structure 3. Read/write control, address space allocation and external address latch 4. Program memory EPROM expansion Key points: System bus and bus structure Memory address space allocation External address latch 74LS373 Typical
[Microcontroller]
Digital voltmeter based on single chip microcomputer control
     1 Introduction     Due to the advantages of simple and practical, high reliability, good performance-price ratio and small size, the single-chip microcomputer has been rapidly developed in various technical fields. Digital voltmeter (DigitalVoltmeter) is abbreviated as DVM. It is an instrument that uses digital m
[Microcontroller]
Digital voltmeter based on single chip microcomputer control
Detailed explanation of the internal data memory RAM structure of MCS-51 single chip microcomputer
Internal data memory lower 128 cells The internal RAM of the 8051 microcontroller has a total of 256 units, which are usually divided into two parts according to their functions: the lower 128 units (unit address 00H ~ 7FH) and the upper 128 units (unit address 80H ~ FFH). The figure shows the configuration diagram
[Microcontroller]
Detailed explanation of the internal data memory RAM structure of MCS-51 single chip microcomputer
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号