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 support@ccsinfo.com

problem with int_rb

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







problem with int_rb
PostPosted: Thu Sep 28, 2006 2:58 am     Reply with quote

I have problem with int_rb. I have tested the following code with 16f877 and worked fine. But when I tryed it with 18f4550 it didnt work. what is the problem? The cuircuit was exactly the same. the only change I have made is the first line of the code. I changed "#include <16F877A.h>" to " #include <18F4550.h>"
can any one tell me what is wrong with the code?



#include <18F4550.h>
#fuses NOWDT,PUT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(b)
#byte portb=0x06
#byte intcon=0x000B
#bit RB4=portb.4
#bit RB5=portb.5
#bit RB6=portb.6
#bit RB7=portb.7
#bit RBIF=intcon.0 //dinh nghia co ngat RB
#bit RBIE=intcon.3 //dinh nghia bit cho phep ngat RB
int led=0,speed;
// Chuong trinh ngat
#int_RB
void ngat_RB()
{
if((RBIF)&&(RBIE))
{
//Kiem tra sw1
{
if(RB4==0)
{
led=0b00000001; //led1 sang
speed=250;
}
}
//Kiem tra sw2
{
if(RB5==0)
{
led=0b00000011; //led1,2 sang
speed=200;
}
}
//Kiem tra sw3
{
if(RB6==0)
{
led=0b00000111; //led1,2,3 sang
speed=150;
}
}
//Kiem tra sw4
{
if(RB7==0)
{
led=0b00001111; //led1,2,3,4 sang
speed=100;
}
}
RBIF=0; //Xoa co ngat RB
}
}
// Chuong trinh chinh
main()
{
set_tris_b(0b11110000);
portb=0b00001111;
enable_interrupts(global);
enable_interrupts(int_RB);
ext_int_edge(H_to_L);
while(true)
{
portb=led;
delay_ms(speed);
portb=0;
delay_ms(speed);
}
}
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Thu Sep 28, 2006 7:24 am     Reply with quote

Download the datasheet for the 18F4550 and look at the "memory organization" section. Specifically, look at the memory map for the "special function registers".

The problem is that the register for port B is at memory location 0x06 for the 16F family, but is located at a different address in the 18F family.
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