18F46K20 PIC in Oshonsoft SYMBOLS

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Hi,
I'm using 18F46K20 PIC using Oshonsoft and MPLAB.

Oshonsoft doesn't fully support the K type, so I've set it to 18F4620 instead. I've set MPLAB to 18F46K20.

For a test I have:
Symbol rled = PORTE.1
Symbol yled = PORTE.0

If I try:
rled = 1
WaitMs 1000
yled = 1
WaitMs 1000
rled = 0
WaitMs 1000
yled = 0
WaitMs 1000

RLED and YLED don't turn on together, RLED goes OFF as YLED comes ON.

If I use:
PORTE = %00000001
WaitMs 1000
PORTE = %00000011
WaitMs 1000
PORTE.1 = 0
WaitMs 1000
PORTE.0 = 0
WaitMs 1000
both turn on as expected.

Any ideas please.

Camerart.
 

ericgibbs

Joined Jan 29, 2010
15,378
hi C,
Have you read thru this PDF.?
What happens if you set the MPLAB to 18F4620, and import the Oshonsoft Hex file, then program the 18F46K20.?
E
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi C,
Have you read thru this PDF.?
What happens if you set the MPLAB to 18F4620, and import the Oshonsoft Hex file, then program the 18F46K20.?
E
Hi E,
I presume this applies to 18F46K20 too? I scanned your information, which is a lot to take in. I had previously set OSCCON correctly and the LEDs flash about right.

I had previously spent some time trying different likely title combinations (i,e, 18F4620 18LF4620) in OSH and MPLAB, all gave the same result.

It appears H's solution seems to work. I know you sometimes add LATs into a program, I'm beginning to see why.
 

ericgibbs

Joined Jan 29, 2010
15,378
hi C,
If you recall we have previously written some code in asm in with the Oshonsoft Basic coding, in order to overcome the limitations in Oshonsoft.
Using
ASM: your command....

Example from manual:

DIM VARNAME AS BYTE
ASM: MOVLW 0xFF
VARNAME = WREG

E
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,656
Hi H,
Good guess! They are switching as expected now. I've never understood LATS, but perhaps your attachment will help me, thanks.
C.
The simple rule is use PORTx only for reading inputs (switches etc) and use LATx for everything else e.g. simple outputs, operations on a single IO bit or operations using logic or arithmetic functions to a physical port or pins on a port. Also, avoid using single bit operations on any of the TRIS registers - define the full 8 bit value then write that to TRISx as an 8bit byte.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi C,
If you recall we have previously written some code in asm in with the Oshonsoft Basic coding, in order to overcome the limitations in Oshonsoft.
Using
ASM: your command....

Example from manual:

DIM VARNAME AS BYTE
ASM: MOVLW 0xFF
VARNAME = WREG

E
Hi E,
If LAT doesn't work properly, I'll come back to this post, thanks.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
The simple rule is use PORTx only for reading inputs (switches etc) and use LATx for everything else e.g. simple outputs, operations on a single IO bit or operations using logic or arithmetic functions to a physical port or pins on a port. Also, avoid using single bit operations on any of the TRIS registers - define the full 8 bit value then write that to TRISx as an 8bit byte.
Hi J,
I'll try to remember your simple rule, perhaps you'd be good enough to scan my programs to make sure I do :)

What do you mean 'using single BIT operations'? Again, please correct my programs, if I see I do.
C.
 

JohnInTX

Joined Jun 26, 2012
4,656
What do you mean 'using single BIT operations'?
I'm sorry, I don't know much about Oshonsoft but in general when you define a single bit output for example, the compiler will generate bsf/bcf instructions which are read-modify-write. These must be done to a LATx register, not a PORTx.

For example:

Symbol rled = PORTE.1 // single bit output to PORT, not recommended
Symbol yled = LATE.0 // single bit output to LAT, much more reliable


rled = 1;
will generate
bsf PORTE,1
That construct is a r-m-w on a PORT and should be avoided.

Writing:
yled=1;
will generate
bsf LATE,0
Which is a more reliable construct.

Note that LATx and PORTx refer to the same physical pins on the PIC and writing to either will write the value to the to the pins but the rule is the same, PORTx for inputs only. LATx for everything else. The actual reason for this is beyond what I have time for but those are the rules.

Have fun!
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
2,979
I'm sorry, I don't know much about Oshonsoft but in general when you define a single bit output for example, the compiler will generate bsf/bcf instructions which are read-modify-write. These must be done to a LATx register, not a PORTx.

For example:

