PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 24, 2011 3:11 pm |
|
|
I modified the program and now it works. The LED flashes when the
program starts. Then when you push a button on pin B4, the LED will
flash again. The main problem is that in vs. 4.119, the IOCB register
address is incorrect.
Code: |
#include <18F45k22.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,BROWNOUT,PUT,MCLR, BORV27,NOPBADEN
#use delay(clock=4000000)
#define LED_RT PIN_B0
#define X_SPUR_A PIN_B4
void setup_IOCB(int8 mask)
{
#byte IOCB = 0xF62 // Register address for 18F45K22
IOCB = mask;
}
//----------------------------
void flash_led(void)
{
int8 j=0;
for(j=0; j<10;j++)
{
output_toggle(LED_RT);
delay_ms(100);
}
}
//------------------------------
#int_rb
void IRQ_XY(void)
{
int temp;
flash_led();
temp = input(PIN_B4); // To clear mismatch condition
}
//============================================
void main()
{
int temp;
output_low(LED_RT); // LED is initially Off
port_b_pullups(0x10); // Enable pull-up on pin B4 only
temp = input(PIN_B4); // Read Pin B4 to clear mismatch condition
clear_interrupt(INT_RB);
enable_interrupts(INT_RB4); // Enable int-on-change for pin B4 only
setup_IOCB(0x10); // *** Fixes bug with ASM code for line above
enable_interrupts(GLOBAL);
flash_led();
while(1);
} |
|
|