PDA

View Full Version : Extreme Noobie question 12F675



Jeff
- 22nd June 2008, 17:29
Hey, I am trying to learn how to use the button command but I have not been able to get it to work. My workaround is not working either. What I want to do is start the flashing loop on GP0 after the button on GP1 is pushed. I think my problem is in the Loop1 but I dont know how to fix it. It just goes directly to flash loop2.

Can anyone show me how to do this using the button command? I will keep trying but it just passes it right up.

Thanks,

Jeff






'INITIALIZE PINS and PORTS:

SYMBOL ANSEL = $9F '$19 IS ANSEL REGISTER
POKE ANSEL, 0 'MAKE PIN DIGITAL, NOT ANALOG

SYMBOL ADCON0 = $1F 'TURN OFF A/D ON PIN4. (DEFAULT IS ON)
POKE ADCON0, 254 '$1F IS ADDR OF A/D REGISTER. 10011111 (7)
'ARE BITS TO TURN A/D ON AND OFF

SYMBOL TRISA = $85 'SETUP PINS DATA DIR I/O
POKE TRISA, 255 'MAKE DATA I/O GP0 AN OUTPUT, GP1 AN INPUT
'AND MAKE GP1 AN INPUT (ALL OTHERS ARE OUTS)

symbol PORTA = $05 '$05 IS OUTPUT DATA REGSITER
POKE PORTA, 0 'TURN OFF ALL BITS

Loop1: PEEK PORTA, BIT0 'COPY PORTA REG, PUT IN VARIABLE B0
IF BIT0 = 1 THEN LOOP1 'WHEN BUTTON IS PUSHED, INPUT GOES LOW


loop2: High 0 'Turn on LED connected to GP0
Pause 500 'Delay for .5 seconds

Low 0 'Turn off LED connected to GP0
Pause 500 'Delay for .5 seconds

Goto loop2 'Go back to loop and blink LED forever

skimask
- 23rd June 2008, 05:08
......................

skimask
- 23rd June 2008, 05:09
? #1 - Are you using PicBasic or PicBasicPro? I assume PicBasic. Which version?

PIC12F675 doesn't have PortA, it's got GPIO.
But I see you're using TRISA/PORTA as an alias for GPIO...
Do you have a pullup resistor on the button? Is it connected to Vdd or Vss directly? Does it float if the button isn't pressed?
How about trying something like this:


POKE $9f,0:POKE $1f,254:POKE $85,255:symbol PORTA=5:POKE PORTA, 0
Loop1: PEEK PORTA, B0 'COPY PORTA REG, PUT IN VARIABLE B0
IF B0 = 1 THEN HIGH 0
IF B0 = 0 then LOW 0
goto loop1
end

The ONLY thing that happens here is that the LED follows the button...that's it. Nothing else..
At least that's the only thing that SHOULD happen...

Jeff
- 25th June 2008, 01:30
Hey, thanks for answering, skimask. I am running PICBASIC 2.3.0.0. My button is pulled up with thru a resistor, so when button is pressed, pin goes low - to ground.

I could not compile your code. Maybe I am missing something:
POKE $9f,0
POKE $1f,254
POKE $85,255
symbol PORTA=5
POKE PORTA, 0
Loop1: PEEK PORTA, B0 'COPY PORTA REG, PUT IN VARIABLE B0
IF B0 = 1 THEN HIGH 0
IF B0 = 0 then LOW 0
goto loop1
end

It gets stuck on the "IF B0" lines. Couple more questions: Can I address the pins on this chip using "GPIO". You mentioned that I was using PortA. Maybe it is the same thing; Port A being used on IC's with more than one port? (sounds like maybe I answered my own Q but gotta ask.) Also, how do you make the code quote box? Thanks in advance!

Jeff

Archangel
- 25th June 2008, 02:30
Hey, thanks for answering, skimask. I am running PICBASIC 2.3.0.0. My button is pulled up with thru a resistor, so when button is pressed, pin goes low - to ground.

I could not compile your code. Maybe I am missing something:
POKE $9f,0
POKE $1f,254
POKE $85,255
symbol PORTA=5
POKE PORTA, 0
Loop1: PEEK PORTA, B0 'COPY PORTA REG, PUT IN VARIABLE B0
IF B0 = 1 THEN HIGH 0
IF B0 = 0 then LOW 0
goto loop1
end

