Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help for 1MHz to 14MHz pwm using pic16f877a

Status
Not open for further replies.

pany_pat

New Member
Hi,

I am having problem for pwm using pic16f877a, I am not getting the pulse output from microcontroller. Please can you help me out for seeing my source code if their is any thing wrong or missing then please help me out.

#include<pic.h>
#include<math.h>
#include "ioports1.h"
#include "delay.h"
#include "lcd.h"

__CONFIG (HS & DEBUGDIS & WDTDIS & BORDIS & PWRTEN & LVPDIS & PROTECT);

unsigned int dummy_sec;

void Sec(unsigned int);

void main()
{
Sec(100);
init_ports();
Sec(50);
lcd_init(); //LCD initialized
Sec(25);

lcd_line1(0); //LCD address specified AT LINE 1
lcd_string(" PANKAJ PATEL "); //Displays message "LCD INTERFACING"
lcd_line2(0); //LCD address specified AT LINE 2
lcd_string(" PWM EXAMPLE "); //Displays message "LCD INTERFACING"

Sec(200);
init();

for(;;)
{
GIE = 1;
lcd_line1(0); //LCD address specified AT LINE 1
lcd_string(" PANKAJ PATEL "); //Displays message "LCD INTERFACING"
lcd_line2(0); //LCD address specified AT LINE 2
lcd_string(" PWM EXAMPLE "); //Displays message "LCD INTERFACING"
}
}

init_ports()
{
T_CPU_LED = 0; // pin enable to output
CPU_LED = 0;
}

init()
{
TMR1H = 0xfc;
TMR1L = 0x17;
TMR1CS = 0;
T1CKPS0 = 0;
T1CKPS1 = 0;
T1CON = 0b00000001;
TMR1ON = 1;
TMR1IF = 0;
TMR1IE = 1;
PR2 = 0b00000000;
T2CON = 0b00000100;
CCPR1L = 0b00000000;
CCP1CON = 0b00011100;
TMR2ON = 1;
TMR2IF = 0;
TMR2IE = 1;
PEIE = 1;
GIE = 1;
}

void Sec(unsigned int itime)
{
unsigned int i;
unsigned char j;
for(i=0;i<itime;i++)
for(j=0;j<165;j++);
}


void interrupt ISR()
{
if(TMR1IF)
{
PIE1 = 0;
TMR1IF = 0;
TMR1ON = 0;
CPU_LED = !CPU_LED;
++dummy_sec;
if(dummy_sec > 1000)
{
// CPU_LED = !CPU_LED;
dummy_sec = 0;
}

TMR1H = 0xfc;
TMR1L = 0x17;
TMR1ON = 1;
PIE1 = 1;
}

}
 
Status
Not open for further replies.

Latest threads

Back
Top