|
|
View previous topic :: View next topic |
Author |
Message |
just4ho Guest
|
problem with int_rb |
Posted: Thu Sep 28, 2006 2:58 am |
|
|
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: 1909
|
|
Posted: Thu Sep 28, 2006 7:24 am |
|
|
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. |
|
|
|
|
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
|