It gets stuck on the "IF B0" lines. Couple more questions: Can I address the pins on this chip using "GPIO". You mentioned that I was using PortA. Maybe it is the same thing; Port A being used on IC's with more than one port? (sounds like maybe I answered my own Q but gotta ask.) Also, how do you make the code quote box? Thanks in advance!

Jeff
Hi Jeff,
I have not used PBC but I tell ya what I think: Change PEEK PORTA to PEEK GPIO.5 and POKE PORTA to POKE GPIO.5 and lose the symbol PORTA=5, I think your compiler is really looking for PortA which is unsupported for this chip. WOW glad I bought the pro version this looks a lot tougher to use.

skimask
- 25th June 2008, 03:19
Hey, thanks for answering, skimask. I am running PICBASIC 2.3.0.0
PicBasic 2.30 huh? I don't see that option on the MeLabs upgrades page...
http://www.melabs.com/support/upgrade.htm
Unless the MeLabs page is wrong, the 12F675 isn't support until version 1.44 of PicBasic...and isn't supported until version 2.42 for PicBasicPro.

So again...
Which version do you have?
Where'd you get it?
Why not spend the $25 for the upgrade to the latest greatest?

paul borgmeier
- 25th June 2008, 16:59
Hi Jeff,

I have not used Pic Basic Compiler for almost 10 years but here are some comments and items to check/change to get you going.


SYMBOL ANSEL = $9F '$19 IS ANSEL REGISTER
POKE ANSEL, 0 'MAKE PIN DIGITAL, NOT ANALOG
this looks good except your comment is for CMCON not ANSEL (see below)


SYMBOL ADCON0 = $1F 'TURN OFF A/D ON PIN4. (DEFAULT IS ON)
POKE ADCON0, 254 '$1F IS ADDR OF A/D REGISTER. 10011111 (7)
you do not need to fiddle with ADCON0 unless you want to use the A2D module. You should leave these two lines out. As it stands now, these two lines set up the A2D to acquire AN3 using a reference voltage on pin GP1, which might be messing you up. The pins do default to analog but changing them to digital is accomplished with ANSEL and CMCON.


You need to disable the comparators so add something like this


SYMBOL CMCON = $19 '$19 IS CMCON REGISTER
POKE CMCON, 7 'MAKE PIN DIGITAL, NOT ANALOG


SYMBOL TRISA = $85 'SETUP PINS DATA DIR I/O
POKE TRISA, 255 'MAKE DATA I/O GP0 AN OUTPUT, GP1 AN INPUT
'AND MAKE GP1 AN INPUT (ALL OTHERS ARE OUTS)
Here the poke 255 is actually making everything inputs. If you want everything to be inputs except GP0, then poke 254


symbol PORTA = $05 '$05 IS OUTPUT DATA REGISTER
POKE PORTA, 0 'TURN OFF ALL BITS
turns off all outputs so okay


Loop1: PEEK PORTA, BIT0 'COPY PORTA REG, PUT IN VARIABLE B0
you need to peek porta into a byte sized variable. Try PEEK PORTA, B0 as noted in your comment


IF BIT0 = 1 THEN LOOP1 'WHEN BUTTON IS PUSHED, INPUT GOES LOW
this does check bit 0 of B0 but you wanted GP0 to be an output? Maybe you want to check the bit where your switch is connected.?



loop2: High 0 'Turn on LED connected to GP0
Pause 500 'Delay for .5 seconds

Low 0 'Turn off LED connected to GP0
Pause 500 'Delay for .5 seconds

Goto loop2 'Go back to loop and blink LED forever

this trap looks good.


One last comments - Ski is correct, it is strange to rename the GPIO port to PORTA. Consider changing all PORTA refs above to GPIO. The same goes for TRISA - change to TRISIO

reply back with progress for more help

F1CHF
- 20th May 2009, 10:00
Hello
First, I have made a search on that PIC but I didn't find any answer on the following questions :

1/ Am I right if I say that the VSS and VDD pins are not in the same way than the well known 16F84 ?
we must make an adaptator to use a JDM programmer and having RB6 (pin 12) and RB7 (pin 13) pins on pin 7 and 6 on the 12F675 (assuming that we reverse VSS and VDD) and take pin 4 of the 16F84 to pin 4 on the 12F675 ! hope it is clear !

