void main(void) {
uint8_t count = 0;
uint8_t temp = 0;
uint8_t temp2 = 0;
uint8_t value = 0;
uint8_t pwmArray[] = {71,73,76,79,81,83,86,89,92,96,97,101,104,107,109,112,114};
OSCILLATOR_Init();
PORT_Init();
SPI1_Init();
LCD(&PORTD, 0,1,2,3,4,5); // set the connection between the MCU and the LCD
LCD_Begin(16,2); // initialize the LCD module with 16 rows and 2 columns (1602 LCD)
// EUSART Settings
// Port, TXSTA1, RCSTA1, BAUDCON1, BaudRate Value
setup_uart(UART_1, ASYNC_MODE | TXMIT_EN | HIGH_SPEED, SPEN_EN | RCVR_EN, BAUD_16BIT, 9600);
setup_uart(UART_2, ASYNC_MODE | TXMIT_EN | HIGH_SPEED, SPEN_EN | RCVR_EN, BAUD_16BIT, 9600);
setup_timer_3(T3_DIV_8 | T3_NO_SYNC_EXT_CLK | T3_ENABLE);
set_timer_3(T3_Loadvalue);
setup_timer_1(T1_DIV_1 | T1_NO_SYNC_EXT_CLK | T1_ENABLE);
set_timer_1(T1_Loadvalue);
setup_pwm();
setup_timer_2(T2_ENABLE);
set_timer_2(T2_Loadvalue);
enable_interrupt(INT_TIMER1);
enable_interrupt(INT_TIMER3);
PERIPHERAL_Interrupts(ENABLE);
GLOBAL_Interrupts(ENABLE);
while(1)
{
if(!PORTBbits.RB7){
while(!PORTBbits.RB7);
if(count > 17) count = 0;
else count++;
value = pwmArray[count];
temp = (uint8_t)(value << 4);
temp = CCP2CON | temp;
CCP2CON = temp;
temp2 = (value >> 2);
CCPR2L = temp2;
LCD_Goto(1,2); printf("%x", temp);
LCD_Goto(7,2); printf("%u", CCPR2L);
}
}
return;
}