CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with #int_ext

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dbrown



Joined: 24 Jul 2004
Posts: 20

View user's profile Send private message

Problem with #int_ext
PostPosted: Sat Jan 07, 2006 7:22 pm     Reply with quote

I have been trying to read the value on port B when an interrupt has occurred on int_ext. I set the flag ext_flag in the ISR when the interrupt occurs. In the main loop I read the port, however I am not seing what I expect. I have b0-b3 tied to ground with 1k resisters, but I keep reading either 16 or 17 when the program executes. I do not understand how it can be reading 16 or 17 since I have set_tris_b(0xf), should it not only be reading bits 0 to 3?

I am using a 18F4550 @ 4 MHz

Any help would be appreciated.

Thanks

Dave Brown

The code is shown below:
Code:

#include <18f4550.h>
#use delay (clock=4096000)
#fuses xt,nowdt,NOPUT,noprotect,nolvp
#USE RS232(BAUD=9600, XMIT=PIN_c6, RCV=PIN_c7,DISABLE_INTS)
int ext_flag;


#int_ext
test_int(){
ext_flag=1;
}




main(){
enable_interrupts(global);
enable_interrupts(int_ext);
set_tris_b(0x0f);
ext_int_edge(l_to_h);

while(1){
if(ext_flag==1){
printf("Port b %u\r\n",input_b());
ext_flag=0;
enable_interrupts(global);
}


}
}
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Jan 07, 2006 7:43 pm     Reply with quote

When you read the port you get the whole 8 bits. If you have a high impednace load on the output pins (say 1K) then you will read the value you have written. However if you have a low impedandance on the output (say 300R), the voltage on the output pin will be much lower (typical output characterists of the driver) and could be less than half VDD. Then means when you read the output port this pin may read the opposite to what you expect.

It is up to you to mask the unwanted bits when reading a port.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Jan 07, 2006 8:53 pm     Reply with quote

Quote:

I have b0-b3 tied to ground with 1k resisters


After Power on, B0..B4 wake up as analog inputs.
You can select this setting/clearing the PBADEN bit in ADCON1 register.

To do it using the CCS built in function:
Code:

   setup_adc_ports(NO_ANALOGS); // set digital inputs
   setup_adc(ADC_OFF);          // switch of the ADC module.


Quote:

should it not only be reading bits 0 to 3?

NOP. You only enabled INT_EXT. The interrupt will be triggered only by an edge in PB0.
If you want the interrupt being triggered by PB1 you must enable INT_EXT1 and code the handler.
If you want the interrupt being triggered by PB2 you must enable INT_EXT2 and code the handler.
or change the inputs prior to trigger the enabled PIN.

To test the external interrupt capabilities, the easy way is to enable the built in pull ups resistors
in PortB and driving them against Gnd. Remember to change the interrupt edge from L_H to H_L.
Code:

     portb_pull_ups(TRUE);
     ext_int_edge( H_TO_L );   
     enable_interrupts(INT_EXT);
     enable_interrupts(GLOBAL);



keep well,

Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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