• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simple 12F683 program in Oshonsoft Basic

camerart

Active Member
Thread starter #1
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

ericgibbs

Well-Known Member
Most Helpful Member
#2
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
ADCON0 = %00000001
ANSEL = %00000001
CMCON0 = %00000111
OPTION_REG = %10000111
TRISIO = %00001001

EDIT:

The ETO blog entry for this has disappeared.????
Copy here:
https://forum.allaboutcircuits.com/...-gen-2-phase-non-overlapping-clock.654/unread
 

camerart

Active Member
Thread starter #3
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
ADCON0 = %00000001
ANSEL = %00000001
CMCON0 = %00000111
OPTION_REG = %10000111
TRISIO = %00001001

EDIT:

The ETO blog entry for this has disappeared.????
Copy here:
https://forum.allaboutcircuits.com/...-gen-2-phase-non-overlapping-clock.654/unread
Hi E,
Couldn't get that one to work, but this one does: http://www.electro-tech-online.com/threads/adding-a-ds-to-12f683-in-oshonsoft.139854/page-4
#62
I'll filter out what I don't need.

Thanks, C.
 

ericgibbs

Well-Known Member
Most Helpful Member
#4
hi,
I have just checked that download and it works perfectly.??
When you compiled it, did you show the micro view on Oshonsoft and adjust the analog voltage level to make it run.??
E

A006.gif
 
Last edited:
#5
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.

'GP0 is analog input, use precision 1% resistors
'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:

'Main read loop. Takes about 88uS with BYTE
'but around 145uS with WORD variable (and word limits)

Adcin 0, i

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
Thread starter #6
hi,
I have just checked that download and it works perfectly.??
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
Thread starter #7
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
Thread starter #8
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

#9
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
Thread starter #10
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.
 

ericgibbs

Well-Known Member
Most Helpful Member
#12
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
Adcin 0, analogin
WaitMs 50
rled = 1
WaitMs analogin
rled = 0
analogin = 1023 - analogin
WaitMs analogin
Endif



Goto loop
 
Last edited:

camerart

Active Member
Thread starter #13
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
Adcin 0, analogin
WaitMs 50
rled = 1
WaitMs analogin
rled = 0
analogin = 1023 - analogin
WaitMs analogin
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

Adcin 0, analogin
WaitMs 50
If analogin > 0 Then
rled = 1
WaitMs analogin
rled = 0
analogin = 1023 - analogin
WaitMs analogin
Endif

Goto loop

Thanks, C.
 
Last edited:

camerart

Active Member
Thread starter #14
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
Most Helpful Member
#15
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

Please post your vid when ready.
E
 

camerart

Active Member
Thread starter #16
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

Please post your vid when ready.
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
Most Helpful Member
#17
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
Thread starter #18
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
Most Helpful Member
#19
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
Thread starter #20
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!
Are you ready for your close up:angelic:
C.
 

Latest threads

EE World Online Articles

Loading

 
Top