PDA

View Full Version : Is this possible?



ERMEGM
- 16th January 2010, 07:37
Hello Everyone,

Having a little trouble with some coding. I have a manufacturer's product that I decided to reprogram. It is a 16F687 chip that connects its outputs to some MOSfets. They are all arranged in a row from 1-10, but the pins used are not. I wanted to be able to use coding like this:


ZigZag DATA Word %0000000001, 2
DATA Word %0000000010, 2
DATA Word %0000000100, 2
DATA Word %0000001000, 2
DATA Word %0000010000, 2
DATA Word %0000100000, 2
DATA Word %0001000000, 2
DATA Word %0010000000, 2
DATA Word %0100000000, 2
DATA Word %1000000000, 2
DATA Word %0100000000, 2
DATA Word %0010000000, 2
DATA Word %0001000000, 2
DATA Word %0000100000, 2
DATA Word %0000010000, 2
DATA Word %0000001000, 2
DATA Word %0000000100, 2
DATA Word %0000000010, 2
DATA Word %0000000001, 2
DATA Word %0000000000, 0

This style makes it easy to see which MOSfets are turning on and in essence is easy on the eyes, but the pins are arranged like this:

RC5, RC0, RC4, RC1, RC3, RC2, RC6, RB4, RC7, RB6

As you can see, they are not in order, so if I used the above format, the outputs won't zigzag like the layout, but rather be randomly jumping around.

So my question is this, is there a way to reassign the bits after reading the zigzag code above? In plain english, I want it to say:

read pin 0 (from zigzag) and display it on RC5
read pin 1 (from zigzag) and display it on RC0
etc....

Is there a way to do this? The obvious thing would be to set up the traces in the correct order, but this is the manufacturer's board and I'm reprogramming it to do something else. I was told to use something like translating the bits, but the sample code did not work and I can't find anything else anywhere.

The rest of my code reads each line from above and displays them one line at a time. But with this board, you can imagine how it's going to jump around.

Thanks for your help in advance,
Tony

mackrackit
- 16th January 2010, 09:44
If all you are wanting to do is make the code readable


ZIG1 VAR PORTC.5
ZIG2 VAR PORTC.0
ZIG3 VAR PORTC.4

You get the picture.

Darrel Taylor
- 16th January 2010, 19:25
Of course it's possible.
You're using PicBasic Pro. :)



Pattern VAR WORD
Idx VAR BYTE
;---------------------------------------------------------------------------
INCLUDE "VirtualPort.bas";
ASM
MyPortPins macro ; these define which bits go with which pins
Vpin 0, PORTC,5
Vpin 1, PORTC,0
Vpin 2, PORTC,4
Vpin 3, PORTC,1
Vpin 4, PORTC,3
Vpin 5, PORTC,2
Vpin 6, PORTC,6
Vpin 7, PORTB,4
Vpin 8, PORTC,7
Vpin 9, PORTB,6
endm
ENDASM
;---------------------------------------------------------------------------
Init:
@ OutputPort MyPortPins ; Set Pins to Output

Main:
FOR Idx = 0 to 38 STEP 2
READ Idx, WORD Pattern ; get pattern from EEPROM
@ WritePort _Pattern, MyPortPins ; write pattern to Virtual Port
PAUSE 100
NEXT Idx
GOTO Main

ERMEGM
- 16th January 2010, 19:28
Thanks Darrel.

ERMEGM
- 17th January 2010, 01:46
OK, having a little difficulty, and can't seem to sort it out. I'm getting a bad expression and an output parameter must be a variable Error on this line:

READ Idx, WORD Pattern ; get pattern from EEPROM

Can't figure it out. What am I doing wrong? This is going on a 16f687 chip.

Darrel Taylor
- 17th January 2010, 01:50
You have PBP 2.60? Right?
<br>

ERMEGM
- 17th January 2010, 14:05
Aha. 2.50b. Is 2.60 available online to download?

Acetronics2
- 17th January 2010, 14:10
Aha. 2.50b. Is 2.60 available online to download?

You are surprising me ...

PBP NEVER has been on-line downloadable ... honestly.

See CrownHill or Rentron sites for an official upgrade ...

Alain

Darrel Taylor
- 17th January 2010, 19:39
Aha. 2.50b. Is 2.60 available online to download?

I just assumed you had 2.60 because of the WORD modifier in your DATA statements.
You can still use VirtualPort with 2.50b, but getting data from EEPROM will be a little different.

Give this a try...
Pattern VAR WORD
Idx VAR BYTE

