PIC16F84A PWM code and Proteus simulation




This post provides the PWM code for PIC16F84A microcontroller using timer0. There are many uses for PWM signal, e-g you can control dc motor speed using PWM.

PIC16F84A PWM

Timer0 is initialized in the start of the main function and using timer0 interrupts, PWM is generated. This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the ‘Downloads‘ section at the bottom of this page.

It is assumed that you know how to configure timer0 of PIC16F84A microcontroller. If you don’t then please read this page first, before proceeding with this article.

The result of simulating the code in Proteus is shown below.

Here PIC16F84A is running on 20MHz crystal. A PWM wave of 9.1KHz frequency with 50% duty cycle is being generated as shown in the above figure. RA0 pin is being used as PWM_PIN, which you can easily change in the code. Also, you can change PWM duty cycle in the code at any time as well.

Code

The code used to initialize PWM is shown below.

In this InitPWM() function, RA0 pin is made an output, also timer0 is initialized with it’s interrupts enabled. Rest of the PWM generation code is written inside timer0 interrupt service routine code, which is shown below.

PIC16F84A PWM schematic

Downloads

PWM code using PIC16F84A was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.

 

For more detail: PIC16F84A PWM code and Proteus simulation




Current Project / Post can also be found using:

  • pic 16f84a
  • PWM pic16f84a
  • PIC16F84 Control
  • PIC16F84A PWM code Proteus simulation

Leave a Comment

*
= 3 + 2

Read previous post:
PIC16F84A LCD interfacing 8bit mode
PIC16F84A LCD interfacing code (In 8bit mode) + Proteus simulation

This post provides the LCD[1] interfacing code using PIC16F84A microcontroller. This code is written in C language using MPLAB with HI-TECH C...

Close
Scroll to top