I am very new to PICs and just compiled ( MikroC ) and loaded my first program to the EasyPIC2 board, the example for PWM that comes with MikroC ( PWM_Test.c ). for the 16F877A
According to the program notes, when the push buttons on RA0 or RA1 are pushed, the output on RC2/CCP should change.
So I assume that the LED on RC2 should change when these buttons are pushed (HIGH).
However, ALL the LEDs are on for Port C.
Settings:
Code Protection: OFF
LVP: OFF
WDT: OFF
HS Oscillator: ON
BODEN: ON
From the code example (below), should only the individual bits for I/O be set? It looks like ALL bits for Port A are set as input, and ALL bits on port B are set for output; and ALL bits on Port C are set as output - is this the case?
Here is the whole code example:void InitMain() {
PORTB = 0; // set PORTB to 0
TRISB = 0; // designate portb pins as output
ADCON1 = 6; // all ADC pins to digital I/O
PORTA = 255;
TRISA = 255; // PORTA is input
PORTC = 0xFF; // set PORTC to $FF
TRISC = 0; // designate PORTC pins as output
PWM_Init(5000); // initialize PWM module
}//~
Any ideas, please?/*
* Project name:
PWM_Test_01 (PWM library Demonstration)
* Done by:
Vladimir Petrovic, mikroElektronika, Feb.2005
* Description:
This is a simple demonstration of PWM library, which is being used for
control of the PIC's CCP module. The module is initialized and started,
after which the PWM Duty Ratio can be adjusted by means of two buttons
connected to pins RA0 and RA1. The changes can be monitored on the CCP
output pin (RC2).
* Test configuration:
MCU: P16F877A
Dev.Board: EasyPIC2
Oscillator: HS, 08.0000 MHz
Modules: x
SW: mikroC v1.01
*/
unsigned short j, oj;
void InitMain() {
PORTB = 0; // set PORTB to 0
TRISB = 0; // designate portb pins as output
ADCON1 = 6; // all ADC pins to digital I/O
PORTA = 255;
TRISA = 255; // PORTA is input
PORTC = 0xFF; // set PORTC to $FF
TRISC = 0; // designate PORTC pins as output
PWM_Init(5000); // initialize PWM module
}//~
void main() {
initMain();
j = 80; // initial value for j
oj = 0; // oj will keep the 'old j' value
PWM_Start(); // start PWM
while (1) { // endless loop
if (Button(&PORTA, 0,1,1)) // button on RA0 pressed
j++ ; // increment j
if (Button(&PORTA, 1,1,1)) // button on RA1 pressed
j-- ; // decrement j
if (oj != j) { // if change in duty cycle requested
PWM_Change_Duty(j); // set new duty ratio,
oj = j; // memorize it
PORTB = oj; // and display on PORTB
}
Delay_ms(200); // slow down change pace a little
}
}//~!
Cheers
Dale