PDA

View Full Version : Basic help for 12F629



Gene Choin
- 10th September 2009, 20:42
I'm new to writing BASIC for PIC.
I'm using a 12F629.
How does one write the "include" statements to use this in BASIC.
I only find ASM statements.
I see "inlcue", "list", "files"
I'm lost here.

I'm using Microcode Studio compiler.
My program begins :

* Notes : Basic Program for Digital P.S. for 12F629 *
'* *
'************************************************* ***************
' Device data

device = pic12f629, intrc_osc, wdt_on, bod_on, cpd_off, pwrt_on, mclr_off, protect_off

Symbol Strike = pin0 'Assign Strike drive to GPIO 0
Symbol RUNNING = pin1 'Assign Runing (Lo) to GPIO 1
Symbol HI_FIL = pin2 'Assign Filament Hi drive to GPIO 2
SYMBOL MCLR = pin3 'Assign Master CLear to GPIO 3
SYMBOL START_LED = pin4 'Assign Start Led to GPIO 4
SYMBOL RUN_LED = pin5 'Assign Run Led to GPIO 5
Symbol Fresh = bit0 'Assign Fresh Start_Up Counter to Bit 0

LED_TEST: 'Test RUN and START LEDS
RUN_TEST: 'Assign name to run test cycle
FIRST_TEST 'Assign name to FIRST TEST cycle
WARM_UP: 'Assign name to Warm up cycle
STRIKE_IT: 'Asssign name to STRIKE cycle
FINISH_WARM_UP: 'Assign name to finish warm up cycle

B0 var byte


Thanks

grounded
- 11th September 2009, 05:48
maybe this will help
http://www.picbasic.co.uk/forum/showthread.php?t=543

Gene Choin
- 21st September 2009, 23:49
I made a short program to test the input switch.
It flashes a couple of LEDs and if the switch is pressed (ground pin1 GPIO1)
it by passes the later flash.
I did learn that Ihad to do the CMON callto get the 12F629 digital.
I declared no variables since the button command seems to do this.

What ever I do, it ignores my input switch.
I went to the button command, but it still ignores.
GPIO1 is 1 and then 0 when switch pressed.
I set B0 = 1 which is steady state before switch pressed. This should be unnecessary but i tried it anyway.

Everything works, it just ignores my input. Just keeps trucking on without no short loop.
Thanks
Gene

'************************************************* ***************
'* 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
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

BobK
- 22nd September 2009, 00:54
Hi Gene,

You arm missing the port settings (TRIS). I haven't touched PBC since 2000 so I'm very rusty but here is an example I pulled from my files taken from this forum. Please note the GPIO and TRISIO settings. They set the port pins as either input or output and whether the pin starts out as high or low. CMCON disables the comparator.


'PIC: 12F629
' GP0: Turn Something On (relay, FET, alarm, etc)
' GP1: Test Location LED, Buzzer, VOM, nothing?
' GP2:
' GP3: (MCLR Internal)
' GP4: XTAL 4.0000 Hz (w/tolerance = 30 ppm) w/ cap to GND
' GP5: XTAL 4.0000 Hz (w/tolerance = 30 ppm) w/ cap to GND
'
' -_-
' +5V--| |--GND
' Xtal-|12F|--to turn on circuit (relay, FET, alarm, etc)
' Xtal-|629|--test location (LED, buzzer, etc. if required)
' -| |-
' ---
' (Xtal caps to GND not shown)
'
' CONFIGURATION SETUP
' Oscillator: XT
' Watchdog Timer: OFF
' Power up Timer: OFF
' Master Clear Enable: Internal
' Brown Out Detect: OFF
' Code Protect: OFF
' Data EE Read Protect:OFF
'************************************************* *********
CMCON=7 'all digital for low power use
GPIO=$00001000
TRISIO=$00001000
OPTION_REG=%10000111 'weak pullups off, TMRO prescale = 256
INTCON=0 'interrupts off
'************************************************* *********
HzTimer VAR Word '1/2 second counter (2 Hz)
SS VAR Byte ' Seconds 0-59
col VAR Bit ' colon 1=on, 0=0ff
trip var bit
cnt var byte
HzTimer=$7A12 'for 1/2 Sec
'************************************************* ********

