Code:
#include <p18f4520.h>
#include <delays.h>
#include <stdio.h>
//#include <xlcd.h>
#include <pwm.h>
#include <timers.h>
#pragma config WDT = OFF // off watch dog timer
#pragma config LVP = OFF // off low voltage programing
#pragma config OSC = EC //config osc = highspeed
void main (void)
{
unsigned char result;
ADCON0 = ADCON0 ^ 0x01; //turn on ADC
// TRISA = 0b00000001;
TRISB = 0; //set port b as output
PORTB = 0; // clear port b
TRISC = 0; //set port c as output
OpenTimer2(TIMER_INT_ON & T2_PS_1_16 & T2_POST_1_1); // set timer on prescale 1:1, postscale 1:1
//PR2=64;
OpenPWM1(0xff); // turn own PWM
while(1)
{
ADCON0= ADCON0 ^0x02; //adc conversion
// Delay1KTCYx(1);
while(ADCON0 & 0x02){}// loop till convension end
// Delay1KTCYx(1);
result = ADRESH; //store adc result
setDCPWM1(result);
PORTB = PORTCbits.RC2;
Delay1KTCYx(100);
}
}
hello i am a newbie and above is my code for my pwm blinking program. i am using a p18f4520 ic chip and i am using mplab c18 complier. i got 2 problems 1 is PORTB=PORTCbits.RC2 and setDCPWM1(result)
portb=portcbit.rc2 cant let me set all port b = to rc2... it wont blink all my LED on my picdem 2 plus board
and the setDCPWM1(result) got error on my build.