Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with the switch button RB6 in the PIC16F877a

Status
Not open for further replies.

One Person

Newbie level 2
Joined
Mar 31, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,303
Hi all
I should implement a program using C language to sample the LDR and potentiometer values I faced a problem when I want to select the sampling time on the LCD I write an if statement so if RB6 is pressed the sampling time should be moved from 1 to 10 and when I release the button the selected value should appear on the LCD I enabled the RBIE (Bits 4-7 in portB interrupt) because I should use it in a part of the program.
The problem is that the sampling time keeps moving on the LCD even if I did not press RB6 I used RB7 to check and it is work fine (sampling time move when I press RB7 and stop when I release it) does anyone have an idea why the same code work with RB7 but does not work with RB6?

if (RB6==1)
{
del(1);
x++; // Counter for holding the sampling time value

if(x>10)
x=1;
}

Best Regards
 

if(RB6_bit==0)
{
delay_ms(10);
if(RB6_bit==0)
{
del(1);
x++;
if(x>10)
{
x=1;
}

while(RB6_bit==0)
{
}


}

}


about why rb7 work and rb6 no ..... may be you need to check TRISB=1; as input or TRISB=0b1111111;
 

is the RB6 pin left floating when the switch is not pressed..?
if yes then use a pull up or pull down resistor according to your circuit...
if checking high then pull down else pull up....

hope this helps..
 

Thanks it works even when I return to the same code that make the problem I did not know what is the problem before but I faced another problem with the LCD number when I release RB6 the number that shown on the LCD incremented by 1 so how can I keep the same number appearing on the LCD (I mean if I release RB6 and the number that is on the LCD is 4 it should stay 4 but in my case it become 5)

while(1)
{
if (RB6==1)
{
del(3);
x++;
if(x>10)
x=1;
}
LCD_cursor(7,1); // function to move the cursor position
LCD_display_value(x); // function to display the x value on the LCD
}
 

your code logic is
when RB6 is clicked or (physically saying when connected to Voltage source )
Then
delay 3 (if del == delay as i think)
then increase variable
check if x>10 then put x=1
put cursor at 7,1 >> where is 7,1 in LCD ?? <<<
display X (x is incremented above so of course the number will be incremented in it)



what is the number you need to display in LCD represent ...
if you need to display numbers don't depend in X variable remove x from your function
like in MikroC
lcd_out(1,7,0x34);
 

Hi One Person,

I am a student at Queen Mary University of London, doing similar kind of project like yours in my design and build module. I need your help in programming PIC microcontroller. Can you please send me your code so that I can take help from it?

Many thanks,

Imran
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top