;---------------------------------------------------------------------------
ZigZag DATA %00,%00000001, 2
DATA %00,%00000010, 2
DATA %00,%00000100, 2
DATA %00,%00001000, 2
DATA %00,%00010000, 2
DATA %00,%00100000, 2
DATA %00,%01000000, 2
DATA %00,%10000000, 2
DATA %01,%00000000, 2
DATA %10,%00000000, 2
DATA %01,%00000000, 2
DATA %00,%10000000, 2
DATA %00,%01000000, 2
DATA %00,%00100000, 2
DATA %00,%00010000, 2
DATA %00,%00001000, 2
DATA %00,%00000100, 2
DATA %00,%00000010, 2
DATA %00,%00000001, 2
DATA %00,%00000000, 0
;---------------------------------------------------------------------------
INCLUDE "VirtualPort.bas"
ASM
MyPortPins macro ; these define which bits go with which pins
Vpin 0, PORTC,5
Vpin 1, PORTC,0
Vpin 2, PORTC,4
Vpin 3, PORTC,1
Vpin 4, PORTC,3
Vpin 5, PORTC,2
Vpin 6, PORTC,6
Vpin 7, PORTB,4
Vpin 8, PORTC,7
Vpin 9, PORTB,6
endm
ENDASM
;---------------------------------------------------------------------------
Init:
@ OutputPort MyPortPins ; Set Pins to Output

Main:
FOR Idx = 0 to (19*3) STEP 3
READ Idx, Pattern.HighByte ; get pattern from EEPROM
READ Idx+1, Pattern.LowByte
@ WritePort _Pattern, MyPortPins ; write pattern to Virtual Port
PAUSE 100
NEXT Idx
GOTO Main

ERMEGM
- 25th January 2010, 04:51
OK, so I ordered 2.6 and installed it. With some minor tweaking, I managed to get rid of all the error pop ups and get the LEDs to flash. Thank you so much for the translated bits. It works perfectly.

I've started changing some coding around to add some variety to it. Had another questions though. Even though I've labeled the pattern above ZigZag, when you reference the code to look up that pattern, you refer to the memory location. Is this the way it has to be done or can you reference the name ZigZag (or any other name)? I ask only because I am adding other patterns and it can become confusing if I have to count to what each memory position is.

Also, the board I am using has programming ports built onto it, so all I have to do is connect 5 wires from the PCB to the ZIF socket of my PBP. My hardware question is, can I leave all the wires attached after programming the chip on the PCB, or do I have to disconnect them? Was curious if when I turn the flasher on without removing the connections, will it fry anything or cause interference? I've been disconnecting the ZIF socket to prevent any back-flow in case it wasn't protected. It's becoming a real pain if it's not necessary. I just don't want to take a chance on an expensive programmer. As before, thanks in advance.

Tony

Darrel Taylor
- 25th January 2010, 19:56
Yes, you can reference them by name.


Sequence VAR BYTE

Sequence = ZigZag
GOSUB RunSequence

Sequence = Marquee
GOSUB RunSequence


Each sequence will probably be a different length, so you might have the first byte indicate the length, then delete all those 2's.
<br>

ERMEGM
- 27th January 2010, 02:17
OK, not quite understanding completely when you say that. I've changed the code around a bit, so I guess that's why it doesn't make much sense. I've done this so far:


ZigZag DATA Word %0000, 100
DATA Word %0001, 100
DATA Word %0010, 100
DATA Word %0100, 100
DATA Word %1000, 100
DATA Word %0000, 100
DATA Word %1000, 100
DATA Word %0100, 100
DATA Word %0010, 100
DATA Word %0001, 100
DATA Word %0000, 100
DATA Word %0000, 0

Later in the code, I have this:


Main:

Idx = 0

repeat

READ Idx, WORD Pattern, timer ; get pattern from EEPROM
IF (timer > 0) THEN
@ WritePort _Pattern, MyPortPins ; write pattern to Virtual Port
PAUSE timer
Idx = Idx + 3
endif

until timer = 0
goto Main

I've added a more complex code after this so as to be able to take a small segment from above and create a variable to the FOR-NEXT loop to be able to increase repetitions without having to write additional 1s and 0s.

In essence, it is to simulate:


FOR x = 1 to reps

high 1
pause 100
low 1
pause 100

NEXT x

FOR x = 1 to reps

high 2
pause 100
low 2
pause 100

NEXT x

Where "reps" can be incremented to create multiple flashes and still not take up additional space. It won't be getting it's code from ZigZag, but rather another "baseline" of code. I have other additional patterns in mind that will be its own entity like ZigZag, but wanted to be able to call it. This is where I'm a little confused as far as listing the length of code in the first byte.

Thanks,
Tony

