Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pwm design on pic16f877a using ccs c

Status
Not open for further replies.

youngjkoh

Newbie level 3
Joined
Oct 15, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Chicago
Activity points
1,376
Hi all,

I'm trying to write codes for building a pwm on pic16f877a using ccs c compiler. Please help if any of you have some example codes for that. Thank you!
 

There are example programs available for the same when you install CCS compiler. Please check the folder where you installed the PIC C compiler. Their Help manual explains about what each example program file does.
Good day.
Regards,
blueshift
 
#include <16f877.H>

#fuses xt,noPROTECT,noWDT,noPUT,noBROWNOUT,nolvp,nowrt

#use delay(clock=10000000)

#use standard_io(a) // set io port a
#use standard_io(b) // set io port b
#use standard_io(c) // set io port c
#use standard_io(d) // set io port d
#use rs232(baud=9600, xmit=pin_c6, rcv=pin_c7) // set rs232 port


main(){
int value; // aset up storage in memory
setup_port_a(ALL_ANALOG); // se port a to all analoges
setup_adc(adc_clock_div_2); // set up adc
setup_timer_2(T2_div_by_4,0xc0,2); // initialize timer 2
setup_ccp1(ccp_pwm); // capture compair pwm on ccp1 (C1)

while (1) // all ways
{
set_adc_channel(0); // adc A0
delay_us (5); // delay 5 us
value= read_adc(); // point to value(store input from A0)
delay_ms (100); // delay 100 ms
if(value >= 190) // if A0 >=190 Store 190
{
value = 190;
}
if(value<=90) // if A0 <=90 Store 90
{
value = 90;
}

set_pwm1_duty(value); // depending on value set pwm output (C1)
delay_ms(10); //// delay 10 ms

}

}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top