|
|
View previous topic :: View next topic |
Author |
Message |
almoba_2010
Joined: 17 Jan 2011 Posts: 3
|
I can not go outside of the #int_rb routine pic16f1827 |
Posted: Tue Jan 18, 2011 11:57 am |
|
|
Hello, I am a beginner on the forum.
My problem is next. I can not go out side of this routine. My version of ccs is 4.116 the pic is 16f1827.
Code: |
#int_RB
RB_isr()
{
int x;
x=b_port;
iocbf=0; //
iocif=0; //from intcon register
iocie=0; //from intcon register
}
|
Thanks for your help, and salutes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 18, 2011 12:15 pm |
|
|
Quote: | x=b_port;
iocbf=0; //
iocif=0; //from intcon register
iocie=0; //from intcon registe |
Post your declarations for all these variables. |
|
|
almoba_2010
Joined: 17 Jan 2011 Posts: 3
|
|
Posted: Tue Jan 18, 2011 2:10 pm |
|
|
Sorry. I will put all the program.
Code: |
#include <16F1827.h>
#device *=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES WDT_SW
#FUSES PUT //Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES PROTECT //Code protected from reads
#FUSES NOCPD //No EE protection
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOCLKOUT
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOWRT //Program memory not write protected
#FUSES PLL
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES BORV19
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(int=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,bits=8,stream=PORT1)
#use fast_io(A)
#use fast_io(B)
//pto a
#byte trisa = 0x8c
#byte a_port = 0x0c
//bits porta
#bit sdi=0x0c.0 //0
#bit nsel=0x0c.1 //0
#bit fsk=0x0c.2 //0
#bit rf_dat=0x0c.3 //0
#bit on_laipac=0x0c.4 //0
#bit nirq=0x0c.5 //1
#bit led=0x0c.6 //0
#bit sck=0x0c.7 //0
//pto b controlling a keypad 3x4 using de pull ups on rb4, rb5, rb6
#byte trisb = 0x8d
#byte b_port = 0x0d
//bits portb
#bit y1=0x0d.0 //0
#bit y2=0x0d.1 //0
#bit y3=0x0d.2 //0
#bit y4=0x0d.3 //0
#bit x3=0x0d.4 //1
#bit x2=0x0d.5 //1
#bit x1=0x0d.6 //1
#bit RS_DAT=0x0d.7 //0
//habilitando para interrupciones con
//flanco de bajada
#byte iocbp = 0x394 //dandolo de alta
#byte iocbn = 0x395 //dandolo de alta
#byte iocbf = 0x396 //dandolo de alta
#byte intcon= 0x0b //dandolo de alta
#bit iocie= 0x0b.4
#bit iocif= 0x0b.0
//*********INCIO DE ALTA DE FUNCIONES Y VARIABLES***************
int orale;
void config();
//*********FIN DE ALTA DE FUNCIONES Y VARIABLES***************
//inicio de interrupcion de cambio en nible alto de rb
#int_RB
RB_isr()
{
orale=b_port;
iocbf=0; //del registro individual de banderas
iocif=0; //del registro del intcon
iocie=0; //del registro del intcon
}
//fin de interrupcion de cambio en nible alto de rb
void main()
{
config();
led=1;
delay_ms(150);
led=0;
while (true)//leyendo el teclado.
{
y1=0;//res, min, pl
if(x1==0)//res?
{
led=1;
delay_ms(200);
led=0;
}
if (x2==0)// min?
{
led=1;
delay_ms(150);
led=0;
}
if (x3==0)// pl
{
led=1;
delay_ms(150);
led=0;
}
y1=1;
y2=0;//on, seg, fl
if(x1==0)// on
{
led=1;
delay_ms(150);
led=0;
}
if (x2==0)// seg
{
led=1;
delay_ms(150);
led=0;
}
if (x3==0)// fl
{
led=1;
delay_ms(150);
led=0;
}
y2=1;
y3=0;//per, pau, fv
if(x1==0)//per
{
led=1;
delay_ms(150);
led=0;
}
if (x2==0)//pau
{
led=1;
delay_ms(150);
led=0;
}
if (x3==0)//fv
{
led=1;
delay_ms(150);
led=0;
}
y3=1;
y4=0;//dec, ent, pv
if(x1==0)//dec
{
led=1;
delay_ms(150);
led=0;
}
if (x2==0)//ent
{
led=1;
delay_ms(150);
led=0;
}
if (x3==0)//pv
{
led=1;
delay_ms(150);
led=0;
}
y4=1;
y1=0;
y2=0;
y3=0;
y4=0;
sleep();
orale=b_port;
y1=1;
y2=1;
y3=1;
y4=1;
}
}
//***********INICIO DE EDICION DE FUNCIONES*****************
//*********************************
//** CONFIGURA HARDWARE DEL MICRO**
//*********************************
void config()
{
port_b_pullups(TRUE);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_PLL_OFF,0);
a_port=0;
b_port=0;
port_b_pullups(TRUE);
trisa=0x20;
trisb=0x70;// leemos con el bit rb4,rb5 y rb6
delay_ms(50);// necesarios para es start up de rfhope
y1=1;
y2=1;
y3=1;
y4=1;
enable_interrupts(INT_RB);
iocbp = 0x00; // do not use the rise edge on any.
iocbn = 0x70; //unsing falling edge on rb4, rb5, rb6
enable_interrupts(GLOBAL);
}
|
Thanks for your quick answer. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 18, 2011 2:59 pm |
|
|
Quote: | port_b_pullups(TRUE);
|
This is not correct.
The 16F1827 doesn't use True/False as the parameter in port_b_pullups().
Each pull-up on each pin can be individually enabled or disabled in this PIC.
You need to use a bitmask as the parameter. For example, to enable
pull-ups on bits 0 and 3 of PortB, you would do this:
Code: | port_b_pullups(0x09); |
or
Code: | port_b_pullups(0b00001001); // in binary |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Jan 18, 2011 3:56 pm |
|
|
Several comments:
1) Correct the tris as PCM points out. Presumably 0x70.
2) Setup the interrupt edge, before enabling the interrupt.
3) Then read port_b, and clear the interrupt before enabling it. Otherwise the flag may well already be set.
4) You appear to only want the interrupt to wake you from sleep. To do this, you don't have to enable_interrupts(GLOBAL), or have an interrupt handler at all.
5) Add a NOP after the sleep (delay_cycles(1)). The instruction following the sleep, is 'prefetched' when you go to sleep, and may not execute as you expect.
So:
Code: |
iocbp = 0x00; // do not use the rise edge on any.
iocbn = 0x70; //using falling edge on rb4, rb5, rb6
//These can be in the config
orale=b_port;
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
//However, do these as the last things before sleeping
sleep();
delay_cycles(1);
disable_interrupts(INT_RB);
//This is really 'unnecessary', unless you are using any other interrupts
orale=b_port;
|
Best Wishes |
|
|
almoba_2010
Joined: 17 Jan 2011 Posts: 3
|
|
Posted: Tue Jan 18, 2011 5:21 pm |
|
|
Firstly, thanks to all, for your quick answer.
Then, I am still having the problem. I did the changes that you suggested, but, Ttelmah, I do not why but if I setup the interrupt edge before enabling the interrupt, it changes to FFh, both. So I am going to leave as before.
I forgot to say you that I am using the MPLAB SIM. For that reason I see the register's values.
The code stay like that:
Code: |
#include <16F1827.h>
#device *=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES WDT_SW
#FUSES PUT //Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES PROTECT //Code protected from reads
#FUSES NOCPD //No EE protection
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOCLKOUT
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOWRT //Program memory not write protected
#FUSES PLL
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES BORV19
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(int=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,bits=8,stream=PORT1)
#use fast_io(A)
#use fast_io(B)
//pto a
#byte trisa = 0x8c
#byte a_port = 0x0c
//bits porta
#bit sdi=0x0c.0 //0
#bit nsel=0x0c.1 //0
#bit fsk=0x0c.2 //0
#bit rf_dat=0x0c.3 //0
#bit on_laipac=0x0c.4 //0
#bit nirq=0x0c.5 //1
#bit led=0x0c.6 //0
#bit sck=0x0c.7 //0
//pto b controlling a keypad 3x4 using de pull ups on rb4, rb5, rb6
#byte trisb = 0x8d
#byte b_port = 0x0d
//bits portb
#bit y1=0x0d.0 //0
#bit y2=0x0d.1 //0
#bit y3=0x0d.2 //0
#bit y4=0x0d.3 //0
#bit x3=0x0d.4 //1
#bit x2=0x0d.5 //1
#bit x1=0x0d.6 //1
#bit RS_DAT=0x0d.7 //0
//habilitando para interrupciones con
//flanco de bajada
#byte iocbp = 0x394 //dandolo de alta
#byte iocbn = 0x395 //dandolo de alta
#byte iocbf = 0x396 //dandolo de alta
#byte intcon = 0x0b //dandolo de alta
#bit iocie = 0x0b.4
#bit iocif = 0x0b.0
//*********INCIO DE ALTA DE FUNCIONES Y VARIABLES***************
int orale;
void config();
//*********FIN DE ALTA DE FUNCIONES Y VARIABLES***************
//inicio de interrupcion de cambio en nible alto de rb
#int_RB
RB_isr()
{
orale=b_port;
iocbf=0; //del registro individual de banderas
iocif=0; //del registro del intcon
iocie=0; //del registro del intcon
}
//fin de interrupcion de cambio en nible alto de rb
void main()
{
config();
led=1;
delay_ms(150);
led=0;
while (true)//leyendo el teclado.
{
if(x1==0)//res?
{
led=1;
delay_ms(200);
led=0;
}
if (x2==0)// min?
{
led=1;
delay_ms(150);
led=0;
}
if (x3==0)// pl
{
led=1;
delay_ms(150);
led=0;
}
sleep();
delay_cycles(1);
delay_cycles(1);
orale=b_port;
}
}
//***********INICIO DE EDICION DE FUNCIONES*****************
//*********************************
//** CONFIGURA HARDWARE DEL MICRO**
//*********************************
void config()
{
port_b_pullups(0x70);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_PLL_OFF,0);
a_port=0;
b_port=0;
port_b_pullups(TRUE);
// trisa=0x20;
// trisb=0x70;// leemos con el bit rb4,rb5 y rb6
set_tris_a (0x20);
set_tris_b (0x70);
delay_ms(50);// necesarios para es start up de rfhope
y1=1;
y2=1;
y3=1;
y4=1;
iocbp = 0x00; // do not use the rise edge on any.
iocbn = 0x70; //unsing falling edge on rb4, rb5, rb6
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
orale=b_port;
iocbf=0;
} |
|
|
|
|
|
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
|