I am working at one project that commands two current channels (coupling and uncoupling a channel) both from computer (via USB) and from board using two pushbuttons that change the status of each channel.
I want to use 3 interrupts: on data received from USB, on pressing button1 INT0 and on pressing the button2 INT1.
I have read the article http://www.beyondlogic.org/interrupts/interupt.htm about interrupts.
What I am asking is that I will have three interrupt service requests that will be put in Interrupt Vector table at some certain addresses and I don''t know how to make it.
I have worked with Intel80552 --- PCmon and there I declared a funcion with no parameters and after then the word interrupt i (range of i= 1:16, because Intel 80552 can handle interrupts from 16 sources: UART, ADC,TIMER, etc).
I saw some codes with the macro: #pragma that puts an interrupt function at some address, but I don't know how to deal with. I want to write the code for MCU in MikroC (not assembly language, but C), if you know other integrated development environment please tell me. So please tell me how should be the look of the functions.
The second question will be: I want to use USB module of PIC18F2550. I have read in the datasheet:
. Well this microcontroller has a 48MHz cuartz crystal integrated, inside. I want to ask something: I know that CLK resource is a critical one (only one task can access this resource at a certain time). Do I need an external crystal?When the PIC18F4550 is used for USB connectivity, it must have either a 6 MHz or 48 MHz clock for USB operation, depending on whether Low-Speed or Full Speed mode is being used.
The final question will be:
I have done the initialization of ports INPUTS/OUTPUTS and Interrupts, if I have to add some instruction please tell me: the code is below:
Code: Select all
void port_init(void)
{
//0-out,1-in
TRISA&= ~31; //00011111=31
TRISB|= 3; //00000011= 3
PORTA= 0; //00010000= 0
//000LLLMM; L=LED,M=MOS
//LED3/LED2/LED1/MOS2/MOS1
}
void INT0_init(void)
{
INTCONbits.INT0E=1;
INTCONbits.INT0F=0; //1 = The INT0 external interrupt occurred (must be cleared in software)
}
void INT1_init(void)
{
INTCON3bits.INT1E=1;
INTCON3bits.INT1F=0; //1 = The INT1 external interrupt occurred (must be cleared in software)
}
void USB_init(void)
{
PIE2bits.USBIE = 1; //USB Interrupt Enable bit
UCFGbits.FSEN = 1; //Full Speed Enable bit
UCFGbits.UPUEN = 1; //USB On-Chip Pull-up Enable
UCFGbits.UTRDIS= 0; // On-Chip Transceiver Disable bit
UCONbits.USBEN = 1; //USB Module Enable bit
}
void init(void)
{
port_init();
INT0_init();
INT1_init();
USB_init();
}
void main(void)
{
bit ch1=0;
bit ch2=0;
init();
.............................................
}