I sure hope this helps you out. After thinking about this I think you have to "poke" the values into the GPIO and TRISIO registers. I don't have my PBC manual with me where I live during the week but I will check over some file archives and see if I can find some old files I did years ago. I will get back to you.


BobK

BobK
- 22nd September 2009, 01:44
Hi Gene,

I was looking at the PBC manual on the MElabs website. Here are some examples of setting the ports. You will also need to have a copy of the 12F629 datasheet to get the register information.



Symbol PortA = 5 'Define PortA register location
Symbol TrisA = $85 'Define PortA direction register location
Poke TrisA,0 'Make all PortA pins outputs


Peek PortA,B0 'Get current PortA pin states to variable B0
Bit1 = 1 'Set Bit1 in B0 which will become PortA pin 1 high
Bit3 = 0 'Set Bit3 in B0 which will become PortA pin 3 low
'Bit0, 2 and 4 will remain unchanged
Poke PortA,B0 'Send the new byte to PortA to complete the change

End

5.23. POKE

POKE Address, Value

Writes Value to the PICmicro MCU register at the specified Address. Special PICmicro MCU features such as A/D converters and additional I/O ports may be written using POKE. POKE is a PICBASIC™ Compiler statement and is not supported on the BASIC Stamp. (See PEEK for more information.)

Poke $85,0 'Write 0 to register hexadecimal 85 (Sets PortA to all outputs)


I also just finished looking for some older examples of programs I wrote in PBC but they are at home on my older computer so I don't have access to them until this coming weekend.

You need to look at the READ.ME file that came with your compiler program to check and see if the 12F629 will work with PBC. I didn't see it in the manual's list. You may be wasting your time with this chip if its not supported!

HTH,

BobK

Gene Choin
- 22nd September 2009, 04:06
Thanks for looking. I have the latest Microcode Studio and programming sw and it handles the 12F629 fine.
I've programmed it to do all kinds of functions, but it just won't read the input.

First, I do address the ports, not as TRIS0, but as each port GP1, ... directing them to be inputs or outputs.
I did add the CMCON,7 statement
And SYMBOL CMCON $1f (that was from Another advice).
The programs proceeds through the light flasing, but doesn't change when I ground GP1.
I did have one error Letting B0 = 1. It should be B0=0 to clear register.
BUTTON claims to look at pin 1, what state is is to be when pressed and when it's pressed, what to goto.
It does that but tHe BUTTON command just follows whatever I set B0 at. No update by the BUTTON command from GP1 (pin1).

I tried the "Button.BAS in the examples and it did the same. No workee! BUT, they give you only the code snippet without any setup.

' BUTTON Command
'
' Demonstrate BUTTON command. Prints working variable (in this case B0) to
' show how auto-repeat works. Prints "PRESS" when button is pressed or
' repeated.

Symbol CMCON = $1f
SYMBOL B = pin1 ' Button Input
poke CMCON,7 'all digital
'symbol GPIO=$00001000
'symbol TRISIO=$00001000
Output 0 'Make GPIO0 the Strike output
Input 1 'Make GPIO1 the Run Sense in
Output 2 'Make GPIO2 the Filament Drive out
Input 3 'Make GPIO3 the MCLR in
Output 4 'Make GPIO4 the START LED out
Output 5

Let B0 = 0 ' Zero Button Working Buffer
Loop:
Button B,0,10,5,B0,0,Skip ' Check Button (Skip if Not Pressed)
Pulsout 5, 2000
Goto Loop
Skip:

PULSOUT 4,2000 ' Indicates Button Pressed
Pause 100 ' Visual Pause
Goto Loop ' Forever