PDA

View Full Version : I thought it was like riding a bike... Help please! 16f630 config



rossfree
- 9th February 2012, 14:45
I'm trying to write a very simple program but can't get off the ground. I don't read data sheets very well though I have spent hours trying. Much of it simply goes over my head. I feel sure that I'm not setting the chip up properly for digital I/O. Once I get the settings right I think I'm off and running. I've been very successful before with this but it has been a while and this is a new chip for me.

The code below is intended to turn on LEDs and leave them on. What happens is that the first LED turns on, then goes OFF as the second LED turns on. Then the second LED turns off as the third turns on. It then stays on as the next two turn on and stay on (as I expect it to). So the end result is the first two LEDS are off and the last three are on.

I suspect that PortA is not configured correctly. Can someone please help me.

Thank you!!!

Ross



@_config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF
ANSEL = 0
CMCON = 7
ADCON1 = 7
TRISA = %111000
TRISC = %111000
porta = 0
portc = 0

Push var porta.4
'************************************************* ******************************
Start: while Push = 1 ' Wait for button push
wend



Run: High porta.0 ' Turn on LED on each port every two seconds
Pause 2000
High porta.1
Pause 2000
high porta.2
pause 2000
high portc.0
pause 2000
high portc.1

End

AvionicsMaster1
- 9th February 2012, 15:33
Shouldn't it be ADCON0=0? This will turn the comparators off. ADCON1=7 doesn't do anything.

What I see is that none of your LEDs will turn off.

If you want LED 1 on wait two seconds then off, then the same for LED 2, then LED 3 on stay on, LED 4 on stay on, then pause and all off it should look like:

(Just the main program)

RUN:
high porta.1 ' led 1 on
pause 2000
low porta.1 'led 1 off
pause 2000
high porta.2 'led 2 on
pause 2000
low porta.2 'led2 off
pause 2000
high portc.0 'led3 on
pause 2000
high portc.1 'led4 on
pause 2000
low portc 'led3 and led4 off
end

Is this getting to more of what you want?
There are more elegant ways to do this but this is the simplest to read.

rossfree
- 9th February 2012, 15:43
Hi,

Thank you for your response!

I want all of the LED's to stay ON. But the first two turn off. I don't understand why. I suspect I need to do something to PORTA that I have not done. PORTC is working fine.

Thoughts?

Ross

rossfree
- 9th February 2012, 16:09
I got it working. Here's the code I used:

CMCON = 7
TRISA = %111000
TRISC = %111000
porta = 0
portc = 0

Push var porta.4
'************************************************* ***************
Start: while Push = 1 ' Wait for button push
wend



Run: High porta.0 ' Turn on LED and leave it on
Pause 2000
High porta.1 ' Turn on LED and leave it on
Pause 2000
high porta.2 ' Turn on LED and leave it on
pause 2000
high portc.0 ' Turn on LED and leave it on
pause 2000
high portc.1 ' Turn on LED and leave it on

End

I thought I also had to set ANSEL but Microcode Studio balks at me for it. :-P I'm trying!

Thank you!

Ross

ScaleRobotics
- 10th February 2012, 00:12
I thought I also had to set ANSEL but Microcode Studio balks at me for it. :-P I'm trying!


The PIC16F630 has no ADC, so no analog selections are available. That's why it was balking at you. :)