PDA

View Full Version : Some help needed (newb content)



Woogle
- 2nd September 2009, 09:06
Hello,

Ok, I've been programming in Ass for a while, and now have seen the light.
Simple prog to flash an led if a button is pressed.

Code follow:
-----------------------------------------------------------------------------------------------------
@ DEVICE pic16F819

@ DEVICE INTRC_OSC_NOCLKOUT

@ DEVICE CPD_OFF



Define OSC 8 'Osciallator 8Mhz

OSCCON=112 'INT OSC 8 MHZ

ADCON0 = 0

CCP1CON = %00000000 'Turn comparators off

Trisa=%00000001 'Sets PortA RA0 and RA1 as ip rest as output.

CoolHeat Var PORTA.0 'Switch IP High=flash

RL1 Var PORTA.1 'Relay output









Start:

If CoolHeat=0 THen 'button not pressed

HIGH RL1

endif



If Coolheat=1 Then 'button pressed flashes LED

high rl1

pause 500

Low RL1

Pause 500

high rl1

pause 500

Low RL1

Pause 500

Endif



goto Start



end

-------------------------------------------------------------------------------------------------

The switch is pulled up via 4k7 to Vcc. LED has 330r in series.

When I power up the led is on as it should be, switch is open.
When I pull RA.0 high the led *should* flash but does not.

Any ideas?

Many thanks.

Acetronics2
- 2nd September 2009, 09:28
Hi,

May be you forgot one I/O config line ...

ADCON1 i.e.

Alain

Woogle
- 2nd September 2009, 10:18
All sorted,

loose power connection to PIC plus added the code detailed.

Full steam ahead now!

jellis00
- 9th September 2009, 04:02
Trisa=%00000001 'Sets PortA RA0 and RA1 as ip rest as output.


Your Trisa statement only sets RA0 as in input. Your comment says you want to also set RA1 as input. Therefore you need TRISA = %00000011 .