|
|
View previous topic :: View next topic |
Author |
Message |
salgulsen
Joined: 16 Sep 2009 Posts: 21
|
using interrupt spi1 with button.c |
Posted: Sat Feb 13, 2010 9:55 am |
|
|
Hi,
I'm trying to use button command that is in code library with the int_spi1 of dspic30f4013. But it doesnt work quite correctly. Here is my code :
Code: |
#include <30F4013.h>
#FUSES NOWDT, HS, PR, NOCKSFSM, WPSB16, WPSA512, PUT64, NOBROWNOUT, BORV47, LPOL_HIGH, HPOL_HIGH, NOPWMPIN, MCLR, NOPROTECT, NOWRT, NODEBUG, NOCOE, ICSP1, RESERVED
#use delay(clock=20000000)
#include <button.c>
#byte SPI1BUF = 0x224 // Register address for dspic30f4013
int8 resp=0,B0,B1,B2,B3,sendit=0x00,counter;
#int_spi1
void spi1_isr(void)
{
int8 command;
command = SPI1BUF;
switch (command){
case 0xFF: SPI1BUF = 0;
break;
case 0xFE: SPI1BUF = sendit;
break;
case 0xFD: resp++;
SPI1BUF = resp;
break;
}
}
void main()
{
int1 menubut,upbut,downbut,selbut,startbut,stopbut,bolusbut;
int8 cnt,anl81=0,anl82;
int16 anl16=0;
//int16 TRISDE;
setup_spi(spi_slave | spi_L_to_H);
clear_interrupt(INT_SPI1);
enable_interrupts(INT_SPI1);
setup_wdt(WDT_OFF);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
//TRISDE = GET_TRIS_D();
//TRISDE = TRISDE && 65279;
//Set_TRIS_D(TRISDE);
while(1)
{
//menubut = input(pin_b0);
//upbut = input(pin_b1);
//downbut = input(pin_b3);
//selbut = input(pin_b4);
menubut = button(pin_b0,0,100,50,B0,1);
upbut = button(pin_b1,0,100,50,B1,1);
downbut = button(pin_b3,0,100,50,B2,1);
selbut = button(pin_b4,0,100,50,B3,1);
if(menubut){
bit_set(sendit,0);
}else{
bit_clear(sendit,0);
}
if(upbut){
bit_set(sendit,1);
}else{
bit_clear(sendit,1);
}
if(downbut){
bit_set(sendit,2);
}else{
bit_clear(sendit,2);
}
if(selbut){
bit_set(sendit,3);
}else{
bit_clear(sendit,3);
}
delay_ms(10);
}
}
|
By the way if I use input(pin) command that are slashed out in code instead of the button commands, it works. I just want to suppress the buttons while I'm using the interrupts.
Thanks in advance. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 13, 2010 12:25 pm |
|
|
The button.c code was written and tested only with the PCM and PCH
compilers (for 16F and 18F PICs). Also, it was written back in version 3
of the compiler (at about vs 3.229). With that version, the input()
function would not take a variable for the PIN number. It required a
constant. So I wrote a macro that would accept a variable pin number.
(Note: Vs. 4 of the compiler allows variables for the input() function).
If you look at the button.c code, you'll see this macro:
Code: | #define read_bit_var(x) bit_test(*(int8 *)(x >> 3), x & 7) |
This macro probably doesn't work with the PCD compiler. I don't have
that compiler, so I don't know for sure. But there I believe there is a
work-around. Edit the button.c file. Comment out the call to the
read_bit_var() function, and add a call to the input() function, as shown
below. See if that fixes the problem with PCD.
Code: |
int8 button(int16 pin, int8 downstate, int8 delay,
int8 rate, int8 &BVar, int8 action)
{
int8 pin_value;
// Read the button pin.
//pin_value = read_bit_var(pin); // *** Comment out this line
pin_value = input(pin); // *** Add this line |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|