2/ we must read first the 12F675 to store oscal and bandgap datas ?

3/ we must play with CMCOM and Ansel command to have Digital port instead of analog status a power on time. (same story than for 16F628 or 16F88)

4/ we must forget PORTA and use GPIO to declare activ pins ?

5/ we must modify HEX file to feed oscal and bangap datas before programming ?

if I can find the famous BLINK.BAS program for 12F675, I will save time ...

what else ? nespresso pub ?

thanks

Francois

AMay
- 22nd May 2009, 22:07
I never found the button command worth the trouble. I just insert a short pause to eliminate bounce problems. 10 - 15 ms.

Archangel
- 22nd May 2009, 23:24
Hello
First, I have made a search on that PIC but I didn't find any answer on the following questions :

1/ Am I right if I say that the VSS and VDD pins are not in the same way than the well known 16F84 ?
we must make an adaptator to use a JDM programmer and having RB6 (pin 12) and RB7 (pin 13) pins on pin 7 and 6 on the 12F675 (assuming that we reverse VSS and VDD) and take pin 4 of the 16F84 to pin 4 on the 12F675 ! hope it is clear !
Correct ! Look at the data sheet for the proper connections, 16f84 has some family members who's power connections are the same . . . 16f628 series . . . others are different 16F690 for example.


2/ we must read first the 12F675 to store oscal and bandgap datas ?
Depends upon your programmer, the PICKit2 offers you a choice at programming time whether or not to overwrite.


3/ we must play with CMCOM and Ansel command to have Digital port instead of analog status a power on time. (same story than for 16F628 or 16F88)Correct ! You need to consult the data sheets for each PIC you are using. You (CAN) open the inc file for the chip you are using and read which registers appear there, you will find those files in the MPASM Suite's root directory.


4/ we must forget PORTA and use GPIO to declare activ pins ?
Usualy the 8 pin devices use GPIO, I think there is one that uses PortA


5/ we must modify HEX file to feed oscal and bangap datas before programming ?
I never have done this, I am sure it is possible, but not necessary unless you are hacking someone's hex file to fit a different chip.

Gene Choin
- 22nd September 2009, 00:08
I'm having the same problem with a 12F675 reading a pin
I'm using PicBasic, Microcode studio and MeL:abs Programmer , latest updates

I've been trying for a week with different combinations of peeks, pokes and button commands. It runs fine, but ignores my input to shorten the run loop.
Here is my latest try using he button command with peek and pokes commented out.

'************************************************* ***************
'* Name : Test.BAS *
'* Author : Gene Choin *
'* Notice : Copyright (c) 2009 *
'* : All Rights Reserved *
'************************************************* ***************
'* Date : 9/20/2009 2:13 *
'* Version : 1.0 *
'* Notes : TEST for 12F629 Input *
'* *
'************************************************* ***************
'TEST program for reading input on pin 1 (Physical pin 6 on 12F629 = GPIO1).
'pin1 has a 24K pull up resistor to 5V and switch to ground.
'If pin1 = 0, flash pin 4 and retest.
'If pin1 = 1. flash pin 5 also and then GOTO TEST

Symbol CMCON = $1f 'Alias $1f to CMCON
Poke CMCON, 7 'makes all digital I/O
'Variables

'Ports
Output 0 'Make GP0 the Strike output
Input 1 'Make GP1 the Run Sense in
Output 2 'Make GP2 the Filament Drive out
Input 3 'Make GP3 the MCLR in
Output 4 'Make GP4 the START LED out
Output 5 'Make GP5 the RUN LED out


'Begin Program
TEST:
pulsout 4,2000 'Marker - Pin 4 for 4 sec
High 4
Pause 4000
Low 4
Let B0 = 1 'clear B0
BUTTON 1,0,0,0,B0,0,Fil_hi 'If switch goes low, goto FilHi- skip High 5
High 5 'Marker - Pin 5 for 4 sec
pause 4000
Low 5

Fil_HI:
High 2
Pause 4000 'Marker - Pin 2 for 4 sec
Low 2
GOTO TEST
end

Darrel Taylor
- 22nd September 2009, 01:13
Symbol CMCON = $1f 'Alias $1f to CMCON

CMCON is at address $19

And if you are using a 12F675, you'll also need to set ANSEL($9F) to 0.
<br>