PDA

View Full Version : PIC never reacts to Button



AlfonsoB
- 30th November 2008, 12:34
Hello everybody,

I have worked on this programme to select between two PWM values on PortB + display and by pressing a button on PORTA.0.

Unfortunately, and after pressing the button I don't get the change I want. I tried a lot but no success. I need a generous help.

Here is the code:

'PWM

include "modedefs.bas"
DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 0 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 5 'Define PIC prot used for E line of LCD
DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 4 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 4 'Define using a 4 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent
W0 var word


ADCON1=7
TRISA=1

TRISB=0
PORTB=0
PORTA=0
'W0=0
'W0=PORTA.0

loop:
if PORTA.0 then
LCDOUT $FE,1,"PWM1",#W0," "
pwm PORTB.6,127,100


else
LCDOUT $FE,1, "PWM2",#W0," "
pwm PORTB.7,127,100
endif

goto loop

END

Many thanks in advance.

Pic2008
- 30th November 2008, 12:49
Do you have a pull up resistor to RA.0?

Try putting a pause 1000 to see the changes before goto loop.

Acetronics2
- 30th November 2008, 12:58
Hi,

The problem could be ... at first, once you release you button ... value comes back to the default.

you ,may be, have to memorize the last button press action ...


Now ... dependinding on your PIC ( BTW ... Which one do you use ??? ) PortB.6 and 7 can be shared with ADC, ( ADCON1 <> 7 !!! ) , clock ... or sthg else.

Osc settings are also necessary to understand how your circuit is REALLY working ...

Your scheme could be useful, in the end, to see if any pulldown on your inputs ...

Alain

AlfonsoB
- 30th November 2008, 16:44
Hi again
Thanks a lot for the reply and to all,

I use the pic16f876, PortB outputs an LCD pins 0 to 5, pulse out are on 6 and 7.
PORTA.0 input where a button with a 10 K pull up resistor connected.
No master clear connection.

But even with or without pull ups or master clears nothing changes. I think I have to learn how to activate or disable internal pullups too.

I'll consider your remarks and try them out and come back later.

Regards

Alfonso