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; } }
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
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Analysis of Capacitance and Resistance Changes Caused by PCB Layout
- LSM6DS3 calibration issue
- F28335 ADC learning process
- Development board directly for AI scenarios: phyBOARD-i.MX 8M Plus development board free application in progress!
- About the fabrication process of fiber-embedded microfluidic chips
- Apply for a free trial! Fluke Norma6000 Power Analyzer, born for convenience!
- Chupuyuan 60MHz bandwidth LCD digital oscilloscope
- [GD32E503 Review]——step04. Domestic M33 for uCgui transplantation
- (Transfer) Ultra-low power consumption 4G module G8100 module data free sharing including schematic diagram
- Analysis of the BUCK/BOOST circuit principle, the summary is so perfect!