0% found this document useful (0 votes)
65 views6 pages

#Define LED GPIO.B2 //pin 5

This document defines constants and variables for controlling an LED and PWM output using a timer interrupt. It initializes Timer1 to generate interrupts alternating the PWM output on and off using on_time and off_time variables. It also checks sensor readings to control an additional output and limits the on and off times.

Uploaded by

softroniics
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views6 pages

#Define LED GPIO.B2 //pin 5

This document defines constants and variables for controlling an LED and PWM output using a timer interrupt. It initializes Timer1 to generate interrupts alternating the PWM output on and off using on_time and off_time variables. It also checks sensor readings to control an additional output and limits the on and off times.

Uploaded by

softroniics
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#define LED GPIO.

B2 //pin 5

#define CLAMP GPIO.B5

#define PWM GPIO.B5

unsigned char count1,on_time,off_time;

unsigned int volt, current,POWER;

bit toggle;

void Timer1_Interrupt() iv 0x0004

PIR1.TMR1IF = 0;

if (toggle==0)

{
TMR1H = 255; // Cleat timer1 registers

TMR1L = off_time; // before enabling timer1

PWM=0;

toggle=1;

else if (toggle==1)

TMR1H = 255; // Cleat timer1 registers

TMR1L = on_time; // before enabling timer1

PWM=1;

toggle=0;

void InitTimer1(void)

TMR1H = 0; // Cleat timer1 registers

TMR1L =0; // before enabling timer1

// Timer1 is 16bit timer

T1CON = 0b00100001; // Prescalar 1:1, Timer1 On


PIR1.TMR1IF = 0; // Clear interrupt bit

PIE1.TMR1IE= 1; // Enable Timer1 interrupt

INTCON.PEIE = 1; // Enable peripheral interrupts

INTCON.GIE = 1; // Enable global interrupts

void chk_limit ()

if (on_time>250)

on_time=249;

if (on_time<5)

on_time=6;

if (off_time>250)

off_time=249;
}

if (off_time<5)

off_time=6;

if (on_time<10)

LED=1;

else if (on_time>10)

LED=0;

void main()

TRISIO = 0b00000001; // an0 for current sense


ANSEL = 0b01110001;

CMCON = 7;

ADC_Init();

InitTimer1();

off_time=125;

on_time=125;

toggle=0;

PWM=0;

LED=0;

do

volt = (ADC_Read(0)); // Read analog value from channel 1


current= (ADC_Read(1));

POWER = volt * current ;

if (POWER < 50)

CLAMP=0;

else

{CLAMP =1;}

while (1);

You might also like