# Simple 12F683 program in Oshonsoft Basic

Status
Not open for further replies.

#### camerart

##### Active Member
Hi,
I would like to make a simple circuit for a PIC demonstration.
Here's one from a modified program here in early 2014.
I would like to have two inputs, one Analogue and one Digital switching two LEDs.
How do I set-up for the digital input?
Cheers, Camerart.

#### Attachments

• 724 bytes Views: 92

#### ericgibbs

##### Well-Known Member
hi C,
Look at the PDF for each of these register settings
I have a program on my ETO blog that uses these settings, if you want to try it, it is the pulse gen project.
E
ANSEL = %00000001
CMCON0 = %00000111
OPTION_REG = %10000111
TRISIO = %00001001

EDIT:

The ETO blog entry for this has disappeared.????
Copy here:

#### camerart

##### Active Member
hi C,
Look at the PDF for each of these register settings
I have a program on my ETO blog that uses these settings, if you want to try it, it is the pulse gen project.
E
ANSEL = %00000001
CMCON0 = %00000111
OPTION_REG = %10000111
TRISIO = %00001001

EDIT:

The ETO blog entry for this has disappeared.????
Copy here:
Hi E,
#62
I'll filter out what I don't need.

Thanks, C.

#### ericgibbs

##### Well-Known Member
hi,
When you compiled it, did you show the micro view on Oshonsoft and adjust the analog voltage level to make it run.??
E

Last edited:

#### sagor1

##### Active Member
I have a simple 12F675 program that reads an analog input 0-4V, and outputs one of two LEDs. It also monitors a digital input to output one of two digital pins depending on the same voltage value.
It should be very similar for the 12F683 except you do not have to do the "OSCCAL" assembly routine, as there is no OSCCAL in the 12F683. Also, the initial configuration bits may be different for your chip.

CODE:
Code:
Define CONFIG = 0x3194
'Processor 12F675, internal 4Mhz clock

Define CLOCK_FREQUENCY = 4.0

'Program To check Icom band voltage/2 (now 0-4V) and check for 6M band
'If 6M selected, then any "send" (PTT) output for amplifier
'is routed to second "send" output for 6M
'Otherwise, all others go to regular HF "send"
'Note that send outputs are active high, needs 2N7000 to conduct
'to ground as PTT/Relay/Amp output to ground.
'Or, can power any relay taking less than 25Ma at 5V
'Need 10k pullup on GP3 (insend) input.

'to divide voltage by 1/2 (0-4V)
'6M band is between 1.2 to 2.0V and divide by 2 (count 30 to 51 for BYTE)
'(count 122 to 204 for WORD, if using WORD for "i")
'Set range check to one or two digits tighter bandwidth

ConfigPin GP0 = Input
ConfigPin GP3 = Input

ConfigPin GP1 = Output
ConfigPin GP2 = Output
ConfigPin GP4 = Output
ConfigPin GP5 = Output

AllDigital
'Alldigital will set CMCON to 0x07
'Will reset AN0 as analog later in ANSEL

Symbol hfled = GP1
Symbol vhfled = GP2
Symbol hfsend = GP4
Symbol vhfsend = GP5
Symbol insend = GP3

ANSEL = 0x31  '30 = internal clock, 1 is GP0 = AN0
ADCON0.VCFG = 0  'use VDD as reference (default anyway)

Dim i As Word

'Following is to read osccal value from 3FFF
'and insert into OSCCAL register
'RETLW instruction is 34xx where xx is value
'OSCCAL is not critical unless using software UART

ASM:        bsf STATUS,RP0 ;bank 1
ASM:        call 3ffh ;get the cal value
ASM:        movwf OSCCAL ;calibrate
ASM:        bcf STATUS,RP0 ;bank 0

hfsend = 0  'HF output =0
vhfsend = 0  'VHF output = 0
vhfled = 0
hfled = 1  'Default to HF LED on
WPU.0 = 0

loop:

'but around 145uS with WORD variable (and word limits)

Select Case i
Case < 122, > 205  'HF
hfled = 1
vhfled = 0
Case Else  'VHF (6M)
hfled = 0
vhfled = 1
EndSelect

If insend = 1 Then Goto loop  'No action on send pin, go back and read over and over

'if we get here, send is set to zero (grounded). Time to output a pin
'No debounce done, assume input is solid state from radio
'If there is bounce, we will bounce along with it...
'Determine action based on which LED is on

If hfled = 1 Then
hfsend = 1
vhfsend = 0
Else
hfsend = 0
vhfsend = 1
Endif

loop2:
If insend = 0 Then Goto loop2 'loop forever until send pin clears (goes high)
'Send clear, clear send outputs
hfsend = 0
vhfsend = 0
Goto loop

Last edited:

#### camerart

##### Active Member
hi,
When you compiled it, did you show the micro view on Oshonsoft and adjust the analog voltage level to make it run.??
E

View attachment 106909
Hi E,
You are correct of course. I did figure out that i had to adjust the voltage level, but I couldn't see it working, and was puzzled by the LOOP. On trying again, it was working.
C.

#### camerart

##### Active Member
I have a simple 12F675 program that reads an analog input 0-4V, and outputs one of two LEDs. It also monitors a digital input to output one of two digital pins depending on the same voltage value.
It should be very similar for the 12F683 except you do not have to do the "OSCCAL" assembly routine, as there is no OSCCAL in the 12F683. Also, the initial configuration bits may be different for your chip.
Hi S,
Thanks for your code, however, it has ASM included, which I can't read.
C

#### camerart

##### Active Member
Hi,
From the code posted, I have made up a simple program, which simulates and has a Digital and an analog IN which each switch on different LEDs.
This will be used to demonstrate what a little PIC is able to do. I will make a circuit, and perhaps add on something that will illustrate the Analog a bit better, perhaps a motor speed control.
Thanks for all the help.
C.

