|
|
View previous topic :: View next topic |
Author |
Message |
June Guest
|
Any problem with my touch switch program? |
Posted: Mon Dec 02, 2002 6:32 am |
|
|
Dear all,
I got an interesting touch switch program from:
<a href="http://www.bytecraft.com/touchsw.html" TARGET="_blank">http://www.bytecraft.com/touchsw.html</a>
I convert it for my PIC16F876 (4MHz). Suppose my PIN_B7 is connected to a resistor of 820Kohm. Then I layout a wire for touch sensing. However the program only light on 0x55 then OFF. It seems like the following programs doesn't executed. Because no signal pattern on (NOT 0XFF AND OXAA).
Does anybody know what's wrong with it? Can we set portb as output and then set it as input for PIC16F876? Thanks a lot.
#include <16f876.h>
#use delay(clock=4000000) //4mhz oscillator
#fuses xt,noprotect,nowdt,nolvp
#byte PORTB=6
main()
{
int i;
set_tris_b(0); //set pin b0-b7 as output
portb=0x55;
delay_ms(1000);
portb=0; //discharge all pins
delay_ms(1);
set_tris_b(0xff); //set pin b0-b7 as input
delay_us(5);
if(input(PIN_B7)) //if touch pad touched
{
portb=0xff;
}
else
{
portb=0xAA;
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 9678 |
|
|
R.J.Hamlett Guest
|
Re: Any problem with my touch switch program? |
Posted: Mon Dec 02, 2002 7:05 am |
|
|
:=Dear all,
:=
:= I got an interesting touch switch program from:
:= <a href="http://www.bytecraft.com/touchsw.html" TARGET="_blank"> <a href="http://www.bytecraft.com/touchsw.html" TARGET="_blank">http://www.bytecraft.com/touchsw.html</a></a>
:=
:= I convert it for my PIC16F876 (4MHz). Suppose my PIN_B7 is connected to a resistor of 820Kohm. Then I layout a wire for touch sensing. However the program only light on 0x55 then OFF. It seems like the following programs doesn't executed. Because no signal pattern on (NOT 0XFF AND OXAA).
:=
:= Does anybody know what's wrong with it? Can we set portb as output and then set it as input for PIC16F876? Thanks a lot.
:=
:=#include <16f876.h>
:=#use delay(clock=4000000) //4mhz oscillator
:=#fuses xt,noprotect,nowdt,nolvp
:=#byte PORTB=6
:=main()
:={
:= int i;
:= set_tris_b(0); //set pin b0-b7 as output
:=
:= portb=0x55;
:= delay_ms(1000);
:= portb=0; //discharge all pins
:= delay_ms(1);
:=
:= set_tris_b(0xff); //set pin b0-b7 as input
:= delay_us(5);
:=
:= if(input(PIN_B7)) //if touch pad touched
:= {
:= portb=0xff;
:= }
:= else
:= {
:= portb=0xAA;
:= }
:=
:=}
Add the line #use fast_io(B) to your setup.
I haven't looked at the details of what you are trying to do, but unless this is present, the CCS C, will be still trying to control the TRIS register for the port. When you do the 'input' instruction (which is the only one that uses the CCS port I/O code), it will set the TRIS register to input, and override your own settings.
Also have something to stop the code running off the end. At the moment, the code will execute just once, and then go to sleep. If you want it to keep watching the input, you need to have a loop containing the code...
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9680 |
|
|
|
|
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
|