Darrel Taylor
- 27th January 2010, 04:12
I was thinking that at the beginning of the sequence you could put the length and the period just before the data. The entire sequence would have to be the same speed, but it saves a bunch of EEPROM.


ZigZag
DATA 12, 100 ; length, speed
DATA Word %0000
DATA Word %0001
DATA Word %0010
DATA Word %0100
DATA Word %1000
DATA Word %0000
DATA Word %1000
DATA Word %0100
DATA Word %0010
DATA Word %0001
DATA Word %0000
DATA Word %0000
Then you do 12 loops with a PAUSE 100 in each loop.
May be more limiting than what you have though.

P.S. You can store the sequences in Flash memory instead of EEPROM, and you'll have a lot more room. (not much more with a 16F687 though)

ERMEGM
- 27th January 2010, 17:28
OK. That makes more sense. So, correct me if I'm wrong, but the chip writes ZigZag at a specific memory location (the next one available) and Marquee at the next available after ZigZag and so on. It is called up by referencing the name and not having to reference the location (i.e. read 0 or read 13...). The first line of DATA code is the seed for the loop (run this many times and delay this many milliseconds). Is this a correct interpretation?

Also, when you wrote the code:

@ WritePort _Pattern, MyPortPins ; write pattern to Virtual Port

This doesn't actually write to the chip does it? I only ask because, as you know, chips have only so many write functions and the patterns I am writing will meet that limit in a short time. I'm assuming NO, but you never know.

Thanks,
Tony

Darrel Taylor
- 28th January 2010, 05:58
Sounds like you've got it, on the first part.

And WritePort just writes to the PINs.
It doesn't write to Flash memory.

Cheers,

Bill Legge
- 28th January 2010, 06:53
Darrel T

I've noticed that when you post code here it is always neatly laid out - upper/lower case correct and tidily tabbed.

When I cut/pase code here it looks a mess - the upper/lower case is what I typed and the tabs go adrift.

How to you do it?

Regards Bill Legge

Darrel Taylor
- 28th January 2010, 07:53
Seems I remember asking Melanie that very question some 6-7 years ago. :)
Her answer was a little different, but this is what I do now.


Never use TAB's. And set the editor to insert 4 spaces when you hit the tab key.
<br>
Set the right gutter to 76 and don't go past it.
Gets rid of bottom scrollbar in code box.
<br>
Turn off the "Reserved Word Formatting" and capitalize things like FOR, SELECT, LCDOUT etc. as you type them in.
<br>
copy&paste variable names and labels, don't type them in each time.
It helps to have a fast "Flywheel" on your mouse when copying.
<br>
And for those special occasions, highlight the code with this.
http://www.darreltaylor.com/files/Show%20us%20your%20Colors_%20-%20MEL%20PICBASIC%20Forum.htm

<br>
hth,

Ioannis
- 28th January 2010, 09:50
Turn off the "Reserved Word Formatting" and capitalize things like FOR, SELECT, LCDOUT etc. as you type them in.
<br>


Well, I have a question on this. DEFINEs should be in capital letters. If the capitalize in MCS is enabled, will the defines be in real capital characters? If the setting is returned to default, I notice that the keyword DEFINE is showed as define.

Will this introduce a problem in the compiler?

Ioannis

Darrel Taylor
- 28th January 2010, 10:12
Contrary to popular belief, the word "define" does not have to be all caps.
DEFINE is a PBP statement, and PBP is NOT case sensitive.

If you are using PM.exe, then none of it has to be in caps, because PM.exe is NOT case sensitive either.

But, if you are using MPASM ... then what you are defining does have to be all caps.

DEFINE OSC 20 <-- OK
define OSC 20 <-- OK
DEFINE Osc 20 < NOT correct

And when MicroCode Studio changes the capitalization, it only changes the way it's displayed on-screen.
It still saves it to the file with the same capitalization you typed in.
If you copy and paste to the forum, you get what you typed, not what it looks like in MCS.

Any changes that MCS makes, will not affect the way it compiles, because the compiler never see's those changes.

hth,

P.S. If you turn off case sensitivity for MPASM, then you don't have to capitalize anything.

mackrackit
- 28th January 2010, 10:28
Or just code with cap lock on :)

Ioannis
- 28th January 2010, 11:55
The following paragraph is from the 2008 year manual of the PBP.

"These definitions must be in all upper case, exactly as shown. If not, the
compiler may not recognize them. No error message will be produced for
DEFINEs the compiler does not recognize"

After Darrels post, re-reading this paragraph, made me realize that indeed the word define can be either in capital or small. The definitions, and not the DEFINEs, must be in all upper case.

OK. Thanks.

Ioannis