Hi I am having trouble activating the digital input on my PIC16F690. I use the LPC-demo board from microchip and the PICkit2 programmer. I have tried this code with Great cow graphical basic:
DIR PORTA.3 in
IF PORTA.3 = 1
THEN
PORTC.0 out
set PORTC.0 on
ENDIF
What am I missing? I've also tried using the assembler generator and adding the code to MPLAB and also adding the PIC16F690.INC file to it before sending it to the programmer.
Any help would be greatly appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What happens if you use a single Set PORTC.0 On icon, without the If or the Dir icons?
If that still doesn't work, can you post your entire program here? (To do this, click View and then View as Text, and copy and paste everything there.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Okay. Back again. Sorry for not replying for a while, but been busy with my applications to Art schools here in Sweden.
As far as I can see, it still just lights up the diode on my LPC board right from the start. I tried the single port on
command as well. The problem is that the thing don't answer when i press the button. Either the diode is lit from the start or it doesn't turn on at all. Nothing happens when i press the button. Nothing at all. The strange thing is that microchips demo programs that involves the button works just fine.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The LPC board is a great way to get familiar with Pics. Getting comfortable with a language syntax always take some getting used to.
The MCLR button or PortA.3 is pulled up to VDD with a 10k resistor, as it is an input only pin. So from that standpoint, pressing the MCLR button will ground that pin or create a "0" and that's what should be tested for in the code. Also it's always good to debounce the button in software for a glitch free transition.
This code may look a little long winded, but should do the job properly.
#chip 16F690, 4
#config Osc = INTRC_OSC_NOCLKOUT
'Port setting
#define LED1 PortC.0
#define Button PortA.3
dir LED1 out
dir Button in
toggle = 1
Set LED1 On
wait 1 s
Main:
If Button Off Then
Debounce_Button
If ButtonCount > 3 then toggle = !toggle
End if
If toggle = 1 Then
Set LED1 On
Else
Set LED1 Off
End if
wait 100 ms
goto Main
Sub Debounce_Button
ButtonCount = 0
Do While Button off
wait 10 ms
ButtonCount += 1
Loop
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hmm… Another silly question: if I want to change the action done by the button, so that a variable pwm is emitted on PORTC.0
instead of simply just turning the led on, what i sthe best way to do that? I tried using a subroutine instead of the Set LED1 command, but the subroutine doesn't quit when button is pressed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would start over on the code for changing the pwm output on the LED. Check out the pwm modules first, by following examples in the help files. Then try decrementing/incrementing the duty cycle variable in a Do While Loop.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi I am having trouble activating the digital input on my PIC16F690. I use the LPC-demo board from microchip and the PICkit2 programmer. I have tried this code with Great cow graphical basic:
DIR PORTA.3 in
IF PORTA.3 = 1
THEN
PORTC.0 out
set PORTC.0 on
ENDIF
What am I missing? I've also tried using the assembler generator and adding the code to MPLAB and also adding the PIC16F690.INC file to it before sending it to the programmer.
Any help would be greatly appreciated.
What happens if you use a single Set PORTC.0 On icon, without the If or the Dir icons?
If that still doesn't work, can you post your entire program here? (To do this, click View and then View as Text, and copy and paste everything there.)
Okay. Back again. Sorry for not replying for a while, but been busy with my applications to Art schools here in Sweden.
As far as I can see, it still just lights up the diode on my LPC board right from the start. I tried the single port on
command as well. The problem is that the thing don't answer when i press the button. Either the diode is lit from the start or it doesn't turn on at all. Nothing happens when i press the button. Nothing at all. The strange thing is that microchips demo programs that involves the button works just fine.
The LPC board is a great way to get familiar with Pics. Getting comfortable with a language syntax always take some getting used to.
The MCLR button or PortA.3 is pulled up to VDD with a 10k resistor, as it is an input only pin. So from that standpoint, pressing the MCLR button will ground that pin or create a "0" and that's what should be tested for in the code. Also it's always good to debounce the button in software for a glitch free transition.
This code may look a little long winded, but should do the job properly.
Thank you very much! I think this will work!
Hmm… Another silly question: if I want to change the action done by the button, so that a variable pwm is emitted on PORTC.0
instead of simply just turning the led on, what i sthe best way to do that? I tried using a subroutine instead of the Set LED1 command, but the subroutine doesn't quit when button is pressed.
I would start over on the code for changing the pwm output on the LED. Check out the pwm modules first, by following examples in the help files. Then try decrementing/incrementing the duty cycle variable in a Do While Loop.