#### Attachments

• 1.1 KB Views: 56

#### sagor1

##### Active Member
Hi S,
Thanks for your code, however, it has ASM included, which I can't read.
C
As I said in the post, ignore the ASM, you only need it for the 12F675. You can actually delete it from the code.
I was merely posting the 675 code as an example of an analog in, digital in, and four digital outs. If you remove the ASM code, re-set the configuration bits, the code should run in the 12F683 as well as the 12F675...
It's just an example of code that runs for me, and how I handle the digital/analog configurations more so than what the actual code does...

Last edited:

#### camerart

##### Active Member
As I said in the post, ignore the ASM, you only need it for the 12F675. You can actually delete it from the code.
I was merely posting the 675 code as an example of an analog in, digital in, and four digital outs. If you remove the ASM code, re-set the configuration bits, the code should run in the 12F683 as well as the 12F675...
It's just an example of code that runs for me, and how I handle the digital/analog configurations more so than what the actual code does...
Hi S,
Apologies! I need to read something a couple of times, before it's READ. I see it now, thanks.
C.

#### camerart

##### Active Member
Hi,
1/ Can anyone tell me why GP4 flashes and doesn't stay on constantly when GP1 is pressed?
2/ I'm trying to change the speed that an LED flashes using the simplest way. Does the Analog section of the LOOP look ok to do that. It's not clear in simulation!
C.

#### Attachments

• 1.1 KB Views: 59

#### ericgibbs

##### Well-Known Member
hi C,
Checking your code it does not cover the correct conditions for GP1 =1 = GP4 ON.
E

EDIT:
Try this.
loop:

If digitalin = 1 Then
yled = 1
Else
yled = 0
''' Endif
WaitMs 50
rled = 1
rled = 0
Endif

Goto loop

Last edited:

#### camerart

##### Active Member
hi C,
Checking your code it does not cover the correct conditions for GP1 =1 = GP4 ON.
E

EDIT:
Try this.
loop:

If digitalin = 1 Then
yled = 1
Else
yled = 0
''' Endif
WaitMs 50
rled = 1
rled = 0
Endif

Goto loop
Hi E,
Your code changed things, but there's something fishy. As soon as Analog is set while digital is set, then they both flash. (analog is expected to flash)
I tried this 'below', and as long as they are used independently, then they work ok. Analogue needed >0 adding so it will stop working even when not set.

loop:
If digitalin = 1 Then
yled = 1
Else
yled = 0
Endif

WaitMs 50
rled = 1
rled = 0
Endif

Goto loop

Thanks, C.

Last edited:

#### camerart

##### Active Member
Hi,
This simulates, and I know it's not the best programming, but I'm in a bit of a rush, as I have to make a new circuit, and then a video explaining PICs in their simplest form before Friday. (The intention is to encourage others to have a go, and not frighten them off) The video will include a quick look at programming, and I'll show them the simulation (Although I will explain that Oshonsoft is perhaps not the best way to go)
There will then be talks on Arduinos and Picaxe etc.
Thanks for all of the help.
C.

#### ericgibbs

##### Well-Known Member
Morning C,
I would say the WaitMs 50 is redundant.
Another possible trivial situation, what if analogin cannot be set to 0, the LED will never be able set to OFF.
Most pots have some end resistance, so I would suggest If analogin > 10 Then

E

#### camerart

##### Active Member
Morning C,
I would say the WaitMs 50 is redundant.
Another possible trivial situation, what if analogin cannot be set to 0, the LED will never be able set to OFF.
Most pots have some end resistance, so I would suggest If analogin > 10 Then

E
Morning E,
All ok.
What do you think I should say about Oshonsoft? I don't want to run it down, and remember I like it, but I don't want to encourage others to get into the difficulties I've had either.
C.

#### ericgibbs

##### Well-Known Member
hi C,
I would say that for entry level to PIC's the Basic and in particular the Simulation models are a good starting point, but the IDE is limited to earlier versions of PIC's.
Most programmers have tried/used Basic compilers in their time.

It should be understood that most versions of the 'C' language compilers are very similar to Basic compilers, so the transition for the learner, from Oshonsoft Basic to 'C' is not too difficult.

Most of my early commercial programming was done using binary switches, after that, machine code.
When assemblers became available, I used assembly language programming until I retired.

E

#### camerart

##### Active Member
Hi E,
The audience will have some Arduinoists amongst them, I'm hoping to show that PICs are just a different family, and are capable of similar results, plus the idea that a 'shield' and plug in extra circuits aren't always necessary.

The circuit works. I had to turn up the threshold from >10 to >50 to get it working.

How can I post a video on this site? Is it as simple as upload a video file?
C.

#### ericgibbs

##### Well-Known Member
hi C,
I think the point you could make is that a PIC is just an IC and it requires associated circuit in order for it to work , an Arduino is an ATMEGA IC mounted on a PCB that has its associated circuitry.
You could do a simple comparative costing of the two options for your LED demo.

IMHO you cannot really compare the two.

Ref the Vid, most vids I have seen are linked to another host site.

E

#### camerart

##### Active Member
Hi E,
I don't know much about Arduinos, but from conversations I've had, an ATMEGA IC can be programmed and removed from the Arduino programmer, then added into a circuit, just as the PICs do, but I'm not sure too many people know that because they mostly come as a circuit.
As for price comparison, I think they come out very similar, although on a quick check the ATtiny is \$2.00 where the 12F683 is 50P. [On second check I find that the ATtiny is made by Microchip £1.50. I bet they are the same as the 12F, but marketed for Arduinoists.
I will also point out that there are many other makes of Micro-controller.

Right let's make a movie!
C.

Status
Not open for further replies.