Symbol rled = PORTE.1 // single bit output to PORT, not recommended
Symbol yled = LATE.0 // single bit output to LAT, much more reliable


rled = 1;
will generate
bsf PORTE,1
That construct is a r-m-w on a PORT and should be avoided.

Writing:
yled=1;
will generate
bsf LATE,0
Which is a more reliable construct.

Note that LATx and PORTx refer to the same physical pins on the PIC and writing to either will write the value to the to the pins but the rule is the same, PORTx for inputs only. LATx for everything else. The actual reason for this is beyond what I have time for but those are the rules.

Have fun!
Hi J,
I looked at the ASM file and sure enough you're correct. It's a bit beyond me, but I follow and don't need any more explanation.
Thanks,
C.
 

JohnInTX

Joined Jun 26, 2012
4,656
Yeah, I did not mean to blow you off but I have written that up several times and didn’t want to write it up again. You’d think I’d have saved a link or two. I’ll try to find one of those posts for your information but as long as you follow those rules that you will be OK. Glad it’s making sense.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Yeah, I did not mean to blow you off but I have written that up several times and didn’t want to write it up again. You’d think I’d have saved a link or two. I’ll try to find one of those posts for your information but as long as you follow those rules that you will be OK. Glad it’s making sense.
Hi J,
All ok, and better than doing Sudoku :)

See post#2.

C.
 

ericgibbs

Joined Jan 29, 2010
15,378
hi C,
As you may know, when the Oshonsoft compiles a Basic program, it also creates the Hex, Lst and Asm files.
The Asm and Lst files include the Basic as Comments, so you can check the actual code the compiler is creating.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi C,
As you may know, when the Oshonsoft compiles a Basic program, it also creates the Hex, Lst and Asm files.
The Asm and Lst files include the Basic as Comments, so you can check the actual code the compiler is creating.
E
Morning E,
Yes, I've looked at the HEX, LST and ASM files many times, and can see some order in them.

Are you able to write a complete program in ASM? If so how is it done without a simulator to find errors?

Every so often someone offers a new (to me) name to investigate, i,e, Swordfish. Up to now I've plodded on with Oshonsoft, and with help i,e, ASM from you occasionally, I/we have got there in the end. I doubt, I have the mind to change, and that's not from lack of confidence, but reality.

EDIT: Did you see my PM?
C.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
15,378
hi C,
Under Tools on the IDE, as well as Basic Compiler there is an Assembler option.
You can create an Asm coded listing, use F8 or F9 to create a hex file, run it in simulation,
[for a test, open an asm file that the Basic compiler has created, from a program you know]

It is possible to load the asm from Oshonsoft into MPLAB, but it needs changes to the Header section, I have done it a few times.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi C,
Under Tools on the IDE, as well as Basic Compiler there is an Assembler option.
You can create an Asm coded listing, use F8 or F9 to create a hex file, run it in simulation,
[for a test, open an asm file that the Basic compiler has created, from a program you know]

It is possible to load the asm from Oshonsoft into MPLAB, but it needs changes to the Header section, I have done it a few times.

E
Hi E,
I got them going, and could see some sense, but without a teacher in the room, it causes more questions than answers, to learn by email, interesting though.

I doubt I could write a program, because I don't usually start properly, but have an idea and keep re-starting till I get some order, which would drive any teacher nuts.

C.
 

ericgibbs

Joined Jan 29, 2010
15,378
hi
If you look here you find asm templates for the PIC's, copy and paste as required

C:\Program Files\Microchip\MPASM Suite\Template\Code

E
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi
If you look here you find asm templates for the PIC's, copy and paste as required

C:\Program Files\Microchip\MPASM Suite\Template\Code

E
Hi E,
I looked up those files, but didn't find them as my system is either different or MPLAB needs updating, but while messing about with ASM, which I agree is interesting, it has completely knocked my concentration for the BASIC program I am working on. It has reminded me again, not to deviate, but thanks for all of the encouragement.

Now where was I:confused:
C.
 

jpanhalt

Joined Jan 18, 2008
11,088
Here're the template files for the 18F46K20 using absolute Assembly ("TEMP"). For relocatable code, you want the "TEMPO" file.

If you want a feeling for PIC Assembly, I suggest starting with anything "lower" than 18Fxxxxx. PIC 16F1829 or 12F1840 are popular, and for going way back to nature, the 12F509. That is just for a feeling; not a suggestion to switch from the 18F series. The instruction sets of those chips are simpler, and then when you go back to the 18F series, the added instructions will not be so imposing.
 

Attachments

Top