You are on page 1of 1

C:/Users/piyathil/MPLABXProjects/PWM.X/pwm.

c
/*
* File:
: LEDOn.
.c
* Author:
: piyathil
*
* Created on March 22, 2023, 10:07 AM
*/

#i
include <stdio.h>
#i
include <stdlib.h>
#i
include <p18f4321.h>
#i
include <delays.h>

# pragma config WDT = OFF


# pragma config LVP = OFF
# pragma config BOR = OFF
# pragma config OSC = INTIO2
/*
*
*/

int period = 100;


; // this the variable to control the period
int on_time = 50 ; // this is the variable to control the pulse on time

void main(void) {

TRISCbits.
.TRISC4=
=0; // Make RC4 as output

LATCbits.
.LATC4 =1; //T
Turn LED D3 ON, This is only for testing

TRISBbits.
.TRISB3 = 0; // This is the Enable A pin
TRISBbits.
.TRISB2 = 0; // This is the Phase A - Directional control pin

LATBbits.
.LATB2=
=1; // this is the direction control bit

// Software PWM code


while(1){

LATBbits.
.LATB3=
=0; // Enable pin on time
Delay10TCYx(
(on_time)
);

LATBbits.
.LATB3=
=1; // Enable pin off time
Delay10TCYx(
(period-
-on_time);

};

return;
}

1.1 of 7 2023.04.18 12:45:28

You might also like