rendered paste body#include <p18cxxx.h>
#include <usart.h>
#include <timers.h>
#include <pwm.h>
#pragma config LVP=OFF
#pragma config WDT=OFF
int r;
void rx_handler (void);
void main()
{
TRISB = 0;
PORTB = 0;
// check 65
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 65);
RCONbits.IPEN = 1;
IPR1bits.RCIP = 1;
INTCONbits.GIEH = 1;
OpenTimer2(TIMER_INT_OFF & T2_PS_1_16);
// 4.8khz duty cycle with 1/16 prescaler and 10mHz clock
OpenPWM1(0x1f);
OpenPWM2(0x1f);
SetDCPWM1(0);
SetDCPWM2(0);
PORTBbits.RB7 = 1;
PORTBbits.RB6 = 0;
PORTBbits.RB5 = 1;
PORTBbits.RB4 = 0;
while(1)
{
while(BusyUSART());
SetDCPWM1(r);
}
}
#pragma code rx_interrupt = 0x8
void rx_int (void)
{
_asm goto rx_handler _endasm
}
#pragma code
#pragma interrupt rx_handler
void rx_handler (void)
{
r = getcUSART();
PIR1bits.RCIF = 0;
}