Flash an LED 10F200 Tutorial

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
To flip, or toggle, a single bit – to change it from 0 to 1 or from 1 to 0, you can exclusive-or it with 1.
That is:
0 XOR 1 = 1
1 XOR 1 = 0
So to repeatedly toggle GP1, we can read the current state of GPIO, exclusive-or the bit corresponding to GP1, then write it back to GPIO, as follows:
movlw b'000010' ; bit mask to toggle GP1 only
flash
xorwf GPIO,f ; toggle GP1 using mask in W
goto flash ; repeat forever
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Above is from the tutorial. It's before adding a delay.

How or when is it reading the current state of GPIO?

I guess I am expecting one line of code that say's 'READ GPIO'.

I thought assembler was one thing at a time.

Am I thinking of machine code?
 

be80be

Joined Jul 5, 2008
2,395
You don't read output's you write to them. I guess you can call it reading but your just moving port to w and doing whatever cause if you really was reading a port the chip wouldn't have rwm problems.
Thats why it's better to save a gpio to a shallow register

Yes you can read what i'm saying is that don't work good on a chip like this cause
you can't get a good reading all the time.
 
Last edited:

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Max and Bebe!

What is WREG?

movlw b'000010' ; bit mask to toggle GP1 only
flash
xorwf GPIO,f ; toggle GP1 using mask in W

What's a 'bit mask' ?

How do you use one?
 

be80be

Joined Jul 5, 2008
2,395
The 10f200 you want write gpio all at one time because RWM problems
There's no latc port and it a pin is loaded you not get what you planed to happen.
and shifting bits makes it even more likely to happen.

So you make a copy of GPIO
ShGPIO do your work here and then write it to GPIO and save it.
 

jayanthd

Joined Jul 4, 2015
945
W REG is th eworking register in PIC microcontrollers.

W = Working

movlw = move literal value to working register
movwf = move working register (contents) to file register
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thanks Bebe !

You're getting ahead again.

Tutorial gets into Read Modify Write soon in this lesson.

Thanks Max!

That paragraph raises more questions so that's a 'not get into it.'

Thanks Jay!

I think you are noticing simple works for me.

Okay. I will study all this.

Breaktime here.
 

MaxHeadRoom

Joined Jul 18, 2013
30,654
BTW the manuals for the MPLAB IDE are online if interested.
Have you ran a program and wished you could see what is actually happening to registers etc, internally step by step?
That is what MPLAB SIM does.
Max.
 

be80be

Joined Jul 5, 2008
2,395
If he was using a better chip Id post A mplab x project setup in sim but this is a dead simple chip
There is nothing there but 4 I/O and a 8 bit timer
And W been talked to death How it works is simple you move W the bit's you want set then you movwf to the GPIO or the trisgpio
Not much need of option not many to set if your not using the timer
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Max!

'manuals for the MPLAB IDE'

Okay. I use MPLAB X to compile only. Have not needed to look at that much.

'MPLAB SIM'

I think I'll stay away from that.

Note. Would be nice to write to a byte and see what's in it.

Does Debug do that? Stepping through program?

Or Variable view in MPLAB?
 
Last edited:

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Bebe!

Good thing this tutorial starts with 10F200.

Did find out 12F508 has 0 banks or 1 bank. Depends how you look at it. Anyhow no bank switching.

12F509 has 2 banks and 16F505 has 4 banks.

Glad I'm not dealing with that right now!
 

be80be

Joined Jul 5, 2008
2,395
You missing a lot there the 12f508 509 and 505 there is no banks to switch to there all handled in the one bank .
Addresses map back to addresses in Bank 0.
Only a Bank O
Banks don't make it harder to use the chip You just got handle them right.
Not a big deal and Like I said if you used a chip that had some banks Id post you a MPLAB x sim project
Note. Would be nice to write to a byte and see what's in it.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Bebe!

I just saw Banks in Memory Organization and thought they were banks.

Did look at a tutorial for 16F84A.

He had to switch banks twice to light an LED.

I can do without that right now.

Thanks for the offer but I have seen posts where simulators don't work exactly like the PIC.
 

jayanthd

Joined Jul 4, 2015
945
Thank you Bebe!
Thanks for the offer but I have seen posts where simulators don't work exactly like the PIC.
Buy mikroProg for PIC or EasyPIC v7 and do your project with mikroC PRO PIC using inline asm. You will learn better. You can debug the code and see the values of the registers inside PIC.

https://shop.mikroe.com/mikroprog-pic-dspic-pic32

https://shop.mikroe.com/easypic

If you want to build your own hardware then buy mikroProg for PIC.

If you want to use development board then use EasyPIC v7. It has a onboard mikroProg programmer/debugger. Works fine with mikroC PRO PIC.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Jay!

I'll keep that in mind.

I have seen other compilers that have an 'Assembler View'.

Basic Cow and something else. Maybe PIC Basic.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
'The XOR gate (sometimes EOR gate, or EXOR gate and pronounced as Exclusive OR gate) is a digital logic gate that gives a true (1/HIGH) output when the number of true inputs is odd. An XOR gate implements an exclusive or; that is, a true output results if one, and only one, of the inputs to the gate is true. If both inputs are false (0/LOW) or both are true, a false output results. XOR represents the inequality function, i.e., the output is true if the inputs are not alike otherwise the output is false. A way to remember XOR is "one or the other but not both".;

That's from Wikipedia.

This is quite a tutorial !

What is being compared here?

Looks like W and reading the GPIO port?
 
Top