PDA

View Full Version : How to start programming in pic



RITESH
- 12th April 2017, 07:25
Hello,
I want to start codding in C the pwm i have programmer how to write code for this like led blinking and all...

HenrikOlsson
- 12th April 2017, 08:08
Get yourself a C compiler, read the manual then find a forum where C is being discussed.

RITESH
- 12th April 2017, 13:40
is it fine for pwm??

#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000


void main()
{
TRISB=0X00;
TRISA = 0xff ;
ADCON1=0b00000000;
ADCON0=0b10000001;//000 = channel 0, (RA0/AN0)
ADIF=0;
ADIE=1;
PEIE=1;
TRISC = 0 ;
PR2 = 0b11111001 ;
T2CON = 0b00000100 ;
CCP1CON = 0b00111100;
PORTC = 0 ;
while(1)
{
__delay_ms(10);
GO_DONE=1;
__delay_ms(10);
while(GO_DONE);
CCPR1L = ADRESH ;
}
}

Art
- 22nd April 2017, 08:39
No, I’s silly. It will sit in while GO_DONE forever, where there is no need to keep setting a register.
Microchip have their own forum with a beginner section which would be fine for this.
This is C. If you post it there I’ll fix it.